diff --git a/src/AstBuilder.cs b/src/AstBuilder.cs index 98b5a2c62..87ac38f39 100644 --- a/src/AstBuilder.cs +++ b/src/AstBuilder.cs @@ -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); diff --git a/src/ControlFlow/Node-Optimize.cs b/src/ControlFlow/Node-Optimize.cs index c251331a8..0c1ab7005 100644 --- a/src/ControlFlow/Node-Optimize.cs +++ b/src/ControlFlow/Node-Optimize.cs @@ -9,8 +9,12 @@ namespace Decompiler.ControlFlow { public void Optimize() { - OptimizeLoops(); - OptimizeIf(); + if (Options.ReduceLoops) { + OptimizeLoops(); + } + if (Options.ReduceConditonals) { + OptimizeIf(); + } } public void OptimizeLoops() diff --git a/src/MainForm.Designer.cs b/src/MainForm.Designer.cs index 60b9ebe3c..ef5ce14d2 100644 --- a/src/MainForm.Designer.cs +++ b/src/MainForm.Designer.cs @@ -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 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 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 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 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 ((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; diff --git a/src/MainForm.cs b/src/MainForm.cs index 8dceb351a..93f2472e8 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -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 { 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 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 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(); } diff --git a/src/Options.cs b/src/Options.cs index d294220c0..bceade7b1 100644 --- a/src/Options.cs +++ b/src/Options.cs @@ -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; } }