Browse Source

Fix crash in disassembler and decompiler when HasPInvokeInfo=true but PInvokeInfo=null (occurs with unmanaged methods in C++/CLI assemblies)

pull/234/merge 1.0-Beta
Daniel Grunwald 14 years ago
parent
commit
c339b9270a
  1. 2
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 2
      ICSharpCode.Decompiler/Ast/NameVariables.cs
  3. 2
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  4. 2
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs
  5. 3
      ILSpy/Languages/CSharpLanguage.cs

2
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -1151,7 +1151,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -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));

2
ICSharpCode.Decompiler/Ast/NameVariables.cs

@ -284,6 +284,8 @@ namespace ICSharpCode.Decompiler.Ast @@ -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];

2
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -117,7 +117,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -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) + "\"");

2
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -849,7 +849,7 @@ namespace ICSharpCode.Decompiler.ILAst @@ -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;

3
ILSpy/Languages/CSharpLanguage.cs

@ -251,6 +251,9 @@ namespace ICSharpCode.ILSpy @@ -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");

Loading…
Cancel
Save