public void Dfa2_Simple() { var pb = new ProgramBuilder(new FakeArchitecture()); pb.Add("test", m=> { var r1 = m.Reg32("r1"); var r2 = m.Reg32("r2"); m.Assign(r1, m.LoadDw(m.Word32(0x010000))); m.Assign(r2, m.LoadDw(m.Word32(0x010004))); m.Store(m.Word32(0x010008), m.IAdd(r1, r2)); m.Return(); }); var dfa = new DataFlowAnalysis(pb.BuildProgram(), new FakeDecompilerEventListener()); dfa.UntangleProcedures2(); var sExp = @"// test // Return size: 0 void test() test_entry: // succ: l1 l1: Mem6[0x00010008:word32] = Mem0[0x00010000:word32] + Mem0[0x00010004:word32] return // succ: test_exit test_exit: "; AssertProgram(sExp, pb); }
public void Dfa2_FactorialReg() { pb = new ProgramBuilder(); pb.Add("fact", m => { var sp = m.Register(m.Architecture.StackRegister); var r1 = m.Register(1); var r2 = m.Register(2); var r3 = m.Register(3); var cc = m.Flags(0xF, "cc"); m.Assign(sp, m.Frame.FramePointer); m.Assign(r2, r1); m.Assign(r1, 1); m.Assign(cc, m.Cond(m.ISub(r2, r1))); m.BranchIf(m.Test(ConditionCode.LE, cc), "done"); m.Assign(sp, m.ISub(sp, 4)); m.Store(sp, r2); m.Assign(r1, m.ISub(r2, r1)); m.Call("fact", 0); m.Assign(r2, m.LoadDw(sp)); m.Assign(sp, m.IAdd(sp, 4)); m.Assign(r1, m.IMul(r1, r2)); m.Label("done"); m.Return(); }); var dfa = new DataFlowAnalysis(pb.BuildProgram(), new FakeDecompilerEventListener()); dfa.UntangleProcedures2(); var sExp = @"@@@"; AssertProgram(sExp, pb); }
public void Dfa2_CallProc() { pb = new ProgramBuilder(); pb.Add("test", m => { var sp = m.Register(m.Architecture.StackRegister); var fooProc = GivenFunction("foo", m.Architecture.GetRegister(1), 4, 8); m.Assign(sp, m.ISub(sp, 4)); m.Store(sp, 2); m.Assign(sp, m.ISub(sp, 4)); m.Store(sp, 1); m.Call(fooProc, 4); m.Assign(sp, m.IAdd(sp, 8)); m.Return(); }); var dfa = new DataFlowAnalysis(pb.BuildProgram(), new FakeDecompilerEventListener()); dfa.UntangleProcedures2(); var sExp = @"// test // Return size: 0 void test() test_entry: // succ: l1 l1: Mem9[0x00010008:word32] = Mem0[fp + 0x00000004:word32] + Mem0[fp + 0x00000008:word32] return // succ: test_exit test_exit: "; AssertProgram(sExp, pb); }