Browse Source

More GUI options

pull/1/head^2
David Srbecký 18 years ago
parent
commit
a95748dc66
  1. 26
      src/AstBuilder.cs
  2. 8
      src/ControlFlow/Node-Optimize.cs
  3. 21
      src/MainForm.Designer.cs
  4. 38
      src/MainForm.cs
  5. 5
      src/Options.cs

26
src/AstBuilder.cs

@ -22,17 +22,21 @@ namespace Decompiler @@ -22,17 +22,21 @@ namespace Decompiler
{
CSharpOutputVisitor csOutVisitor = new CSharpOutputVisitor();
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.Idioms(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
for (int i = 0; i < 2; i++) {
if (Options.ReduceAstJumps) {
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
}
if (Options.ReduceAstLoops) {
astCompileUnit.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
}
if (Options.ReduceAstOther) {
astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.Idioms(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
}
}
astCompileUnit.AcceptVisitor(csOutVisitor, null);

8
src/ControlFlow/Node-Optimize.cs

@ -9,8 +9,12 @@ namespace Decompiler.ControlFlow @@ -9,8 +9,12 @@ namespace Decompiler.ControlFlow
{
public void Optimize()
{
OptimizeLoops();
OptimizeIf();
if (Options.ReduceLoops) {
OptimizeLoops();
}
if (Options.ReduceConditonals) {
OptimizeIf();
}
}
public void OptimizeLoops()

21
src/MainForm.Designer.cs generated

@ -38,7 +38,6 @@ namespace Decompiler @@ -38,7 +38,6 @@ namespace Decompiler
this.reduceBtn = new System.Windows.Forms.Button();
this.decompileBtn = new System.Windows.Forms.Button();
this.sourceCodeBox = new System.Windows.Forms.RichTextBox();
this.nodeComments = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.collapseCount)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.reduceCount)).BeginInit();
this.SuspendLayout();
@ -59,7 +58,7 @@ namespace Decompiler @@ -59,7 +58,7 @@ namespace Decompiler
0,
0,
0});
this.collapseCount.ValueChanged += new System.EventHandler(this.CollapseCountValueChanged);
this.collapseCount.ValueChanged += new System.EventHandler(this.Decompile);
//
// reduceCount
//
@ -77,7 +76,7 @@ namespace Decompiler @@ -77,7 +76,7 @@ namespace Decompiler
0,
0,
0});
this.reduceCount.ValueChanged += new System.EventHandler(this.ReduceCountValueChanged);
this.reduceCount.ValueChanged += new System.EventHandler(this.Decompile);
//
// collapseBtn
//
@ -109,7 +108,7 @@ namespace Decompiler @@ -109,7 +108,7 @@ namespace Decompiler
this.decompileBtn.TabIndex = 5;
this.decompileBtn.Text = "Decompile";
this.decompileBtn.UseVisualStyleBackColor = true;
this.decompileBtn.Click += new System.EventHandler(this.DecompileBtnClick);
this.decompileBtn.Click += new System.EventHandler(this.Decompile);
//
// sourceCodeBox
//
@ -124,23 +123,11 @@ namespace Decompiler @@ -124,23 +123,11 @@ namespace Decompiler
this.sourceCodeBox.Text = "";
this.sourceCodeBox.WordWrap = false;
//
// nodeComments
//
this.nodeComments.AutoSize = true;
this.nodeComments.Location = new System.Drawing.Point(12, 44);
this.nodeComments.Name = "nodeComments";
this.nodeComments.Size = new System.Drawing.Size(147, 24);
this.nodeComments.TabIndex = 7;
this.nodeComments.Text = "Node comments";
this.nodeComments.UseVisualStyleBackColor = true;
this.nodeComments.CheckedChanged += new System.EventHandler(this.NodeCommentsCheckedChanged);
//
// 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.Controls.Add(this.nodeComments);
this.Controls.Add(this.sourceCodeBox);
this.Controls.Add(this.decompileBtn);
this.Controls.Add(this.reduceBtn);
@ -152,9 +139,7 @@ namespace Decompiler @@ -152,9 +139,7 @@ namespace Decompiler
((System.ComponentModel.ISupportInitialize)(this.collapseCount)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.reduceCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.CheckBox nodeComments;
private System.Windows.Forms.RichTextBox sourceCodeBox;
private System.Windows.Forms.Button decompileBtn;
private System.Windows.Forms.Button reduceBtn;

38
src/MainForm.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Mono.Cecil;
@ -18,6 +19,25 @@ namespace Decompiler @@ -18,6 +19,25 @@ namespace Decompiler
{
this.filename = filename;
InitializeComponent();
int x = 16;
int y = 46;
foreach(FieldInfo _field in typeof(Options).GetFields()) {
FieldInfo field = _field;
if (field.FieldType == typeof(bool)) {
CheckBox checkBox = new CheckBox();
checkBox.Left = x;
checkBox.Top = y;
checkBox.AutoSize = true;
checkBox.Text = field.Name;
checkBox.Checked = (bool)field.GetValue(null);
checkBox.CheckedChanged += delegate {
field.SetValue(null, checkBox.Checked);
Decompile();
};
this.Controls.Add(checkBox);
x += checkBox.Width + 10;
}
}
}
public string SourceCode {
@ -34,7 +54,6 @@ namespace Decompiler @@ -34,7 +54,6 @@ namespace Decompiler
ControlFlow.Node.NextNodeID = 0;
Options.CollapseExpression = (int)collapseCount.Value;
Options.ReduceGraph = (int)reduceCount.Value;
Options.NodeComments = nodeComments.Checked;
AssemblyDefinition assembly = AssemblyFactory.GetAssembly(filename);
AstBuilder codeDomBuilder = new AstBuilder();
@ -54,22 +73,7 @@ namespace Decompiler @@ -54,22 +73,7 @@ namespace Decompiler
Decompile();
}
void DecompileBtnClick(object sender, EventArgs e)
{
Decompile();
}
void CollapseCountValueChanged(object sender, EventArgs e)
{
Decompile();
}
void ReduceCountValueChanged(object sender, EventArgs e)
{
Decompile();
}
void NodeCommentsCheckedChanged(object sender, EventArgs e)
void Decompile(object sender, EventArgs e)
{
Decompile();
}

5
src/Options.cs

@ -7,5 +7,10 @@ namespace Decompiler @@ -7,5 +7,10 @@ namespace Decompiler
public static int CollapseExpression = int.MaxValue;
public static int ReduceGraph = int.MaxValue;
public static bool NodeComments = false;
public static bool ReduceLoops = true;
public static bool ReduceConditonals = true;
public static bool ReduceAstJumps = true;
public static bool ReduceAstLoops = true;
public static bool ReduceAstOther = true;
}
}

Loading…
Cancel
Save