r/windowsdev • • Apr 29 '22

What is difference between AddressOfEntryPoint and ImageBase

Till now I new that the ImageBase is first loaded in VM and then gets executed. Other sections are relative to it so it is easy to locate and import runtime or loadtime resources.

But now I am confused between AddressOfEntryPoint - is it the address of main function when loaded or the function that calls main function?

2 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/tbhaxor May 01 '22

Since it is relative to ImageBase, then instructions between [ImageBase, ImageBase + AddressOfEntryPoint] are for initializing CRT?

1

u/sheng_jiang May 01 '22 edited May 01 '22

nope, the PE file is mapped into memory at the base address, therefore you would find an IMAGE_DOS_HEADER header at the base address. There is very little difference between the file on disk and in memory (https://www.codeproject.com/Articles/17636/Dynamic-TEXT-Section-Image-Verification).

The code of the entry point function starts at ImageBase+AddressOfEntryPoint. It could be written in any native language (C, VB, Delphi etc). Initializing CRT is just the behavior of the CRT provided entry point mainCRTStartup.