const int c_LinkerTimestampOffset = 8;
然后:
int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
此代码提取存储在程序集中的IMAGE_FILE_HEADER 结构TimeDateStamp
的成员。结构定义如下:
typedef struct _IMAGE_FILE_HEADER {
WORD Machine;
WORD NumberOfSections;
DWORD TimeDateStamp;
DWORD PointerToSymbolTable;
DWORD NumberOfSymbols;
WORD SizeOfOptionalHeader;
WORD Characteristics;
} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
andWORD
是两个字节,应该是两个字节对齐的。当我使用 Visual C++ 10 编译以下代码时:
IMAGE_FILE_HEADER header;
char* start = (char*)&header;
char* field = (char*)(&header.TimeDateStamp);
int diff = field - start;
diff
等于4
我个人的预期。
这是 C# 代码中的错误吗?为什么8
使用偏移值?