From fd18add5a229902bd052314673b0d97645ba5a33 Mon Sep 17 00:00:00 2001 From: de4dot Date: Thu, 15 Mar 2012 19:03:22 +0100 Subject: [PATCH] Add method to detect .NET type --- blocks/DotNetUtils.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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; + } } }