PE文件,文件头两字节为0x4d5a即("MZ"),然后到地址0x3c中读出PE文件头(_IMAGE_NT_HEADERS),
判断文件头结构的标记是否为17744(即"PE")。
fsTemp = new FileStream("c:\temp\test.dll", FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 512, false);
if (fsTemp.Length > 2)
{
bBuf = new byte[2];
fsTemp.Position = 0;
fsTemp.Read(bBuf, 0, 2);
if (BitConverter.ToUInt16(bBuf, 0) == 0x5a4d)
{
fsTemp.Position = 0x3c;
bBuf = new byte[4];
fsTemp.Read(bBuf, 0, 4);
position = BitConverter.ToUInt32(bBuf, 0);
fsTemp.Position = position;
fsTemp.Read(bBuf, 0, 4);
if (BitConverter.ToUInt32(bBuf, 0) == 0x00004550)
return true;
}
}
fsTemp.Close();