After reaching to the base address, we will read 0x200 bytes (using ReadProcessMemory) from the base address.
Workflow (To read the offset to e_lfanew)
By analysing these 0x200 bytes, we will find the address of e_lfanew at 0x3c offset from the base address of executable.
e_lfanew: 4 byte offset which tells us where the PE header is located (offset to PE Header)
ADD the offset we got from e_lfanew to BaseAddress of executable
Now we need to navigate to the AddressofEntryPoint which is 0x28 from the PE header location
AddressofEntryPoint (0x28 from PE Header)
Here we will get the RVA for Entrypoint of the application, and RVA is just an offset so it needs to be Added with the base address of the remote proccess to find the absolute virtual memory address.
Case Study
Steps before actual calculations
Start the process in Suspended mode
Use zwqueryinformationprocess to find the PEB Address
Now Actual Case Study
we have the PEB Address: 0x3004000
Task: Find the memory address of the entrypoint of the application
We ADD 0x10 in PEB Address == (0x3004010) -> to find the Base Address of the executable, we read the value of the address above and it comes out as 0x7ffff01000000
Base Address of the Executable == 0x7ffff01000000
Read the 0x200 bytes using ReadProcessMemory for inspecting locally
Check the 0x3c location from Base Address of the Executable == 0x7ffff0100003c to find the e_lfanew header
e_lfanew header at 0x7ffff0100003c will give the offset to PE Header
PE Header the offset we got is 0x110
Add the total offset bytes to the Base Address of the Executable -> 0x7ffff01000000 + 0x110 == 0x7ffff01000110
So PE Header is at 0x7ffff01000110
From PE Header, we need to read 0x28 ahead in order to find the RVA for Entrypoint of the application
ProcessInformationClass --> ProcessBasicInformation --> PEB address --> 0x10 bytes into PEB --> Base Address of Executable Reached
Base Address of Executable Reached --> ReadProcessMemory --> 0x200 bytes --> inspect the 0x200 memory space locally --> 0x3c from base address locally --> e_lfanew reached
e_lfanew offset + base address of executable == PE Header memory address
PE Header memory address --> 0x28 --> AddressofEntryPoint (we got offset as its RVA)
Base Address of Executable Reached --> ADD RVA in it --> Base address of the entrypoint of application is reached.
PEB Address -> base address of executable (0x10) -> e_lfanew (base address of executable + 0x3c) -> PE Header (offset got from e_lfanew + base address of executable) -> RVA to Application entry point (PE Header + 0x28 bytes)