Browse Source

Decompiling class 'ReversiForm'.

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

1930
bin/Debug/output.cs

File diff suppressed because it is too large Load Diff

11
src/AstMetodBodyBuilder.cs

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

12
src/ByteCode.StackAnalysis.cs

@ -36,6 +36,18 @@ namespace Decompiler @@ -36,6 +36,18 @@ namespace Decompiler
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) {
case FlowControl.Branch:
this.BranchTarget.MergeStackBeforeWith(this.StackAfter);

17
src/ByteCodeCollection.cs

@ -56,13 +56,20 @@ namespace Decompiler @@ -56,13 +56,20 @@ namespace Decompiler
}
foreach(ByteCode byteCode in this) {
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) {
ByteCode target = GetByOffset(inst.Offset);
operands.Add(target);
target.BranchesHere.Add(byteCode);
}
byteCode.Operand = operands.ToArray();
} else {
ByteCode target = GetByOffset(((Instruction)byteCode.Operand).Offset);
byteCode.Operand = target;
target.BranchesHere.Add(byteCode);
}
}
foreach(ByteCode byteCode in this) {
if (byteCode.CanBranch) {
byteCode.BranchTarget.BranchesHere.Add(byteCode);
}
}
UpdateNextPrevious();
UpdateStackAnalysis(methodDef);

3
src/CilStack.cs

@ -120,7 +120,8 @@ namespace Decompiler @@ -120,7 +120,8 @@ namespace Decompiler
merged = stack1.Clone();
for (int i = 0; i < count; 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;
}
}

2
src/MainForm.cs

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

Loading…
Cancel
Save