Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Edit PE Header

Posted on 2004-08-15
15
Medium Priority
?
1,189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Progress
Introduction to Processes

722 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