From 8b611e50a48934f038f6532a2f3162d58a1b6a53 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 29 May 2011 20:01:35 +0200 Subject: [PATCH 1/3] Show architecture of assembly being decompiled. --- ILSpy/Languages/CSharpLanguage.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index ad3ee5ae1..8e7680a32 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -230,6 +230,29 @@ namespace ICSharpCode.ILSpy WriteProjectFile(new TextOutputWriter(output), files, assembly.AssemblyDefinition.MainModule); } else { base.DecompileAssembly(assembly, output, options); + output.WriteLine(); + ModuleDefinition mainModule = assembly.AssemblyDefinition.MainModule; + if (mainModule.EntryPoint != null) { + output.Write("// Entry point: "); + output.WriteReference(mainModule.EntryPoint.DeclaringType.FullName + "." + mainModule.EntryPoint.Name, mainModule.EntryPoint); + output.WriteLine(); + } + switch (mainModule.Architecture) { + case TargetArchitecture.I386: + if ((mainModule.Attributes & ModuleAttributes.Required32Bit) == ModuleAttributes.Required32Bit) + output.WriteLine("// Architecture: x86"); + else + output.WriteLine("// Architecture: AnyCPU"); + break; + case TargetArchitecture.AMD64: + output.WriteLine("// Architecture: x64"); + break; + case TargetArchitecture.IA64: + output.WriteLine("// Architecture: Itanium-64"); + break; + } + output.WriteLine(); + // don't automatically load additional assemblies when an assembly node is selected in the tree view using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) { AstBuilder codeDomBuilder = CreateAstBuilder(options, currentModule: assembly.AssemblyDefinition.MainModule); From f2c001ab55c1740fc66a00c2b64e8023e2603010 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 29 May 2011 20:03:04 +0200 Subject: [PATCH 2/3] Show .NET runtime version. --- ILSpy/Languages/CSharpLanguage.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 8e7680a32..699fee3ad 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -251,6 +251,20 @@ namespace ICSharpCode.ILSpy output.WriteLine("// Architecture: Itanium-64"); break; } + switch (mainModule.Runtime) { + case TargetRuntime.Net_1_0: + output.WriteLine("// Runtime: .NET 1.0"); + break; + case TargetRuntime.Net_1_1: + output.WriteLine("// Runtime: .NET 1.1"); + break; + case TargetRuntime.Net_2_0: + output.WriteLine("// Runtime: .NET 2.0"); + break; + case TargetRuntime.Net_4_0: + output.WriteLine("// Runtime: .NET 4.0"); + break; + } output.WriteLine(); // don't automatically load additional assemblies when an assembly node is selected in the tree view From c339b9270a7b620c6b97b38e27bd7fbf9dbbd0fd Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 29 May 2011 20:21:18 +0200 Subject: [PATCH 3/3] Fix crash in disassembler and decompiler when HasPInvokeInfo=true but PInvokeInfo=null (occurs with unmanaged methods in C++/CLI assemblies) --- ICSharpCode.Decompiler/Ast/AstBuilder.cs | 2 +- ICSharpCode.Decompiler/Ast/NameVariables.cs | 2 ++ ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs | 2 +- ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs | 2 +- ILSpy/Languages/CSharpLanguage.cs | 3 +++ 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index 0c50975b4..f39a4cbf0 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -1151,7 +1151,7 @@ namespace ICSharpCode.Decompiler.Ast MethodImplAttributes implAttributes = methodDefinition.ImplAttributes & ~MethodImplAttributes.CodeTypeMask; #region DllImportAttribute - if (methodDefinition.HasPInvokeInfo) { + if (methodDefinition.HasPInvokeInfo && methodDefinition.PInvokeInfo != null) { PInvokeInfo info = methodDefinition.PInvokeInfo; Ast.Attribute dllImport = CreateNonCustomAttribute(typeof(DllImportAttribute)); dllImport.Arguments.Add(new PrimitiveExpression(info.Module.Name)); diff --git a/ICSharpCode.Decompiler/Ast/NameVariables.cs b/ICSharpCode.Decompiler/Ast/NameVariables.cs index defc30202..9b3632119 100644 --- a/ICSharpCode.Decompiler/Ast/NameVariables.cs +++ b/ICSharpCode.Decompiler/Ast/NameVariables.cs @@ -284,6 +284,8 @@ namespace ICSharpCode.Decompiler.Ast string GetNameByType(TypeReference type) { + type = TypeAnalysis.UnpackModifiers(type); + GenericInstanceType git = type as GenericInstanceType; if (git != null && git.ElementType.FullName == "System.Nullable`1" && git.GenericArguments.Count == 1) { type = ((GenericInstanceType)type).GenericArguments[0]; diff --git a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs index 4e144924e..f623597da 100644 --- a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs @@ -117,7 +117,7 @@ namespace ICSharpCode.Decompiler.Disassembler if ((method.Attributes & MethodAttributes.PInvokeImpl) == MethodAttributes.PInvokeImpl) { output.Write("pinvokeimpl"); - if (method.HasPInvokeInfo) { + if (method.HasPInvokeInfo && method.PInvokeInfo != null) { PInvokeInfo info = method.PInvokeInfo; output.Write("(\"" + NRefactory.CSharp.OutputVisitor.ConvertString(info.Module.Name) + "\""); diff --git a/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs b/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs index 3667bc895..9eacc13d7 100644 --- a/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs +++ b/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs @@ -849,7 +849,7 @@ namespace ICSharpCode.Decompiler.ILAst return null; } - static TypeReference UnpackModifiers(TypeReference type) + internal static TypeReference UnpackModifiers(TypeReference type) { while (type is OptionalModifierType || type is RequiredModifierType) type = ((TypeSpecification)type).ElementType; diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 699fee3ad..2bca8b859 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -251,6 +251,9 @@ namespace ICSharpCode.ILSpy output.WriteLine("// Architecture: Itanium-64"); break; } + if ((mainModule.Attributes & ModuleAttributes.ILOnly) == 0) { + output.WriteLine("// This assembly contains unmanaged code."); + } switch (mainModule.Runtime) { case TargetRuntime.Net_1_0: output.WriteLine("// Runtime: .NET 1.0");