コード例 #1
0
ファイル: Decompiler.cs プロジェクト: nemerle/reko
 /// <summary>
 /// Extracts structured program constructs out of snarled goto nests, if possible.
 /// Since procedures are now independent of each other, this analysis
 /// is done one procedure at a time.
 /// </summary>
 public void StructureProgram()
 {
     if (project is null)
     {
         return;
     }
     foreach (var program in project.Programs)
     {
         int i = 0;
         foreach (Procedure proc in program.Procedures.Values)
         {
             if (eventListener.IsCanceled())
             {
                 return;
             }
             try
             {
                 eventListener.ShowProgress("Rewriting procedures to high-level language.", i, program.Procedures.Values.Count);
                 ++i;
                 IStructureAnalysis sa = new StructureAnalysis(eventListener, program, proc);
                 sa.Structure();
             }
             catch (Exception e)
             {
                 eventListener.Error(
                     eventListener.CreateProcedureNavigator(program, proc),
                     e,
                     "An error occurred while rewriting procedure to high-level language.");
             }
         }
     }
     project.FireScriptEvent(ScriptEvent.OnProgramDecompiled);
     WriteDecompilerProducts();
     eventListener.ShowStatus("Rewriting complete.");
 }
コード例 #2
0
ファイル: Decompiler.cs プロジェクト: feelworld/reko
 /// <summary>
 /// Extracts structured program constructs out of snarled goto nests, if possible.
 /// Since procedures are now independent of each other, this analysis
 /// is done one procedure at a time.
 /// </summary>
 public void StructureProgram()
 {
     foreach (var program in project.Programs)
     {
         int i = 0;
         foreach (Procedure proc in program.Procedures.Values)
         {
             try
             {
                 eventListener.ShowProgress("Rewriting procedures to high-level language.", i, program.Procedures.Values.Count);
                 ++i;
                 Console.WriteLine("rewriting: {0}", proc);
                 IStructureAnalysis sa = new StructureAnalysis(proc);
                 sa.Structure();
             }
             catch (Exception e)
             {
                 eventListener.Error(
                     eventListener.CreateProcedureNavigator(program, proc),
                     e,
                     "An error occurred while rewriting procedure to high-level language.");
             }
         }
         WriteDecompilerProducts();
     }
     eventListener.ShowStatus("Rewriting complete.");
 }
コード例 #3
0
        private void CompileTest(ProcedureBuilder mock)
        {
            proc = mock.Procedure;
            var sa = new StructureAnalysis(new FakeDecompilerEventListener(), new Program(), proc);

            sa.Structure();
        }
コード例 #4
0
        private void CompileTest(ProcedureBuilder mock)
        {
            proc = mock.Procedure;
            var sa = new StructureAnalysis(proc);

            sa.Structure();
        }
コード例 #5
0
ファイル: SimpleStructureTests.cs プロジェクト: mmyydd/reko
        private void RunTest32(string expected, Program program)
        {
            var sw = new StringWriter();

            foreach (var proc in program.Procedures.Values)
            {
                var cfgc = new ControlFlowGraphCleaner(proc);
                cfgc.Transform();
                var sa = new StructureAnalysis(proc);
                sa.Structure();
                var fmt = new CodeFormatter(new TextFormatter(sw));
                fmt.Write(proc);
                sw.WriteLine("===");
            }
            Console.WriteLine(sw);
            Assert.AreEqual(expected, sw.ToString());
        }
コード例 #6
0
        private void RunTest(ProcedureBuilder mock, string outFilename)
        {
            Procedure proc = mock.Procedure;
            using (FileUnitTester fut = new FileUnitTester(outFilename))
            {
                ControlFlowGraphCleaner cfgc = new ControlFlowGraphCleaner(proc);
                cfgc.Transform();
                proc.Write(false, fut.TextWriter);
                fut.TextWriter.WriteLine();

                StructureAnalysis sa = new StructureAnalysis(proc);
                sa.Structure();
                CodeFormatter fmt = new CodeFormatter(new TextFormatter(fut.TextWriter));
                fmt.Write(proc);
                fut.TextWriter.WriteLine("===========================");

                fut.AssertFilesEqual();
            }
        }
