为什么我没有得到“PE”

本文关键字:PE 为什么 | 更新日期: 2023-09-27 18:05:47

来自PE规格:

在位置0x3c处,存根具有PE签名的文件偏移量。此信息使Windows能够正确执行映像文件,即使它有一个MS DOS存根。这个文件偏移量位于链接时定位0x3c

2.2。签名(仅限图像)
MS DOS存根后,在偏移量0x3c指定的文件偏移量处,是一个4字节的签名,用于标识文件为PE格式的映像文件。此签名为"PE'0'0"(即字母" P "answers" E "后面跟着两个空字节)。

I try read these bytes:

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字符)…为什么我得到这样的结果?

为什么我没有得到“PE��”

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