我正在開發一個解決方案,我需要能夠檢查文件是否屬于我無法信任該文件的擴展名的特定類型。我已經能夠識別 EXE 和 DLL 文件,只需要識別最后一個。目前我不知道如何識別 MSI MSI 與 EXE 和 DLL 有什么不同?我應該在哪里看?例如,為了找到一個 DLL,我正在執行以下操作:if ((ntHeader.FileHeader.Characteristics & IMAGE_FILE_DLL) != 0){ //If DLL then this returns True Else Return False return (ntHeader.FileHeader.Characteristics & IMAGE_FILE_DLL) == 8192;}是否有類似的解決方案來確定文件是否為 MSI 類型?編輯 1 這就是我現在根據 dlatikay 的想法所做的private static ulong FIRST_8_BYTES_OF_MSI_FILE =0xD0CF11E0A1B11AE1;private bool MSICheck(FileStream fileData){ byte[] first8bytes = new byte[8]; using (BinaryReader reader = new BinaryReader(fileData)) { reader.BaseStream.Seek(0, SeekOrigin.Begin); reader.Read(first8bytes, 0, 7); } ulong sum = BitConverter.ToUInt64(first8bytes, 0); //string hexString = BitConverter.ToString(first8bytes); bool returnval = sum == FIRST_8_BYTES_OF_MSI_FILE; return returnval; //D0 CF 11 E0 A1 B1 1A E1 First 8 hexadecimal of a MSI package //return false;}但是這種方法無法將我的測試 msi 文件作為 msi 文件調用,所以我猜我做錯了什么?我的解決方案:在dlatikay的指導下private static string FIRST_8_BYTES_OF_MSI_FILE = "D0CF11E0A1B11AE1";private bool MSICheck(FileStream fileData){ byte[] first8bytes = new byte[8]; using (BinaryReader reader = new BinaryReader(fileData)) { reader.BaseStream.Seek(0, SeekOrigin.Begin); reader.Read(first8bytes, 0, first8bytes.Length); } string sum = BitConverter.ToString(first8bytes).Replace("-",""); ; bool returnval = sum.Equals(FIRST_8_BYTES_OF_MSI_FILE); return returnval; //D0 CF 11 E0 A1 B1 1A E1 First 8 hexadecimal of a MSI package //return false;}
如何檢查文件頭結構以識別 MSI 文件
慕婉清6462132
2021-07-03 14:51:04