Improve company productivity with a Business Account.Sign Up

x
?
Solved

Edit PE Header

Posted on 2004-08-15
15
Medium Priority
?
1,257 Views
Last Modified: 2013-11-13
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?
0
Comment
Question by:savagecat
  • 9
  • 5
15 Comments
 
LVL 8

Expert Comment

by:adg080898
ID: 11804284
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
 

Author Comment

by:savagecat
ID: 11804318
Using UltraEdit, where is offset 60?  Are you referring to 60h?
0
 
LVL 8

Expert Comment

by:adg080898
ID: 11804346
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
LVL 8

Expert Comment

by:adg080898
ID: 11804379
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
 

Author Comment

by:savagecat
ID: 11804400
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
 
LVL 8

Expert Comment

by:adg080898
ID: 11804468
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
 
LVL 8

Expert Comment

by:adg080898
ID: 11804489
What 3 characters? The 'h' ? That means the number is hex. You showed you knew what 'h' mean so I began using it.
0
 
LVL 5

Assisted Solution

by:Dragonmen
Dragonmen earned 200 total points
ID: 11805122
0
 

Author Comment

by:savagecat
ID: 11805874
adq

my apoligies  - wrong snapshot.

please try again.

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

0
 
LVL 8

Expert Comment

by:adg080898
ID: 11813208
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
 
LVL 8

Expert Comment

by:adg080898
ID: 11813219
UPX executables are compressed.
0
 

Author Comment

by:savagecat
ID: 11816086
upx -t says the file is uncompressed
0
 

Author Comment

by:savagecat
ID: 11816478
Someone's got  to know where the PE header is.
0
 
LVL 8

Expert Comment

by:adg080898
ID: 11816833
> 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
 
LVL 8

Accepted Solution

by:
adg080898 earned 1800 total points
ID: 11821155
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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.

Join & Write a Comment

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Make the most of your online learning experience.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Introduction to Processes

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question