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.

  1. get value @ offset 0x3c in file. start of pe header.

pe header stores fields target machine, number of sections , on. these things not important you.

  1. you can skip whole pe header. (add 0x14 pointer - sizeof(pe_header_s)==20)

  2. after adding 20 bytes pointer, you're pointing start of pe optional header standard fields. on offset 0x10, there's dword contains 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:

  1. find section containing entry point. .code section, better if compare starts of sections base of code (value of base of code located in pe optional header standard fields).
  2. substract virtual address of section (simply section start in memory when executable loaded) => offset of entry point (offset relative start of section).
  3. we have offset, add file offset of .code section 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

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -