Edit PE Header

I need to repair the DOS Header *and* the PE Header.

Using UltraEdit I've figured out that the DOS Header is MZ and is the first 2 characters of the file.

But where is the PE Header in the file?
savagecatAsked:
Who is Participating?
 
adg080898Commented:
Look at this:

http://doug.perrycomputerservices.com/ee/pe.gif

I outlined the *beginning* of the PE header in red. The numbers outlined in blue tell you where to look for the PE header.

Your executable is either compressed, or corrupt.
0
 
adg080898Commented:
To find the PE header, seek to offset 60 and read a DWORD. This value you read is the offset of the PE header.

Then you seek to the value you read and make sure you see 4 bytes that say "PE\0\0". After that is the IMAGE_FILE_HEADER...

This is how a PE file is laid out:

IMAGE_DOS_HEADER
PE\0\0
IMAGE_FILE_HEADER
IMAGE_OPTIONAL_HEADER
for (each section) {
    IMAGE_SECTION_HEADER
}

The names I used are the ones used in standard windows headers.
0
 
savagecatAuthor Commented:
Using UltraEdit, where is offset 60?  Are you referring to 60h?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
adg080898Commented:
Well, 60 = 3Ch

So you read the four bytes at offset 3Ch. But remember they are stored in little-endian format. Which means:

01234567h is stored as 67 45 23 01
11223344h is stored as 44 33 22 11
etc...

For example, you look at offset 3Ch and see the value F8h.

Then you look at offset F8h and see 50h 45h 00h 00h which is "PE  ". After that is IMAGE_FILE_HEADER, etc.
0
 
adg080898Commented:
The first two bytes of the file are MZ. The offset of the PE header is stored at 3Ch.

The "offset" is the number of bytes from the beginning.

When you are about to read byte 5, you are at offset 5. Before you read the first byte, you are at offset zero. See? So if you read byte 05h, that is the same thing as "read the byte at offset 05h".
0
 
savagecatAuthor Commented:
From http://www.savagecat.us/ee/ee01.jpg

Ok, how are you coming up with 3 character entities, and UltraEdit is coming up with 2 character entities?
0
 
adg080898Commented:
Forget the MZ. That is the DOS header.

I said the offset to the PE header is stored at 0000003C, therefore...

If you look at row 00000030h, look at the number fourth from the right. D8h 00h 00h 00h.

So you then look at row 000000D0. The 8th is in the middle:50 46 00 00 4C etc...

See? 000000D8h is the offset of the PE header in your screenshot.
0
 
adg080898Commented:
What 3 characters? The 'h' ? That means the number is hex. You showed you knew what 'h' mean so I began using it.
0
 
savagecatAuthor Commented:
adq

my apoligies  - wrong snapshot.

please try again.

http://www.savagecat.us/ee/ee01.jpg

0
 
adg080898Commented:
Right, this one is a packed executable. Your cursor is sitting at offset 3Ch, and the value there is D8h.

If you look at offset D8h you'll see a PF header. What gives it away is the UPX UPX that occurs further down.

http://upx.sourceforge.net/
0
 
adg080898Commented:
UPX executables are compressed.
0
 
savagecatAuthor Commented:
upx -t says the file is uncompressed
0
 
savagecatAuthor Commented:
Someone's got  to know where the PE header is.
0
 
adg080898Commented:
> Someone's got  to know where the PE header is.

Yes. Me! :)

Your file is corrupt. Open a known-good exe. Look at offset 3C. The value stored at 3C is the offset of the PE header. The PE header begins with the letters PE.

Believe me, I know what I'm talking about. I wrote a program that BUILDS win32 executables.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.