Created
January 23, 2012 13:55
-
-
Save Tak/1663276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool IsManagedAssembly (string file) | |
{ | |
try { | |
using (Stream fs = new FileStream (file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { | |
BinaryReader reader = new BinaryReader(fs); | |
//The 4-byte PE Header indicator is at 0x3C | |
fs.Position = 0x3C; | |
uint peHeader = reader.ReadUInt32(); | |
//Jump to the CLR header start location at 0xE8 past the PE header | |
fs.Position = peHeader + 0xe8; | |
// These two bytes will be nonzero for managed assemblies, | |
// and zero for native dlls | |
return (0UL != reader.ReadUInt64 ()); | |
}// using fs | |
} catch { } // Don't care | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment