|
|
@ -27,7 +27,7 @@ namespace ICSharpCode.Decompiler.Disassembler |
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Disassembles a method body.
|
|
|
|
/// Disassembles a method body.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public sealed class MethodBodyDisassembler |
|
|
|
public class MethodBodyDisassembler |
|
|
|
{ |
|
|
|
{ |
|
|
|
readonly ITextOutput output; |
|
|
|
readonly ITextOutput output; |
|
|
|
readonly bool detectControlStructure; |
|
|
|
readonly bool detectControlStructure; |
|
|
@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Disassembler |
|
|
|
this.cancellationToken = cancellationToken; |
|
|
|
this.cancellationToken = cancellationToken; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Disassemble(MethodBody body/*, MemberMapping methodMapping*/) |
|
|
|
public void Disassemble(MethodBody body) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// start writing IL code
|
|
|
|
// start writing IL code
|
|
|
|
MethodDefinition method = body.Method; |
|
|
|
MethodDefinition method = body.Method; |
|
|
@ -61,20 +61,7 @@ namespace ICSharpCode.Decompiler.Disassembler |
|
|
|
WriteStructureBody(new ILStructure(body), branchTargets, ref inst, method.Body.CodeSize); |
|
|
|
WriteStructureBody(new ILStructure(body), branchTargets, ref inst, method.Body.CodeSize); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
foreach (var inst in method.Body.Instructions) { |
|
|
|
foreach (var inst in method.Body.Instructions) { |
|
|
|
//var startLocation = output.Location;
|
|
|
|
WriteInstruction(output, inst); |
|
|
|
inst.WriteTo(output); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
if (debugSymbols != null) { |
|
|
|
|
|
|
|
// add IL code mappings - used in debugger
|
|
|
|
|
|
|
|
debugSymbols.SequencePoints.Add( |
|
|
|
|
|
|
|
new SequencePoint() { |
|
|
|
|
|
|
|
StartLocation = output.Location, |
|
|
|
|
|
|
|
EndLocation = output.Location, |
|
|
|
|
|
|
|
ILRanges = new ILRange[] { new ILRange(inst.Offset, inst.Next == null ? method.Body.CodeSize : inst.Next.Offset) } |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output.WriteLine(); |
|
|
|
output.WriteLine(); |
|
|
|
} |
|
|
|
} |
|
|
|
WriteExceptionHandlers(body); |
|
|
|
WriteExceptionHandlers(body); |
|
|
@ -191,19 +178,7 @@ namespace ICSharpCode.Decompiler.Disassembler |
|
|
|
if (!isFirstInstructionInStructure && (prevInstructionWasBranch || branchTargets.Contains(offset))) { |
|
|
|
if (!isFirstInstructionInStructure && (prevInstructionWasBranch || branchTargets.Contains(offset))) { |
|
|
|
output.WriteLine(); // put an empty line after branches, and in front of branch targets
|
|
|
|
output.WriteLine(); // put an empty line after branches, and in front of branch targets
|
|
|
|
} |
|
|
|
} |
|
|
|
//var startLocation = output.Location;
|
|
|
|
WriteInstruction(output, inst); |
|
|
|
inst.WriteTo(output); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*// add IL code mappings - used in debugger
|
|
|
|
|
|
|
|
if (debugSymbols != null) { |
|
|
|
|
|
|
|
debugSymbols.SequencePoints.Add( |
|
|
|
|
|
|
|
new SequencePoint() { |
|
|
|
|
|
|
|
StartLocation = startLocation, |
|
|
|
|
|
|
|
EndLocation = output.Location, |
|
|
|
|
|
|
|
ILRanges = new ILRange[] { new ILRange(inst.Offset, inst.Next == null ? codeSize : inst.Next.Offset) } |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output.WriteLine(); |
|
|
|
output.WriteLine(); |
|
|
|
|
|
|
|
|
|
|
|
prevInstructionWasBranch = inst.OpCode.FlowControl == FlowControl.Branch |
|
|
|
prevInstructionWasBranch = inst.OpCode.FlowControl == FlowControl.Branch |
|
|
@ -237,5 +212,10 @@ namespace ICSharpCode.Decompiler.Disassembler |
|
|
|
throw new NotSupportedException(); |
|
|
|
throw new NotSupportedException(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void WriteInstruction(ITextOutput output, Instruction instruction) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
instruction.WriteTo(output); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|