I'm writing a tool for program analysis. I want to find all code regions (i.e. regions with machine instructions) inside the program. I also want to consider dynamically linked code. This far, I have a main process that fork
s and attaches as a tracer to a sub-process. I read from the procfs
/proc/<pid>/maps
to find all executable m-mapped regions (and redo it every time a mmap
syscall is performed to support dynamic linking), but then I am stuck. I believe all virtual-memory regions that are marked executable in the vm-map are in ELF
format.
I have tried looking at all section headers with executable permissions in-memory, but sometimes their offset in the ELF
is outside the mapped space, and as such not inside the executable. I believe I might need to look at the program headers, but I can't get it right.
Any help would be much appreciated!