1

来自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,0x00x0x00字节(第一个和第二个不是PE字符)......为什么我得到这样的结果?

4

1 回答 1

4

PE 标头本身并非从偏移量 0x3C 开始 - 相反,那里有一个指向 PE 标头开始位置的指针(从文件开头的 32 位文件偏移量)。

于 2015-07-30T15:36:28.343 回答