示例#1
0
        public void BlockCloner_Store()
        {
            var proc = BuildTest("fn01010", m =>
            {
                var r1 = m.Register("r1");
                m.MStore(r1, r1);
                m.Return();
            });

            var block    = proc.EntryBlock.Succ[0];
            var cloner   = new BlockCloner(block, procCalling, callgraph);
            var blockNew = cloner.Execute();
        }
示例#2
0
        public void BlockCloner_CloneBin()
        {
            var proc = BuildTest("fn1000", m =>
            {
                var r1 = m.Register("r1");
                var r2 = m.Register("r2");
                m.Assign(r1, m.IAdd(r1, r2));
                m.Return();
            });
            var block = proc.ControlGraph.Blocks[2];

            var blockCloner = new BlockCloner(block, procCalling, callgraph);
            var blockNew = blockCloner.Execute();

            var assNew = (Assignment) blockNew.Statements[0].Instruction;
            Assert.AreEqual("r1 = r1 + r2", assNew.ToString());
        }
示例#3
0
        public void BlockCloner_CloneBin()
        {
            var proc = BuildTest("fn1000", m =>
            {
                var r1 = m.Register("r1");
                var r2 = m.Register("r2");
                m.Assign(r1, m.IAdd(r1, r2));
                m.Return();
            });
            var block = proc.ControlGraph.Blocks[2];

            var blockCloner = new BlockCloner(block, procCalling, callgraph);
            var blockNew    = blockCloner.Execute();

            var assNew = (Assignment)blockNew.Statements[0].Instruction;

            Assert.AreEqual("r1 = r1 + r2", assNew.ToString());
        }
示例#4
0
        public void BlockCloner_CloneBlock()
        {
            var m = new ProcedureBuilder(arch, "fn1000");
            var r1 = m.Register("r1");
            var r2 = m.Register("r2");
            var ass = m.Assign(r1, r2);
            m.Return();
            var block = m.Procedure.ControlGraph.Blocks[2];

            m = new ProcedureBuilder(arch, "procCalling");

            var blockCloner = new BlockCloner(block, m.Procedure, callgraph);
            var blockNew = blockCloner.Execute();

            var assNew = (Assignment) blockNew.Statements[0].Instruction;
            Assert.AreNotSame(ass.Dst, assNew.Dst);
            Assert.AreNotSame(ass.Src, assNew.Src);
        }
示例#5
0
        public void BlockCloner_CloneTwoBlocks()
        {
            var proc = BuildTest("fn01010", m =>
            {
                var r1 = m.Register("r1");
                m.Assign(r1, m.Mem32(r1));
                m.Goto("next");
                m.Label("next");
                m.Assign(r1, m.Mem32(m.Word32(0x123123)));
                m.Return();
            });

            var block    = proc.EntryBlock.Succ[0];
            var cloner   = new BlockCloner(block, procCalling, callgraph);
            var blockNew = cloner.Execute();

            Assert.AreEqual(4, procCalling.ControlGraph.Blocks.Count, "2 for entry and exit, 2 for cloned blocks");
            Assert.AreSame(procCalling.ExitBlock, blockNew.Succ[0].Succ[0]);
        }
示例#6
0
        public void BlockCloner_CloneMem()
        {
            var proc = BuildTest("fn1000", m =>
            {
                var r1 = m.Register("r1");
                var r2 = m.Register("r2");
                m.Assign(r1, m.Mem32(r2));
                m.Return();
            });
            var block = proc.ControlGraph.Blocks[2];

            var blockCloner = new BlockCloner(block, procCalling, callgraph);
            var blockNew    = blockCloner.Execute();

            var assNew = (Assignment)blockNew.Statements[0].Instruction;

            Assert.AreEqual("r1 = Mem0[r2:word32]", assNew.ToString());
            Assert.AreNotSame(proc.Frame.Memory, ((MemoryAccess)assNew.Src).MemoryId);
        }
示例#7
0
        public void BlockCloner_CloneBlock()
        {
            var m   = new ProcedureBuilder(arch, "fn1000");
            var r1  = m.Register("r1");
            var r2  = m.Register("r2");
            var ass = m.Assign(r1, r2);

            m.Return();
            var block = m.Procedure.ControlGraph.Blocks[2];

            m = new ProcedureBuilder(arch, "procCalling");

            var blockCloner = new BlockCloner(block, m.Procedure, callgraph);
            var blockNew    = blockCloner.Execute();

            var assNew = (Assignment)blockNew.Statements[0].Instruction;

            Assert.AreNotSame(ass.Dst, assNew.Dst);
            Assert.AreNotSame(ass.Src, assNew.Src);
        }
示例#8
0
        public void BlockCloner_CloneBlock_Temporaries()
        {
            var m   = new ProcedureBuilder(arch, "fn1000");
            var tmp = m.Frame.CreateTemporary(PrimitiveType.Word32);
            var r2  = m.Register("r2");
            var ass = m.Assign(tmp, r2);
            var sto = (Store)m.MStore(m.Word32(0x00123400), tmp).Instruction;

            m.Return();
            var block = m.Procedure.ControlGraph.Blocks[2];

            m = new ProcedureBuilder(arch, "procCalling");

            var blockCloner = new BlockCloner(block, m.Procedure, callgraph);
            var blockNew    = blockCloner.Execute();

            var assNew = (Assignment)blockNew.Statements[0].Instruction;
            var stoNew = (Store)blockNew.Statements[1].Instruction;

            Assert.AreNotSame(ass.Dst, assNew.Dst);
            Assert.AreNotSame(sto.Src, stoNew.Src);
            Assert.AreSame(assNew.Dst, stoNew.Src);
        }
示例#9
0
        public void BlockCloner_CloneMem()
        {
            var proc = BuildTest("fn1000", m =>
            {
                var r1 = m.Register("r1");
                var r2 = m.Register("r2");
                m.Assign(r1, m.LoadDw(r2));
                m.Return();
            });
            var block = proc.ControlGraph.Blocks[2];

            var blockCloner = new BlockCloner(block, procCalling, callgraph);
            var blockNew = blockCloner.Execute();

            var assNew = (Assignment) blockNew.Statements[0].Instruction;
            Assert.AreEqual("r1 = Mem0[r2:word32]", assNew.ToString());
            Assert.AreNotSame(proc.Frame.Memory, ((MemoryAccess) assNew.Src).MemoryId);
        }
示例#10
0
        public void BlockCloner_Store()
        {
            var proc = BuildTest("fn01010", m =>
            {
                var r1 = m.Register("r1");
                m.Store(r1, r1);
                m.Return();
            });

            var block = proc.EntryBlock.Succ[0];
            var cloner = new BlockCloner(block, procCalling, callgraph);
            var blockNew = cloner.Execute();
        }
示例#11
0
        public void BlockCloner_CloneTwoBlocks()
        {
            var proc = BuildTest("fn01010", m =>
            {
                var r1 = m.Register("r1");
                m.Assign(r1, m.LoadDw(r1));
                m.Jump("next");
                m.Label("next");
                m.Assign(r1, m.LoadDw(m.Word32(0x123123)));
                m.Return();
            });

            var block = proc.EntryBlock.Succ[0];
            var cloner = new BlockCloner(block, procCalling, callgraph);
            var blockNew = cloner.Execute();

            Assert.AreEqual(4, procCalling.ControlGraph.Blocks.Count, "2 for entry and exit, 2 for cloned blocks");
            Assert.AreSame(procCalling.ExitBlock, blockNew.Succ[0].Succ[0]);
        }