PDA

View Full Version : PE Header in C Language. Please Help!!!


cdiaz0712
April 5th, 2008, 00:40
Write a program in C that do the following. ----------------------------------------------------------------------------------------------------------------------------------------------------
1. Accepts 1 parameter. The parameter is the filename to be processed.
If there are no parameters, or if there are more than 1 parameters, show an error message.
2. Opens the file and verify if it’s a PE file.
A PE File has the following characteristics:
MZ signature at offset 00h..01h
A value > 0x40 at offset 18h
PE signature at offset pointed to by value in offset 3Ch
** You can use either fread/ReadFile/ReadFileEx/CreateFileMapping to read the contents of the file.
3. Loads the PE header, PE Optional Header and Data directory into a structure and display the values inside this table.
Please refer to the attached excel sheet for the PE Header documentation.
You can start your structure for the PE Header as follows:

struct _PE_HEADER
{
char szPeSignature[4];
WORD wMachine;
WORD wNumberOfSections;
DWORD dwTimeDateStamp;
DWORD dwPointerToSymbolTable;



} PE_HEADER;
Sample Output:
PE-Dump of "calc.exe"
============================================================================
PE-Header at offset 000000F
============================================================================
Machine (014C) Intel 386
Number of sections 3
TimeDate stamp (3B7D8410) Fri Aug 17 13:52:32 2001
Pointer to symbol table 00000000
Number of symbols (00000000) 0
Size of optional header (00E0) 224
Characteristics 010F
bit 0: relocations stripped Yes
bit 1: executable image Yes
bit 2: line numbers stripped Yes
bit 3: local symbols stripped Yes
bit 4: agressively trim working set No
bit 5: (reserved) No
...
Magic optional header 010B
Linker version 7.00
Size of code (00012800) 75776
Size of initialized data (00009C00) 39936
Size of uninitialized data (00000000) 0
Address of entry point 00012475

Kayaker
April 5th, 2008, 01:34
cdiaz0712, I have deleted your Blog and blog entry you created to post this. The Blog function is NOT meant to post random help requests but is reserved for meaningful reversing related contributions.

You can still create a blog at a future time if you so wish and understand what it's meant for.

As for your post.. we're here to help, even if it's homework I guess, BUT you need to do your own work and at least show you're trying here.

Where are you stuck? You can write a basic C program presumably. Do you know how to open a file with fread/ReadFile/ReadFileEx/CreateFileMapping? Have you even found the prototypes for these API's from the Microsoft site or PSDK? Find them at least and let us know if you even know how to use the information. You *should* at least be able to make sense of what they are saying or you will be able to go no further.

As for interpreting the PE format.. Besides there being a lot of code examples around to do what is asked for, understanding how to make use of the PE header fields will come later.

Start with creating a basic C program to open (any) file. Don't even worry about mapping it yet (CreateFileMapping), show us that you have at least attempted a skeleton program to open a file and we can go from there.

Kayaker