Browse Source

Disassembler bugfixes.

pull/1/head
Daniel Grunwald 15 years ago
parent
commit
1ee3aee83e
  1. 8
      ICSharpCode.Decompiler/FlowAnalysis/OpCodeInfo.cs
  2. 29
      ILSpy/Disassembler/ReflectionDisassembler.cs
  3. 1
      ILSpy/TextView/DecompilerTextView.cs

8
ICSharpCode.Decompiler/FlowAnalysis/OpCodeInfo.cs

@ -205,7 +205,7 @@ namespace ICSharpCode.Decompiler
// CanThrow is true by default - most OO instructions can throw, so we don't specify CanThrow all of the time // CanThrow is true by default - most OO instructions can throw, so we don't specify CanThrow all of the time
new OpCodeInfo(OpCodes.Box), new OpCodeInfo(OpCodes.Box),
new OpCodeInfo(OpCodes.Callvirt), new OpCodeInfo(OpCodes.Callvirt),
new OpCodeInfo(OpCodes.Castclass), // (output type not Input0 as type arguments may change) new OpCodeInfo(OpCodes.Castclass),
new OpCodeInfo(OpCodes.Cpobj), new OpCodeInfo(OpCodes.Cpobj),
new OpCodeInfo(OpCodes.Initobj) { CanThrow = false }, new OpCodeInfo(OpCodes.Initobj) { CanThrow = false },
new OpCodeInfo(OpCodes.Isinst) { CanThrow = false }, new OpCodeInfo(OpCodes.Isinst) { CanThrow = false },
@ -232,11 +232,11 @@ namespace ICSharpCode.Decompiler
new OpCodeInfo(OpCodes.Ldstr) { CanThrow = false }, new OpCodeInfo(OpCodes.Ldstr) { CanThrow = false },
new OpCodeInfo(OpCodes.Ldtoken) { CanThrow = false }, new OpCodeInfo(OpCodes.Ldtoken) { CanThrow = false },
new OpCodeInfo(OpCodes.Ldvirtftn), new OpCodeInfo(OpCodes.Ldvirtftn),
//new OpCodeInfo(OpCodes.Mkrefany), don't enable this without checking what it is new OpCodeInfo(OpCodes.Mkrefany),
new OpCodeInfo(OpCodes.Newarr), new OpCodeInfo(OpCodes.Newarr),
new OpCodeInfo(OpCodes.Newobj), new OpCodeInfo(OpCodes.Newobj),
//new OpCodeInfo(OpCodes.Mkrefany), don't enable this without checking what it is new OpCodeInfo(OpCodes.Refanytype) { CanThrow = false },
//new OpCodeInfo(OpCodes.Refanyval), don't enable this without checking what it is new OpCodeInfo(OpCodes.Refanyval),
new OpCodeInfo(OpCodes.Rethrow), new OpCodeInfo(OpCodes.Rethrow),
new OpCodeInfo(OpCodes.Sizeof) { CanThrow = false }, new OpCodeInfo(OpCodes.Sizeof) { CanThrow = false },
new OpCodeInfo(OpCodes.Stelem_Any), new OpCodeInfo(OpCodes.Stelem_Any),

29
ILSpy/Disassembler/ReflectionDisassembler.cs

