PE 导出目录表的 OrdinalBase 字段被忽略?
根据我和其他人的经验 (http://webster.cs.ucr.edu/Page_TechDocs/pe.txt),PE/COFF 规范文档错误地声称序数表中包含的导出地址表索引是相对的到序数基,甚至给出了一个错误的例子(第 5.3 节)。实际上,在 Ordinal Base = 1 的正常情况下,Ordinal Table 中的索引是地址表中基于 0 的索引。我在 VS Studio 生成的 PE 库和 Kernel32.dll 等系统库中看到了这一点。
我的问题是,您是否观察过序数基数不等于 1 的二进制?我想知道这是否是一个相差一错误,或者序数基数是否从未应用于序数表条目。
In my experience and that of others (http://webster.cs.ucr.edu/Page_TechDocs/pe.txt), the PE/COFF specification document incorrectly claims that the Export Address Table indices that are contained in the Ordinal Table are relative to the Ordinal Base, and even gives an incorrect example (Section 5.3). In actuality, the indices in the Ordinal Table are 0-based indices into the Address Table for the normal case in which Ordinal Base = 1. I have seen this in VS Studio generated PE libraries and in system libraries like Kernel32.dll.
My question is, have you ever observed a binary with an Ordinal Base that was not equal to 1? I want to know if this an off-by-one error, or if the Ordinal Base is never applied to Ordinal Table entries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是 mfc42.dll 版本 6.06.8064.0 的转储。
这是它在二进制文件中的样子:
所以是的,看来你是对的,序数表中的索引是基于0。
Here's a dump for mfc42.dll, version 6.06.8064.0.
Here's how it looks in the binary:
So yes, it seems you're right and the indexes in the ordinal table are 0-based.
这不是差一错误,并且序数基数不应用于序数表条目,而是应用于序数本身的计算。是的,Microsoft PE 规范 (http://msdn.microsoft .com/en-us/library/windows/hardware/gg463119.aspx,第 5.3.4 节)是错误的。这就是应该如何完成计算:
或者,以不同的方式表达:
如果我转储我的 mfc42.dll...
...这就是我得到的:
上面的第 7 个函数(例如)是 DllRegisterServer,它对应于以下 mfc42.dll 的十六进制转储中导出序数表中的第 7 个字 (0x0004)。开头是
A7 05
。计算:
It's not an off-by-one error and the Ordinal Base is not applied to the Ordinal Table entries but to the calulation of the ordinal itself. And yes, the Microsoft PE specification (http://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx, section 5.3.4) is wrong. This is how the calculations should be done:
Or, expressed in a different way:
If I dump my mfc42.dll...
...this is what I get:
The 7th function (for example) above is DllRegisterServer, which corresponds to the 7th word (0x0004) in the export ordinal table in the below hex dump of mfc42.dll. The start is
A7 05
.The calculations:
不,PE 导出目录表的 OrdinalBase 字段不会被忽略!
上面提供的示例 (mfc42.dll) 是一个很好的示例(因为它的 Ordinal Base 不是 1)。
关于这个问题,这里有两点评论
:就序数字段而言,转储工具的输出是正确的。它显示,Base 字段为 5。这意味着,当按名称从 mfc42.dll 导入导出函数时,导出地址表中计算的偏移量将为 x-5。 Microsoft 规范第 5.3 节是正确的。
。就提示而言,转储工具的输出不正确。导出表没有提示字段,只有导入表有提示字段。
事实上,序数基数不是在序数表中应用,而是在检索地址表的索引时应用!
NO, PE Export Directory Table's OrdinalBase field is NOT ignored!
The sample provided above (mfc42.dll) is a good one (since its Ordinal Base is not 1).
Here two remarks about this issue:
. the output of the Dump tool is correct as far as the ordinal field is concerned. It shows, that the Base field is 5. This means that, when importing an exported function from mfc42.dll by name, the computed offset in the Export Address Table will be x-5. The Microsoft specification Section 5.3 is correct.
. the output of the Dump tool is NOT correct as far as the Hint is concerned. Export Tables have NO Hint field, ONLY Import tables have a Hint field.
As a matter of fact, the Ordinal Base is applied NOT in the Ordinal Table BUT when retrieving the index of the Address Table!