Silver
September 23rd, 2004, 08:34
Okay, so I've come across another conceptual problem I have with the PE structure. Not sure why I didn't notice this before, but anyway.
I was unpacking a target packed with a slightly mangled UPX 1.25 (-d wouldn't unpack it), but ran into some problems. So I grabbed upx.exe and upx'd notepad to test the process (I've successfully unpacked upx manually before, so I figure I've just forgotten something). Long story short, I dumped and fixed it without problems, and used Imprec to rebuild the IAT.
When I looked at the PE directory info, I noticed something I don't understand (from procdump PE editor, directory structures editor):
Original notepad:
Import table RVA: 6D20 Size: C8
IAT RVA: 1000 Size: 324
Dumped & Imprec fixed notepad:
Import table RVA: 1D000 Size: B4
IAT RVA: 0 Size: 0
I understand the Import table RVA/size is different due to a new section by imprec, that's fine. What I don't understand is how & why the dumped/fixed notepad still works when the RVA for the IAT isn't set?
I've read a number of PE tutorials & docs, and they don't explain this very clearly (ie: the difference/use/function of the import table entry and the IAT entry in the PE structure). Quote from http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/default.aspx
Okay, so that says to me that the import table directory entry in the PE header points to a location within the exe that contains 2 arrays - the IAT and the INT. Fine. But if I read part 1 of that essay, I see the following:
Okay, so that says that the IAT directory entry points to the start of the first IAT (which up until now I thought was exactly how this worked).
The original notepad PE has values for both import table and IAT in the directory. The dumped version has no value set for the IAT in the directory, yet it works.
How can the dumped Notepad work without an RVA for the IAT? What am I missing here?
I was unpacking a target packed with a slightly mangled UPX 1.25 (-d wouldn't unpack it), but ran into some problems. So I grabbed upx.exe and upx'd notepad to test the process (I've successfully unpacked upx manually before, so I figure I've just forgotten something). Long story short, I dumped and fixed it without problems, and used Imprec to rebuild the IAT.
When I looked at the PE directory info, I noticed something I don't understand (from procdump PE editor, directory structures editor):
Original notepad:
Import table RVA: 6D20 Size: C8
IAT RVA: 1000 Size: 324
Dumped & Imprec fixed notepad:
Import table RVA: 1D000 Size: B4
IAT RVA: 0 Size: 0
I understand the Import table RVA/size is different due to a new section by imprec, that's fine. What I don't understand is how & why the dumped/fixed notepad still works when the RVA for the IAT isn't set?
I've read a number of PE tutorials & docs, and they don't explain this very clearly (ie: the difference/use/function of the import table entry and the IAT entry in the PE structure). Quote from http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/default.aspx
Quote:
The anchor of the imports data is the IMAGE_IMPORT_DESCRIPTOR structure. The DataDirectory entry for imports points to an array of these structures. There's one IMAGE_IMPORT_DESCRIPTOR for each imported executable. The end of the IMAGE_IMPORT_DESCRIPTOR array is indicated by an entry with fields all set to 0. Figure 5 shows the contents of an IMAGE_IMPORT_DESCRIPTOR. Each IMAGE_IMPORT_DESCRIPTOR typically points to two essentially identical arrays. These arrays have been called by several names, but the two most common names are the Import Address Table (IAT) and the Import Name Table (INT). Figure 6 shows an executable importing some APIs from USER32.DLL. |
Okay, so that says to me that the import table directory entry in the PE header points to a location within the exe that contains 2 arrays - the IAT and the INT. Fine. But if I read part 1 of that essay, I see the following:
Quote:
IMAGE_DIRECTORY_ENTRY_IAT - Points to the beginning of the first Import Address Table (IAT). The IATs for each imported DLL appear sequentially in memory. The Size field indicates the total size of all the IATs. The loader uses this address and size to temporarily mark the IATs as read-write during import resolution. |
Okay, so that says that the IAT directory entry points to the start of the first IAT (which up until now I thought was exactly how this worked).
The original notepad PE has values for both import table and IAT in the directory. The dumped version has no value set for the IAT in the directory, yet it works.
How can the dumped Notepad work without an RVA for the IAT? What am I missing here?