Is there a way to programatically determine if a binary is managed code?
-
So i think it would be handy if I could write a function that does this: If \\server\share\binary.exe is managed code Do this Otherwise it is not managed code Do that Is such a thing possible? Thanks, Ian
-
So i think it would be handy if I could write a function that does this: If \\server\share\binary.exe is managed code Do this Otherwise it is not managed code Do that Is such a thing possible? Thanks, Ian
I know this function works with managed and unmanaged dlls. You could try it with executables though:
public bool IsManaged(string filePath) { byte[] Data = new byte[4096]; FileInfo file = new FileInfo(filePath); FileStream fin = file.OpenRead(); int read = fin.Read(Data,0,Data.Length); fin.Close(); // Verify this is a executable/dll if ((Data[1] << 8 | Data[0]) != 0x5a4d) return false; // This will get the address for the WinNT header Int32 iWinNTHdr = Data[63]<<24 | Data[62]<<16 | Data[61] << 8 | Data[60]; // Verify this is an NT address if ((Data[iWinNTHdr+3] << 24 | Data[iWinNTHdr+2] << 16 | Data[iWinNTHdr+1] << 8 | Data[iWinNTHdr]) != 0x00004550) return false; Int32 iLightningAddr = iWinNTHdr + 24 + 208; Int32 iSum=0; Int32 iTop = iLightningAddr + 8; for (int i = iLightningAddr; i < iTop; i++) iSum|=Data[i]; if (iSum == 0) return false; else return true; }
Got this from a blog entry here: http://blogs.msdn.com/adam_nathan/archive/2003/10/26/56786.aspx[^] Hope this helps, Nathan --------------------------- Hmmm... what's a signature?