Browse Source

Target of decompilation is now AboutDialog in the Reversi game.

pull/1/head^2
David Srbecký 18 years ago
parent
commit
bc89f0a071
  1. 2
      src/AstBuilder.cs
  2. 14
      src/ByteCode.StackBehaviour.cs
  3. 39
      src/MainForm.Designer.cs
  4. 7
      src/MainForm.cs
  5. 1
      src/Options.cs
  6. 2
      src/Program.cs

2
src/AstBuilder.cs

@ -111,6 +111,8 @@ namespace Decompiler @@ -111,6 +111,8 @@ namespace Decompiler
public void AddType(TypeDefinition typeDef)
{
if (Options.TypeFilter != null && !typeDef.Name.EndsWith(Options.TypeFilter)) return;
TypeDeclaration astType = CreateType(typeDef);
NamespaceDeclaration astNS = GetCodeNamespace(typeDef.Namespace);
if (astNS != null) {

14
src/ByteCode.StackBehaviour.cs

@ -42,10 +42,11 @@ namespace Decompiler @@ -42,10 +42,11 @@ namespace Decompiler
case StackBehaviour.Popref_popi_popr4: return 3;
case StackBehaviour.Popref_popi_popr8: return 3;
case StackBehaviour.Popref_popi_popref: return 3;
case StackBehaviour.PopAll: throw new Exception("PopAll");
case StackBehaviour.PopAll: return this.StackBefore.Count;
case StackBehaviour.Varpop:
switch(this.OpCode.Code) {
case Code.Call:
case Code.Call:
case Code.Callvirt:
Cecil.MethodReference cecilMethod = ((MethodReference)this.Operand);
if (cecilMethod.HasThis) {
return cecilMethod.Parameters.Count + 1 /* this */;
@ -53,14 +54,15 @@ namespace Decompiler @@ -53,14 +54,15 @@ namespace Decompiler
return cecilMethod.Parameters.Count;
}
case Code.Calli: throw new NotImplementedException();
case Code.Callvirt: throw new NotImplementedException();
case Code.Ret:
if (methodDef.ReturnType.ReturnType.FullName == Constants.Void) {
return 0;
} else {
return 1;
}
case Code.Newobj: throw new NotImplementedException();
case Code.Newobj:
Cecil.MethodReference ctorMethod = ((MethodReference)this.Operand);
return ctorMethod.Parameters.Count;
default: throw new Exception("Unknown Varpop opcode");
}
default: throw new Exception("Unknown pop behaviour: " + this.OpCode.StackBehaviourPop);
@ -80,7 +82,8 @@ namespace Decompiler @@ -80,7 +82,8 @@ namespace Decompiler
case StackBehaviour.Pushref: return 1;
case StackBehaviour.Varpush: // Happens only for calls
switch(this.OpCode.Code) {
case Code.Call:
case Code.Call:
case Code.Callvirt:
Cecil.MethodReference cecilMethod = ((MethodReference)this.Operand);
if (cecilMethod.ReturnType.ReturnType.FullName == Constants.Void) {
return 0;
@ -88,7 +91,6 @@ namespace Decompiler @@ -88,7 +91,6 @@ namespace Decompiler
return 1;
}
case Code.Calli: throw new NotImplementedException();
case Code.Callvirt: throw new NotImplementedException();
default: throw new Exception("Unknown Varpush opcode");
}
default: throw new Exception("Unknown push behaviour: " + this.OpCode.StackBehaviourPush);

39
src/MainForm.Designer.cs generated

@ -38,6 +38,8 @@ namespace Decompiler @@ -38,6 +38,8 @@ namespace Decompiler
this.reduceBtn = new System.Windows.Forms.Button();
this.decompileBtn = new System.Windows.Forms.Button();
this.sourceCodeBox = new System.Windows.Forms.RichTextBox();
this.label1 = new System.Windows.Forms.Label();
this.filter = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.collapseCount)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.reduceCount)).BeginInit();
this.SuspendLayout();
@ -51,7 +53,7 @@ namespace Decompiler @@ -51,7 +53,7 @@ namespace Decompiler
0,
0});
this.collapseCount.Name = "collapseCount";
this.collapseCount.Size = new System.Drawing.Size(120, 26);
this.collapseCount.Size = new System.Drawing.Size(78, 26);
this.collapseCount.TabIndex = 1;
this.collapseCount.Value = new decimal(new int[] {
1000,
@ -62,14 +64,14 @@ namespace Decompiler @@ -62,14 +64,14 @@ namespace Decompiler
//
// reduceCount
//
this.reduceCount.Location = new System.Drawing.Point(308, 12);
this.reduceCount.Location = new System.Drawing.Point(266, 12);
this.reduceCount.Maximum = new decimal(new int[] {
100000,
0,
0,
0});
this.reduceCount.Name = "reduceCount";
this.reduceCount.Size = new System.Drawing.Size(120, 26);
this.reduceCount.Size = new System.Drawing.Size(70, 26);
this.reduceCount.TabIndex = 2;
this.reduceCount.Value = new decimal(new int[] {
1000,
@ -80,7 +82,7 @@ namespace Decompiler @@ -80,7 +82,7 @@ namespace Decompiler
//
// collapseBtn
//
this.collapseBtn.Location = new System.Drawing.Point(138, 12);
this.collapseBtn.Location = new System.Drawing.Point(96, 12);
this.collapseBtn.Name = "collapseBtn";
this.collapseBtn.Size = new System.Drawing.Size(164, 26);
this.collapseBtn.TabIndex = 3;
@ -90,7 +92,7 @@ namespace Decompiler @@ -90,7 +92,7 @@ namespace Decompiler
//
// reduceBtn
//
this.reduceBtn.Location = new System.Drawing.Point(434, 12);
this.reduceBtn.Location = new System.Drawing.Point(342, 12);
this.reduceBtn.Name = "reduceBtn";
this.reduceBtn.Size = new System.Drawing.Size(143, 26);
this.reduceBtn.TabIndex = 4;
@ -102,7 +104,7 @@ namespace Decompiler @@ -102,7 +104,7 @@ namespace Decompiler
//
this.decompileBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.decompileBtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.decompileBtn.Location = new System.Drawing.Point(639, 12);
this.decompileBtn.Location = new System.Drawing.Point(799, 12);
this.decompileBtn.Name = "decompileBtn";
this.decompileBtn.Size = new System.Drawing.Size(109, 26);
this.decompileBtn.TabIndex = 5;
@ -118,16 +120,34 @@ namespace Decompiler @@ -118,16 +120,34 @@ namespace Decompiler
this.sourceCodeBox.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.sourceCodeBox.Location = new System.Drawing.Point(12, 74);
this.sourceCodeBox.Name = "sourceCodeBox";
this.sourceCodeBox.Size = new System.Drawing.Size(736, 603);
this.sourceCodeBox.Size = new System.Drawing.Size(896, 603);
this.sourceCodeBox.TabIndex = 6;
this.sourceCodeBox.Text = "";
this.sourceCodeBox.WordWrap = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(491, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 20);
this.label1.TabIndex = 7;
this.label1.Text = "Filter:";
//
// filter
//
this.filter.Location = new System.Drawing.Point(545, 12);
this.filter.Name = "filter";
this.filter.Size = new System.Drawing.Size(100, 26);
this.filter.TabIndex = 8;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(760, 689);
this.ClientSize = new System.Drawing.Size(920, 689);
this.Controls.Add(this.filter);
this.Controls.Add(this.label1);
this.Controls.Add(this.sourceCodeBox);
this.Controls.Add(this.decompileBtn);
this.Controls.Add(this.reduceBtn);
@ -139,7 +159,10 @@ namespace Decompiler @@ -139,7 +159,10 @@ namespace Decompiler
((System.ComponentModel.ISupportInitialize)(this.collapseCount)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.reduceCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TextBox filter;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox sourceCodeBox;
private System.Windows.Forms.Button decompileBtn;
private System.Windows.Forms.Button reduceBtn;

7
src/MainForm.cs

@ -38,8 +38,9 @@ namespace Decompiler @@ -38,8 +38,9 @@ namespace Decompiler
x += checkBox.Width + 10;
}
}
collapseCount.Value = Options.CollapseExpression;
reduceCount.Value = Options.ReduceGraph;
collapseCount.Value = 0;
reduceCount.Value = 0;
filter.Text = "AboutDialog";
}
public string SourceCode {
@ -56,6 +57,8 @@ namespace Decompiler @@ -56,6 +57,8 @@ namespace Decompiler
ControlFlow.Node.NextNodeID = 0;
Options.CollapseExpression = (int)collapseCount.Value;
Options.ReduceGraph = (int)reduceCount.Value;
Options.TypeFilter = filter.Text;
AssemblyDefinition assembly = AssemblyFactory.GetAssembly(filename);
AstBuilder codeDomBuilder = new AstBuilder();

1
src/Options.cs

@ -4,6 +4,7 @@ namespace Decompiler @@ -4,6 +4,7 @@ namespace Decompiler
{
public static class Options
{
public static string TypeFilter = null;
public static int CollapseExpression = 1000;
public static int ReduceGraph = 1000;
public static bool NodeComments = false;

2
src/Program.cs

@ -21,7 +21,7 @@ namespace Decompiler @@ -21,7 +21,7 @@ namespace Decompiler
[STAThread]
private static void Main(string[] args)
{
string sourceFilename = @".\QuickSort.exe";
string sourceFilename = @".\Reversi.exe";
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Loading…
Cancel
Save