diff --git a/ICSharpCode.Decompiler/Ast/AstBuilder.cs b/ICSharpCode.Decompiler/Ast/AstBuilder.cs index d6f1bf4a6..a9f5e3063 100644 --- a/ICSharpCode.Decompiler/Ast/AstBuilder.cs +++ b/ICSharpCode.Decompiler/Ast/AstBuilder.cs @@ -1159,7 +1159,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 502ed57bb..2ced5f8d9 100644 --- a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs @@ -124,7 +124,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 67ab007d7..0c628bb6f 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -235,6 +235,46 @@ 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; + } + 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"); + 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 using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) { AstBuilder codeDomBuilder = CreateAstBuilder(options, currentModule: assembly.AssemblyDefinition.MainModule);