Exemplo n.º 1
0
        public void CfgcJmpToBranch()
        {
            var m   = new ProcedureBuilder();
            var c   = m.Temp(PrimitiveType.Bool, "c");
            var pfn = m.Temp(PrimitiveType.Ptr32, "pfn");

            m.Label("m1");
            m.BranchIf(c, "m3");
            m.Label("m2");
            m.Goto("m3");
            m.Label("m3");
            m.SideEffect(m.Fn(pfn));
            m.Return();

            var sExp =
                #region Expected
                @"// ProcedureBuilder
// Return size: 0
void ProcedureBuilder()
ProcedureBuilder_entry:
	pfn()
	return
	// succ:  ProcedureBuilder_exit
m1:
m3:
ProcedureBuilder_exit:
";

            #endregion
            var cfgc = new ControlFlowGraphCleaner(m.Procedure);
            cfgc.Transform();
            var sw = new StringWriter();
            m.Procedure.Write(false, sw);
            Assert.AreEqual(sExp, sw.ToString());
        }
Exemplo n.º 2
0
        private void RunTest(string sourceFile, string testFile)
        {
            using (FileUnitTester fut = new FileUnitTester(testFile))
            {
                this.RewriteProgramMsdos(sourceFile, Address.SegPtr(0xC00, 0));
                program.Procedures.Values[0].Write(false, fut.TextWriter);
                fut.TextWriter.WriteLine();
                var cfgc = new ControlFlowGraphCleaner(program.Procedures.Values[0]);
                cfgc.Transform();
                program.Procedures.Values[0].Write(false, fut.TextWriter);

                fut.AssertFilesEqual();
            }
        }
Exemplo n.º 3
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());
        }
        private void RunTest(string sExp, Procedure proc)
        {
            var cfgc = new ControlFlowGraphCleaner(proc);

            cfgc.Transform();
            var ps  = new StructureAnalysis(new FakeDecompilerEventListener(), new Program(), proc);
            var reg = ps.Execute();
            var sb  = new StringWriter();

            reg.Write(sb);
            sb.GetStringBuilder().Replace("\t", "    ");
            var s = sb.ToString();

            if (sExp != s)
            {
                Debug.WriteLine(s);
                Assert.AreEqual(sExp, s);
            }
        }
Exemplo n.º 5
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();
            }
        }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
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;
            }
        }