2011-12-28 56 views
4

我正在研究PE解剖器,并且遇到了一些相当不寻常的事情。的名称和在PE格式的目录顺序似乎不同取决于你往哪里看:PE目录的名称

PEReader (perdr)

#define IMAGE_DIRECTORY_ENTRY_EXPORT   0 // Export Directory 
#define IMAGE_DIRECTORY_ENTRY_IMPORT   1 // Import Directory 
#define IMAGE_DIRECTORY_ENTRY_RESOURCE  2 // Resource Directory 
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION  3 // Exception Directory 
#define IMAGE_DIRECTORY_ENTRY_SECURITY  4 // Security Directory 
#define IMAGE_DIRECTORY_ENTRY_BASERELOC  5 // Base Relocation Table 
#define IMAGE_DIRECTORY_ENTRY_DEBUG   6 // Debug Directory 
#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 // Architecture Specific Data 
#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR  8 // RVA of GP 
#define IMAGE_DIRECTORY_ENTRY_TLS    9 // TLS Directory 
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory 
#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers 
#define IMAGE_DIRECTORY_ENTRY_IAT   12 // Import Address Table 
#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 // Delay Load Import Descriptors 
#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // COM Runtime descriptor 

PEInfo(校正到0基):

0 Export 
1 Import 
2 Resource 
3 Exception 
4 Security 
5 Base Reloc 
6 Debug 
7 Copyright 
8 Global Ptr 
9 TLS 
10 Load Config 
11 Bound Import 
12 IAT 
13 COM 
14 Delay Import 
15 (reserved) 

CFF Explorer

0 Export 
1 Import 
2 Resource 
3 Exception 
4 Security 
5 Relocation 
6 Debug 
7 Architecture 
8 (reserved) 
9 TLS 
10 Configuration 
11 Bound Import 
12 IAT 
13 Delay Import 
14 .NET MetaData 

WINE's winnt.h

#define IMAGE_DIRECTORY_ENTRY_EXPORT   0 
#define IMAGE_DIRECTORY_ENTRY_IMPORT   1 
#define IMAGE_DIRECTORY_ENTRY_RESOURCE   2 
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION   3 
#define IMAGE_DIRECTORY_ENTRY_SECURITY   4 
#define IMAGE_DIRECTORY_ENTRY_BASERELOC   5 
#define IMAGE_DIRECTORY_ENTRY_DEBUG    6 
#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT   7 
#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR   8 /* (MIPS GP) */ 
#define IMAGE_DIRECTORY_ENTRY_TLS    9 
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG  10 
#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT  11 
#define IMAGE_DIRECTORY_ENTRY_IAT    12 /* Import Address Table */ 
#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT  13 
#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 

在这里,他们是作为一个表:

+------+-------------------+-------------------+-------------------+-------------------+ 
| Dir# | WINE's winnt.h | PEReader   | PEInfo   | CFF Explorer  | 
+------+-------------------+-------------------+-------------------+-------------------+ 
| 0 | Export   | Export   | Export   | Export   | 
| 1 | Import   | Import   | Import   | Import   | 
| 2 | Resource   | Resource   | Resource   | Resource   | 
| 3 | Exception   | Exception   | Exception   | Exception   | 
| 4 | Security   | Security   | Security   | Security   | 
| 5 | Relocation  | Relocation  | Relocation  | Relocation  | 
| 6 | Debug    | Debug    | Debug    | Debug    | 
| 7 | Copyright   | Architecture  | Copyright   | Architecture  | 
| 8 | Global Ptr  | Global Ptr  | Global Ptr  | (reserved)  | 
| 9 | TLS    | TLS    | TLS    | TLS    | 
| 10 | Load Config  | Load Config  | Load Config  | Load Config  | 
| 11 | Bound Import  | Bound Import  | Bound Import  | Bound Import  | 
| 12 | IAT    | IAT    | IAT    | IAT    | 
| 13 | Delay Import  | Delay Import  | COM    | Delay Import  | 
| 14 | COM Descriptor | COM Descriptor | Delay Import  | .NET MetaData  | 
| 15 | -     | -     | (reserved)  | -     | 
+------+-------------------+-------------------+-------------------+-------------------+ 

编号和这些订单似乎没有正确地匹配。在PEReader和winnt.h中,条目14都是COM描述符,但是在CFF Explorer中显示为.NET MetaData。 COM和Delay Import条目似乎也被切换了。

似乎有些奇怪的是,其中几个工具会导致这个错误。哪一个是正确的?我错过了一个更新的定义吗?

回答

6

您不必使用任何未公开的内容。正确的一个可以在Windows SDK附带的WinNT.h文件中找到(一旦安装,在我的机器上,它位于C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.0A \ Include):

// Directory Entries 

#define IMAGE_DIRECTORY_ENTRY_EXPORT   0 // Export Directory 
#define IMAGE_DIRECTORY_ENTRY_IMPORT   1 // Import Directory 
#define IMAGE_DIRECTORY_ENTRY_RESOURCE  2 // Resource Directory 
#define IMAGE_DIRECTORY_ENTRY_EXCEPTION  3 // Exception Directory 
#define IMAGE_DIRECTORY_ENTRY_SECURITY  4 // Security Directory 
#define IMAGE_DIRECTORY_ENTRY_BASERELOC  5 // Base Relocation Table 
#define IMAGE_DIRECTORY_ENTRY_DEBUG   6 // Debug Directory 
//  IMAGE_DIRECTORY_ENTRY_COPYRIGHT  7 // (X86 usage) 
#define IMAGE_DIRECTORY_ENTRY_ARCHITECTURE 7 // Architecture Specific Data 
#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR  8 // RVA of GP 
#define IMAGE_DIRECTORY_ENTRY_TLS    9 // TLS Directory 
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 // Load Configuration Directory 
#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 // Bound Import Directory in headers 
#define IMAGE_DIRECTORY_ENTRY_IAT   12 // Import Address Table 
#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13 // Delay Load Import Descriptors 
#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14 // COM Runtime descriptor 

WINE & PEReader的定义只是(正确地我相信)借用这个.h文件。

还有一个在这里提到:ImageDirectoryEntryToDataEx function

3

的PE规格由MS记录,最好的办法是他们pecoff.doc提供信息:

http://msdn.microsoft.com/en-us/windows/hardware/gg463119.aspx

中的最后一项被描述为CLR运行头,如果我没有记错它使用有不同的含义(这就是为什么有人称之为COM描述符),但现在用于指向CLR元数据。

最后三位的顺序是IAT,DelayImport,CLR。其他任何事情都是错的,目录显然不会奇迹般地转向。

+2

在2001年之前,.NET最初被称为'COM + Runtime'(或者也是COM2或NGWS ...),因此可以在各种.H文件中看到COR前缀,以及名称'COM运行时描述符“。 – 2011-12-28 16:33:28

0

由于事实上,原有的次序是固定的,在WINNT.H中定义。 即使COM,延迟导入和.NET元数据在目录表中都有固定的位置!有些工具会以自己的名字和顺序显示目录。表示的方式与PE规范无关。