0

我正在编写一个生成 .NET 程序集清单的库,我需要获取程序集模块的图像基础值。如何在 C# 中获取它?

4

1 回答 1

3

您必须阅读 DLL 或 EXE 的 Portable Executable Header。可以在此处找到执行此操作的说明:

在 C# http://code.cheesydesign.com/?p=572中读取可移植可执行文件 (PE) 标头

ImageBase位于IMAGE_OPTIONAL_HEADER32

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct IMAGE_OPTIONAL_HEADER32 {
  public UInt16 Magic;
  public Byte MajorLinkerVersion;
  public Byte MinorLinkerVersion;
  public UInt32 SizeOfCode;
  public UInt32 SizeOfInitializedData;
  public UInt32 SizeOfUninitializedData;
  public UInt32 AddressOfEntryPoint;
  public UInt32 BaseOfCode;
  public UInt32 BaseOfData;
  public UInt32 ImageBase;         <------------------ Here
  public UInt32 SectionAlignment;
  public UInt32 FileAlignment;
  public UInt16 MajorOperatingSystemVersion;
  public UInt16 MinorOperatingSystemVersion;
  public UInt16 MajorImageVersion;
  public UInt16 MinorImageVersion;
  public UInt16 MajorSubsystemVersion;
  public UInt16 MinorSubsystemVersion;
  public UInt32 Win32VersionValue;
  public UInt32 SizeOfImage;
  public UInt32 SizeOfHeaders;
  public UInt32 CheckSum;
  public UInt16 Subsystem;
  public UInt16 DllCharacteristics;
  public UInt32 SizeOfStackReserve;
  public UInt32 SizeOfStackCommit;
  public UInt32 SizeOfHeapReserve;
  public UInt32 SizeOfHeapCommit;
  public UInt32 LoaderFlags;
  public UInt32 NumberOfRvaAndSizes;
}
于 2012-05-08T15:48:29.027 回答