Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What arguments are passed to entry point of a PE (Portable Executable) file?

If you assemble a PE (.exe, portable executable for Win32) file it has an entry point which you could call _start, _main or whatever you like.

The question is - is this entry point called with some args? If so, are they accessible in the stack? If so, does this entry point function need to clear the stack? Where can I find some documentation about this?

like image 244
user2214913 Avatar asked Oct 01 '15 20:10

user2214913


People also ask

What is entry point of a PE executable?

The PE entry point is defined in the IMAGE_OPTIONAL_HEADER structure, in the AddressOfEntryPoint field: A pointer to the entry point function, relative to the image base address. For executable files, this is the starting address. For device drivers, this is the address of the initialization function.

How do I find the entry point of a PE file?

The entry point is given by AddressOfEntryPoint in the PE header, which gives you the virtual address of the entry point.

Which field in the Portable Executable PE header specifies the address of the instruction that the operating system should execute first after loading the executable?

text: This is normally the first section and contains the executable code for the application. Inside this section is also an entry point of the application: the address of the first application instruction that will be executed.

What two characters does every Windows Portable Executable PE file start with?

After the MS-DOS stub, at the file offset specified at offset 0x3c, is a 4-byte signature that identifies the file as a PE format image file. This signature is "PE\0\0" (the letters "P" and "E" followed by two null bytes).


1 Answers

No the process does not have any information about it's arguments on the stack at the entry point. You have to call GetCommandLine or access the information in the PEB via RTL_USER_PROCESS_PARAMETERS, but that's not a stable API.

Every language support library (like the CRT) has to do this as well.

like image 200
typ1232 Avatar answered Nov 15 '22 07:11

typ1232