Kayaker
January 28th, 2001, 03:40
Hi All,
I've developed a curiosity as to the exact process that occurs when a program first starts up, specifically what determines what sections are mapped into memory at the Program Entry Point.
It's sort of like exploring the precise moment of the Big Bang - what exactly happens when you load a file in SoftIce Loader and press that first F8?
Take Notepad as an example. Here are the sections and their Virtual Sizes:
.text :00401000 00003E9C
.data :00405000 0000084C
.idata :00406000 00000DE8
.rsrc :00407000 00004FB8
.reloc :0040C000 00000A9C
At the Program Entry Point of 4010CC, the only sections that are committed to memory are the 1st 1000 bytes of the .text section, the full .idata section, and the 1st 1000 bytes of the .rsrc section. As you step through the program you can find where the other bits and pieces are memory mapped by monitoring the Data Window.
Now I can live with the .text, or code, section being mapped piecemeal 1000 bytes at a time, but I'd like to know what determines which sections and how much of each is mapped into memory in that very first instance at the Program Entry Point. I've been burning up various PE documentations for clues, but nothing seems to jump out at me. Are all sections treated equally? Could you force a program to load the WHOLE of its .text section upon startup, irrespective of any later code which might be involved in doing this?
For Notepad the Program Entry Point and register values are below. What information is here concerning what's to be mapped into memory as soon as you F8 over that first magic PUSH EBP? Are the values in ECX, EDX and ESI significant?
EAX=004010CC EBX=00000000 ECX=8171B660 EDX=8171B6A0 ESI=8171B640
EDI=00000000 EBP=0063FF78 ESP=0063FE38 EIP=004010CD
0167:004010CA 0000 ADD [EAX],AL
0167:004010CC 55 PUSH EBP
0167:004010CD 8BEC MOV EBP,ESP
0167:004010CF 83EC44 SUB ESP,44
0167:004010D2 56 PUSH ESI
0167:004010D3 FF15E0634000 CALL [KERNEL32!GetCommandLineA]
You may rightly wonder why I ask such strange questions. Specifically, I have a packed program which, during the unpacking process every section is mapped into memory in the regular program address space, and then it jumps to the OEP and the program runs fine. Unpack the program and partway through the code there's a Runtime error because part of the .text section is not mapped into memory yet! Hence my interest in committing the entire .text section to memory on program startup, but this is as a general interest question as well.
Any light shed on this mystery of Windows is appreciated ;-)
Regards,
Kayaker
I've developed a curiosity as to the exact process that occurs when a program first starts up, specifically what determines what sections are mapped into memory at the Program Entry Point.
It's sort of like exploring the precise moment of the Big Bang - what exactly happens when you load a file in SoftIce Loader and press that first F8?
Take Notepad as an example. Here are the sections and their Virtual Sizes:
.text :00401000 00003E9C
.data :00405000 0000084C
.idata :00406000 00000DE8
.rsrc :00407000 00004FB8
.reloc :0040C000 00000A9C
At the Program Entry Point of 4010CC, the only sections that are committed to memory are the 1st 1000 bytes of the .text section, the full .idata section, and the 1st 1000 bytes of the .rsrc section. As you step through the program you can find where the other bits and pieces are memory mapped by monitoring the Data Window.
Now I can live with the .text, or code, section being mapped piecemeal 1000 bytes at a time, but I'd like to know what determines which sections and how much of each is mapped into memory in that very first instance at the Program Entry Point. I've been burning up various PE documentations for clues, but nothing seems to jump out at me. Are all sections treated equally? Could you force a program to load the WHOLE of its .text section upon startup, irrespective of any later code which might be involved in doing this?
For Notepad the Program Entry Point and register values are below. What information is here concerning what's to be mapped into memory as soon as you F8 over that first magic PUSH EBP? Are the values in ECX, EDX and ESI significant?
EAX=004010CC EBX=00000000 ECX=8171B660 EDX=8171B6A0 ESI=8171B640
EDI=00000000 EBP=0063FF78 ESP=0063FE38 EIP=004010CD
0167:004010CA 0000 ADD [EAX],AL
0167:004010CC 55 PUSH EBP
0167:004010CD 8BEC MOV EBP,ESP
0167:004010CF 83EC44 SUB ESP,44
0167:004010D2 56 PUSH ESI
0167:004010D3 FF15E0634000 CALL [KERNEL32!GetCommandLineA]
You may rightly wonder why I ask such strange questions. Specifically, I have a packed program which, during the unpacking process every section is mapped into memory in the regular program address space, and then it jumps to the OEP and the program runs fine. Unpack the program and partway through the code there's a Runtime error because part of the .text section is not mapped into memory yet! Hence my interest in committing the entire .text section to memory on program startup, but this is as a general interest question as well.
Any light shed on this mystery of Windows is appreciated ;-)
Regards,
Kayaker