PE目录名称 [英] Names of PE directories

查看:153
本文介绍了PE目录名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事PE解剖器的工作,遇到了非常不寻常的事情. PE格式的目录名称和顺序似乎随您所处的位置而有所不同:

I'm working on a PE dissector and came across something rather unusual. The names and order of directories in the PE format seem to differ depending on where you look:

来自 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-基数):

In PEInfo (corrected to 0-base):

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资源管理器中:

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的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条目似乎也被切换了.

The numbering and order of these seems to not match properly. In both PEReader and winnt.h, entry 14 is COM Descriptor, but in CFF Explorer this shows as .NET MetaData. The COM and Delay Import entries seem to get switched around too.

这些工具中的几种会弄错这一点似乎很奇怪.哪一个是正确的?我是否缺少新定义?

It seems odd that several of these tools would get this wrong. Which one is correct? Am I missing a newer definition?

推荐答案

您不必使用任何未记录的内容.在 Windows SDK随附的WinNT.h文件中找到了正确的文件. (一旦安装,在我的计算机上,它位于C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v7.0A \ Include)中:

You don't have to use anything undocumented. The correct one are found in the WinNT.h file that comes with the Windows SDK (once installed, on my machine it's in 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

葡萄酒& PEReader定义只是(我相信是)从此.h文件中借用的.

The WINE & PEReader definitions just (correctly I believe) borrow from this .h file.

这里也有提及: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