来自PE规范:
在 location
0x3c
,存根具有 PE 签名的文件偏移量。此信息使 Windows 能够正确执行映像文件,即使它具有 MS DOS 存根。此文件偏移量放置在0x3c
链接期间的位置。2.2. 签名(仅图像)
在 MS DOS 存根之后,在 offset 指定的文件偏移处0x3c
,是一个 4 字节的签名,将文件标识为 PE 格式的图像文件。这个签名是“PE\0\0”(字母“P”和“E”后跟两个空字节)。
我尝试读取这些字节:
using System;
using System.IO;
class Program {
const String fileName = @".\some_application.exe";
const Int64 peMarkerPosition = 0x3c;
static void Main(string[] args) {
using (FileStream fs = new FileStream(fileName, FileMode.Open,
FileAccess.Read)) {
Byte[] marker = new Byte[4];
fs.Position = peMarkerPosition;
fs.Read(marker, 0, marker.Length);
// Now I expect 'marker'has such bytes: "PE\0\0".
fs.Close();
foreach (Byte b in marker) {
Console.Write(Convert.ToChar(b)); // But I see other values...
}
Console.WriteLine("\nPress any key for exit...");
Console.ReadKey();
}
}
}
但是marker
变量有0x08
, 0x01
,0x00
和x0x00
字节(第一个和第二个不是P
和E
字符)......为什么我得到这样的结果?