コード例 #7
0
ファイル: SimpleStructureTests.cs プロジェクト: mmyydd/reko
        private void RunTest(ProcedureBuilder mock, string outFilename)
        {
            Procedure proc = mock.Procedure;

            using (FileUnitTester fut = new FileUnitTester(outFilename))
            {
                ControlFlowGraphCleaner cfgc = new ControlFlowGraphCleaner(proc);
                cfgc.Transform();
                proc.Write(false, fut.TextWriter);
                fut.TextWriter.WriteLine();

                StructureAnalysis sa = new StructureAnalysis(proc);
                sa.Structure();
                CodeFormatter fmt = new CodeFormatter(new TextFormatter(fut.TextWriter));
                fmt.Write(proc);
                fut.TextWriter.WriteLine("===========================");

                fut.AssertFilesEqual();
            }
        }
コード例 #8
0
ファイル: SimpleStructureTests.cs プロジェクト: mmyydd/reko
        private void RunTest16(string sourceFilename, string outFilename, Address addrBase)
        {
            using (FileUnitTester fut = new FileUnitTester(outFilename))
            {
                RewriteProgramMsdos(sourceFilename, addrBase);
                foreach (Procedure proc in program.Procedures.Values)
                {
                    var cfgc = new ControlFlowGraphCleaner(program.Procedures.Values[0]);
                    cfgc.Transform();
                    proc.Write(false, fut.TextWriter);
                    fut.TextWriter.WriteLine();

                    var sa = new StructureAnalysis(proc);
                    sa.Structure();
                    var fmt = new CodeFormatter(new TextFormatter(fut.TextWriter));
                    fmt.Write(proc);
                    fut.TextWriter.WriteLine("===========================");
                }
                fut.AssertFilesEqual();
            }
        }
コード例 #9
0
        private void RunTest16(string sourceFilename, string outFilename, Address addrBase)
        {
            using (FileUnitTester fut = new FileUnitTester(outFilename))
            {
                RewriteProgramMsdos(sourceFilename, addrBase);
                foreach (Procedure proc in program.Procedures.Values)
                {
                    var cfgc = new ControlFlowGraphCleaner(program.Procedures.Values[0]);
                    cfgc.Transform();
                    proc.Write(false, fut.TextWriter);
                    fut.TextWriter.WriteLine();

                    var sa = new StructureAnalysis(proc);
                    sa.Structure();
                    var fmt = new CodeFormatter(new TextFormatter(fut.TextWriter));
                    fmt.Write(proc);
                    fut.TextWriter.WriteLine("===========================");
                }
                fut.AssertFilesEqual();
            }
        }
コード例 #10
0
        private void RunTest(string expected, Program program)
        {
            var sw = new StringWriter();

            foreach (var proc in program.Procedures.Values)
            {
                var cfgc = new ControlFlowGraphCleaner(proc);
                cfgc.Transform();
                var sa = new StructureAnalysis(new FakeDecompilerEventListener(), program, proc);
                sa.Structure();
                var fmt = proc.CreateCodeFormatter(new TextFormatter(sw));
                fmt.Write(proc);
                sw.WriteLine("===");
            }
            try
            {
                Assert.AreEqual(expected, sw.ToString());
            } catch
            {
                Console.WriteLine(sw);
                throw;
            }
        }
コード例 #11
0
 private void RunTest32(string expected, Program program)
 {
     var sw = new StringWriter();
     foreach (var proc in program.Procedures.Values)
     {
         var cfgc = new ControlFlowGraphCleaner(proc);
         cfgc.Transform();
         var sa = new StructureAnalysis(proc);
         sa.Structure();
         var fmt = new CodeFormatter(new TextFormatter(sw));
         fmt.Write(proc);
         sw.WriteLine("===");
     }
     Console.WriteLine(sw);
     Assert.AreEqual(expected, sw.ToString());
 }