diff --git a/blocks/DotNetUtils.cs b/blocks/DotNetUtils.cs index 76f3b429..2f9d56ab 100644 --- a/blocks/DotNetUtils.cs +++ b/blocks/DotNetUtils.cs @@ -24,6 +24,14 @@ using Mono.Cecil.Cil; using Mono.Cecil.Metadata; namespace de4dot.blocks { + public enum DotNetRuntimeType { + Unknown, + Desktop, + Silverlight, // and WindowsPhone, XNA Xbox360 + CompactFramework, + Zune, + } + class TypeCache { ModuleDefinition module; TypeDefinitionDict typeRefToDef = new TypeDefinitionDict(); @@ -1084,5 +1092,26 @@ namespace de4dot.blocks { typeRef.IsValueType = isValueType; return typeRef; } + + public static DotNetRuntimeType getDotNetRuntimeType(ModuleDefinition module) { + foreach (var modRef in module.AssemblyReferences) { + if (modRef.Name != "mscorlib") + continue; + if (modRef.PublicKeyToken == null || modRef.PublicKeyToken.Length == 0) + continue; + switch (BitConverter.ToString(modRef.PublicKeyToken).Replace("-", "").ToLowerInvariant()) { + case "b77a5c561934e089": + return DotNetRuntimeType.Desktop; + case "7cec85d7bea7798e": + return DotNetRuntimeType.Silverlight; + case "969db8053d3322ac": + return DotNetRuntimeType.CompactFramework; + case "e92a8b81eba7ceb7": + return DotNetRuntimeType.Zune; + } + } + + return DotNetRuntimeType.Unknown; + } } }