assembly - How to determine location of _main in x86-64 executable? -
i interested in constructing cfg x86-64 executable using static methods. having trouble including "main" function because there no precomputed jumps main function; appears jump may not computed until program run. such, cfg missing 1 of important functions - main one! how can statically determine location of _main?
for further information read microsoft pe specification.
getting entry point address
base of actual pe executables (term image preffered in documentation) lies in old dos .exe mz executables. first 2 bytes of every executable ascii 'm' , 'z'. nowadays, dos header skipped. used contain values such starting cs, ip, ss or sp.
- get value @ offset
0x3cin file. start of pe header.
pe header stores fields target machine, number of sections , on. these things not important you.
you can skip whole pe header. (add
0x14pointer -sizeof(pe_header_s)==20)after adding
20bytes pointer, you're pointing start of pe optional header standard fields. on offset0x10, there'sdwordcontains address of entry point relative image base.
getting file offset of entry point
getting file offset of entry point bit more difficult. process looks this:
- find section containing entry point.
.codesection, better if compare starts of sections base of code (value of base of code located in pe optional header standard fields). - substract virtual address of section (simply section start in memory when executable loaded) => offset of entry point (offset relative start of section).
- we have offset, add file offset of
.codesection result of previous step, , you're done.
all steps not lead address of main, address of crt entry point, calls _main function.
if wan't address of main, must go through pe object files , find symbol _main in symbol table.
Comments
Post a Comment