Browse Source

Decompiling class 'ReversiForm'.

Initial support for the switch bytecode
pull/1/head^2
David Srbecký 17 years ago
parent
commit
a26fd6c0b2
  1. 1982
      bin/Debug/output.cs
  2. 27
      src/AstMetodBodyBuilder.cs
  3. 12
      src/ByteCode.StackAnalysis.cs
  4. 19
      src/ByteCodeCollection.cs
  5. 3
      src/CilStack.cs
  6. 2
      src/MainForm.cs

1982
bin/Debug/output.cs

File diff suppressed because it is too large Load Diff

27
src/AstMetodBodyBuilder.cs

@ -29,6 +29,8 @@ namespace Decompiler
{ {
Ast.BlockStatement astBlock = new Ast.BlockStatement(); Ast.BlockStatement astBlock = new Ast.BlockStatement();
if (methodDef.Body == null) return astBlock;
methodDef.Body.Simplify(); methodDef.Body.Simplify();
ByteCodeCollection body = new ByteCodeCollection(methodDef); ByteCodeCollection body = new ByteCodeCollection(methodDef);
@ -521,14 +523,19 @@ namespace Decompiler
case Code.Ldc_R8: return new Ast.PrimitiveExpression(operand, null); case Code.Ldc_R8: return new Ast.PrimitiveExpression(operand, null);
case Code.Ldfld: case Code.Ldfld:
case Code.Ldsfld: { case Code.Ldsfld: {
FieldDefinition field = (FieldDefinition) operand; if (operand is FieldDefinition) {
if (field.IsStatic) { FieldDefinition field = (FieldDefinition) operand;
return new Ast.MemberReferenceExpression( if (field.IsStatic) {
new Ast.IdentifierExpression(field.DeclaringType.FullName), return new Ast.MemberReferenceExpression(
field.Name new Ast.IdentifierExpression(field.DeclaringType.FullName),
); field.Name
);
} else {
return new Ast.MemberReferenceExpression(arg1, field.Name);
}
} else { } else {
return new Ast.MemberReferenceExpression(arg1, field.Name); // TODO: Static accesses
return new Ast.MemberReferenceExpression(arg1, ((FieldReference)operand).Name);
} }
} }
case Code.Stfld: case Code.Stfld:
@ -634,7 +641,11 @@ namespace Decompiler
static Ast.Expression Convert(Ast.Expression expr, Cecil.TypeReference reqType) static Ast.Expression Convert(Ast.Expression expr, Cecil.TypeReference reqType)
{ {
return Convert(expr, reqType.FullName); if (reqType == null) {
return expr;
} else {
return Convert(expr, reqType.FullName);
}
} }
static Ast.Expression Convert(Ast.Expression expr, string reqType) static Ast.Expression Convert(Ast.Expression expr, string reqType)

12
src/ByteCode.StackAnalysis.cs

@ -36,6 +36,18 @@ namespace Decompiler
stackAfter = SimulateEffectOnStack(this.StackBefore); stackAfter = SimulateEffectOnStack(this.StackBefore);
if (this.OpCode.Code == Code.Endfinally) {
return; // TODO
}
if (this.OpCode.Code == Code.Switch) {
this.Next.MergeStackBeforeWith(this.StackAfter);
foreach(ByteCode target in (ByteCode[])this.Operand) {
target.MergeStackBeforeWith(this.StackAfter);
}
return;
}
switch(this.OpCode.FlowControl) { switch(this.OpCode.FlowControl) {
case FlowControl.Branch: case FlowControl.Branch:
this.BranchTarget.MergeStackBeforeWith(this.StackAfter); this.BranchTarget.MergeStackBeforeWith(this.StackAfter);

19
src/ByteCodeCollection.cs

@ -56,12 +56,19 @@ namespace Decompiler
} }
foreach(ByteCode byteCode in this) { foreach(ByteCode byteCode in this) {
if (byteCode.CanBranch) { if (byteCode.CanBranch) {
byteCode.Operand = GetByOffset(((Instruction)byteCode.Operand).Offset); if (byteCode.Operand is Instruction[]) {
} List<ByteCode> operands = new List<ByteCode>();
} foreach(Instruction inst in (Instruction[])byteCode.Operand) {
foreach(ByteCode byteCode in this) { ByteCode target = GetByOffset(inst.Offset);
if (byteCode.CanBranch) { operands.Add(target);
byteCode.BranchTarget.BranchesHere.Add(byteCode); target.BranchesHere.Add(byteCode);
}
byteCode.Operand = operands.ToArray();
} else {
ByteCode target = GetByOffset(((Instruction)byteCode.Operand).Offset);
byteCode.Operand = target;
target.BranchesHere.Add(byteCode);
}
} }
} }
UpdateNextPrevious(); UpdateNextPrevious();

3
src/CilStack.cs

@ -120,7 +120,8 @@ namespace Decompiler
merged = stack1.Clone(); merged = stack1.Clone();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
if (!stack1[i].Equals(stack2[i])) { if (!stack1[i].Equals(stack2[i])) {
merged[i] = new CilStackSlot(null, null); // Merge slots // TODO: Do the merge
// merged[i] = new CilStackSlot(null, null); // Merge slots
same = false; same = false;
} }
} }

2
src/MainForm.cs

@ -39,7 +39,7 @@ namespace Decompiler
x += checkBox.Width + 10; x += checkBox.Width + 10;
} }
} }
filter.Text = "Board"; filter.Text = "ReversiForm";
} }
public string SourceCode { public string SourceCode {

Loading…
Cancel
Save