@ -142,13 +142,17 @@ namespace ICSharpCode.ILSpy.Disassembler
WriteFlags(method.ImplAttributes & ~(MethodImplAttributes.CodeTypeMask | MethodImplAttributes.ManagedMask), methodImpl); WriteFlags(method.ImplAttributes & ~(MethodImplAttributes.CodeTypeMask | MethodImplAttributes.ManagedMask), methodImpl);
output.Unindent(); output.Unindent();
OpenBlock(isInType); if (method.HasBody || method.HasCustomAttributes) {
OpenBlock(defaultCollapsed: isInType);
WriteAttributes(method.CustomAttributes); WriteAttributes(method.CustomAttributes);
if (method.HasBody) if (method.HasBody)
methodBodyDisassembler.Disassemble(method.Body); methodBodyDisassembler.Disassemble(method.Body);
CloseBlock("End of method " + method.DeclaringType.Name + "." + method.Name); CloseBlock("End of method " + method.DeclaringType.Name + "." + method.Name);
} else {
output.WriteLine();
}
} }
void WriteParameters(Collection<ParameterDefinition> parameters) void WriteParameters(Collection<ParameterDefinition> parameters)
@ -181,6 +185,7 @@ namespace ICSharpCode.ILSpy.Disassembler
{ FieldAttributes.InitOnly, "initonly" }, { FieldAttributes.InitOnly, "initonly" },
{ FieldAttributes.SpecialName, "specialname" }, { FieldAttributes.SpecialName, "specialname" },
{ FieldAttributes.RTSpecialName, "rtspecialname" }, { FieldAttributes.RTSpecialName, "rtspecialname" },
{ FieldAttributes.NotSerialized, "notserialized" },
}; };
public void DisassembleField(FieldDefinition field) public void DisassembleField(FieldDefinition field)
@ -195,8 +200,14 @@ namespace ICSharpCode.ILSpy.Disassembler
output.Write(" = "); output.Write(" = ");
DisassemblerHelpers.WriteOperand(output, field.Constant); DisassemblerHelpers.WriteOperand(output, field.Constant);
} }
if (field.HasCustomAttributes) {
OpenBlock(false);
WriteAttributes(field.CustomAttributes);
CloseBlock();
} else {
output.WriteLine(); output.WriteLine();
} }
}
#endregion #endregion
#region Disassemble Property #region Disassemble Property
@ -296,6 +307,7 @@ namespace ICSharpCode.ILSpy.Disassembler
{ TypeAttributes.Import, "import" }, { TypeAttributes.Import, "import" },
{ TypeAttributes.Serializable, "serializable" }, { TypeAttributes.Serializable, "serializable" },
{ TypeAttributes.BeforeFieldInit, "beforefieldinit" }, { TypeAttributes.BeforeFieldInit, "beforefieldinit" },
{ TypeAttributes.HasSecurity, null },
}; };
public void DisassembleType(TypeDefinition type) public void DisassembleType(TypeDefinition type)
@ -311,16 +323,19 @@ namespace ICSharpCode.ILSpy.Disassembler
WriteFlags(type.Attributes & ~masks, typeAttributes); WriteFlags(type.Attributes & ~masks, typeAttributes);
output.Write(DisassemblerHelpers.Escape(type.Name)); output.Write(DisassemblerHelpers.Escape(type.Name));
output.MarkFoldStart(defaultCollapsed: isInType);
output.WriteLine();
if (type.BaseType != null) { if (type.BaseType != null) {
output.WriteLine();
output.Indent(); output.Indent();
output.Write("extends "); output.Write("extends ");
type.BaseType.WriteTo(output, true); type.BaseType.WriteTo(output, true);
output.WriteLine();
output.Unindent(); output.Unindent();
} }
OpenBlock(isInType); output.WriteLine("{");
output.Indent();
bool oldIsInType = isInType; bool oldIsInType = isInType;
isInType = true; isInType = true;
WriteAttributes(type.CustomAttributes); WriteAttributes(type.CustomAttributes);
@ -351,7 +366,6 @@ namespace ICSharpCode.ILSpy.Disassembler
foreach (var prop in type.Properties) { foreach (var prop in type.Properties) {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
DisassembleProperty(prop); DisassembleProperty(prop);
output.WriteLine();
} }
output.WriteLine(); output.WriteLine();
} }
@ -374,9 +388,8 @@ namespace ICSharpCode.ILSpy.Disassembler
output.WriteLine(); output.WriteLine();
} }
} }
output.WriteLine();
} }
CloseBlock("// End of class " + type.FullName); CloseBlock("End of class " + type.FullName);
isInType = oldIsInType; isInType = oldIsInType;
} }
#endregion #endregion
@ -439,7 +452,7 @@ namespace ICSharpCode.ILSpy.Disassembler
long tested = 0; long tested = 0;
foreach (var pair in flagNames) { foreach (var pair in flagNames) {
tested |= pair.Key; tested |= pair.Key;
if ((val & pair.Key) != 0) { if ((val & pair.Key) != 0 && pair.Value != null) {
output.Write(pair.Value); output.Write(pair.Value);
output.Write(' '); output.Write(' ');
} }
@ -453,8 +466,10 @@ namespace ICSharpCode.ILSpy.Disassembler
long val = Convert.ToInt64(enumValue); long val = Convert.ToInt64(enumValue);
foreach (var pair in enumNames) { foreach (var pair in enumNames) {
if (pair.Key == val) { if (pair.Key == val) {
if (pair.Value != null) {
output.Write(pair.Value); output.Write(pair.Value);
output.Write(' '); output.Write(' ');
}
return; return;
} }
} }

1
ILSpy/TextView/DecompilerTextView.cs

@ -88,6 +88,7 @@ namespace ICSharpCode.ILSpy.TextView
if (currentCancellationTokenSource == myCancellationTokenSource) { if (currentCancellationTokenSource == myCancellationTokenSource) {
currentCancellationTokenSource = null; currentCancellationTokenSource = null;
waitAdorner.Visibility = Visibility.Collapsed; waitAdorner.Visibility = Visibility.Collapsed;
textEditor.ScrollToHome();
foldingManager.Clear(); foldingManager.Clear();
try { try {
SmartTextOutput textOutput = task.Result; SmartTextOutput textOutput = task.Result;

Loading…
Cancel
Save