Beispiel #1
0
        public void VpDbpDbp()
        {
            var m  = new ProcedureBuilder();
            var d1 = m.Reg32("d32", 0);
            var a1 = m.Reg32("a32", 1);

            m.Assign(d1, m.Dpb(d1, m.Mem16(a1), 0));
            m.Assign(d1, m.Dpb(d1, m.Mem16(m.IAdd(a1, 4)), 0));

            Procedure proc           = m.Procedure;
            var       gr             = proc.CreateBlockDominatorGraph();
            var       importResolver = MockRepository.GenerateStub <IImportResolver>();

            importResolver.Replay();
            var sst = new SsaTransform(new ProgramDataFlow(), proc, importResolver, gr, new HashSet <RegisterStorage>());
            var ssa = sst.SsaState;

            var vp = new ValuePropagator(segmentMap, ssa, listener);

            vp.Transform();

            using (FileUnitTester fut = new FileUnitTester("Analysis/VpDpbDpb.txt"))
            {
                proc.Write(false, fut.TextWriter);
                fut.TextWriter.WriteLine();
                fut.AssertFilesEqual();
            }
        }
Beispiel #2
0
        public void VpDbpDbp()
        {
            var m  = new ProcedureBuilder();
            var d1 = m.Reg32("d32", 0);
            var a1 = m.Reg32("a32", 1);

            m.Assign(d1, m.Dpb(d1, m.Mem16(a1), 0));
            m.Assign(d1, m.Dpb(d1, m.Mem16(m.IAdd(a1, 4)), 0));

            Procedure proc          = m.Procedure;
            var       gr            = proc.CreateBlockDominatorGraph();
            var       dynamicLinker = new Mock <IDynamicLinker>();
            var       sst           = new SsaTransform(
                program,
                proc,
                new HashSet <Procedure>(),
                dynamicLinker.Object,
                new ProgramDataFlow());

            sst.Transform();
            var ssa = sst.SsaState;

            var vp = new ValuePropagator(segmentMap, ssa, program.CallGraph, dynamicLinker.Object, listener);

            vp.Transform();

            using (FileUnitTester fut = new FileUnitTester("Analysis/VpDpbDpb.txt"))
            {
                proc.Write(false, fut.TextWriter);
                fut.TextWriter.WriteLine();
                fut.AssertFilesEqual();
            }
        }
        public void TrashRepeatedDpbs()
        {
            p.Add("main", m =>
            {
                var eax = m.Frame.EnsureRegister(Registers.eax);
                var v1  = m.Frame.CreateTemporary("v1", PrimitiveType.Byte);
                var v2  = m.Frame.CreateTemporary("v2", PrimitiveType.Byte);
                var v3  = m.Frame.CreateTemporary("v3", PrimitiveType.Byte);
                m.Assign(v1, m.Or(m.Cast(v1.DataType, eax), 0));
                m.Assign(eax, m.Dpb(eax, v1, 0));
                m.Assign(v2, m.Or(m.Cast(v1.DataType, eax), 0));
                m.Assign(eax, m.Dpb(eax, v2, 0));
                m.Assign(v3, m.Or(m.Cast(v1.DataType, eax), 0));
                m.Assign(eax, m.Dpb(eax, v3, 0));
                m.Return();
            });

            var sExp =
                @"main
    main_entry esp:fp
    l1 esp:fp
    main_exit eax:eax esp:fp";

            RunTest(p, sExp);
        }
        public void VpDbpDbp()
        {
            var m   = new ProcedureBuilder();
            var d1  = m.Reg32("d32");
            var a1  = m.Reg32("a32");
            var tmp = m.Frame.CreateTemporary(PrimitiveType.Word16);

            m.Assign(d1, m.Dpb(d1, m.LoadW(a1), 0, 16));
            m.Assign(d1, m.Dpb(d1, m.LoadW(m.IAdd(a1, 4)), 0, 16));

            Procedure    proc = m.Procedure;
            var          gr   = proc.CreateBlockDominatorGraph();
            SsaTransform sst  = new SsaTransform(new ProgramDataFlow(), proc, gr);
            SsaState     ssa  = sst.SsaState;

            ssa.DebugDump(true);

            var vp = new ValuePropagator(arch, ssa.Identifiers, proc);

            vp.Transform();

            using (FileUnitTester fut = new FileUnitTester("Analysis/VpDpbDpb.txt"))
            {
                proc.Write(false, fut.TextWriter);
                fut.TextWriter.WriteLine();
                fut.AssertFilesEqual();
            }
        }
Beispiel #5
0
        public void TrcoDbp()
        {
            ProcedureBuilder m = new ProcedureBuilder();
            Identifier       a = m.Local32("a");
            Identifier       b = m.LocalByte("b");
            var s = m.Assign(a, m.Dpb(a, b, 0));

            coll = CreateCollector();
            s.Accept(eqb);
            s.Accept(coll);
            StringWriter sb = new StringWriter();

            handler.Traits.Write(sb);
            string exp =
                "T_1 (in a : word32)" + nl +
                "\ttrait_primitive(word32)" + nl +
                "\ttrait_primitive(word32)" + nl +
                "\ttrait_primitive(word32)" + nl +
                "\ttrait_equal(T_3)" + nl +
                "T_2 (in b : byte)" + nl +
                "\ttrait_primitive(byte)" + nl +
                "T_3 (in DPB(a, b, 0) : word32)" + nl +
                "\ttrait_primitive(word32)" + nl;

            Assert.AreEqual(exp, sb.ToString());
        }
Beispiel #6
0
        public void Rl_DepositBytes()
        {
            Identifier edx = f.EnsureRegister(Registers.edx);
            Identifier al  = f.EnsureRegister(Registers.al);

            m.Assign(edx, m.Dpb(edx, al, 0)).Accept(rl);
            Assert.AreEqual(" al", Dump(rl.IdentifierLiveness));
        }
Beispiel #7
0
        public void VpLoadDpbSmallerCast()
        {
            var m   = new ProcedureBuilder();
            var a2  = m.Reg32("a2", 10);
            var d3  = m.Reg32("d3", 3);
            var tmp = m.Temp(PrimitiveType.Word16, "tmp");

            m.Assign(tmp, m.Mem16(a2));
            m.Assign(d3, m.Dpb(d3, tmp, 0));
            m.MStore(m.IAdd(a2, 4), m.Cast(PrimitiveType.Byte, d3));

            SsaState ssa = RunTest(m);

            var sExp =
                #region Expected
                @"a2:a2
    def:  def a2
    uses: tmp_3 = Mem0[a2:word16]
          Mem6[a2 + 4<32>:byte] = (byte) tmp_3
Mem0:Mem
    def:  def Mem0
    uses: tmp_3 = Mem0[a2:word16]
tmp_3: orig: tmp
    def:  tmp_3 = Mem0[a2:word16]
    uses: d3_5 = SEQ(SLICE(d3, word16, 16), tmp_3)
          Mem6[a2 + 4<32>:byte] = (byte) tmp_3
d3:d3
    def:  def d3
    uses: d3_5 = SEQ(SLICE(d3, word16, 16), tmp_3)
d3_5: orig: d3
    def:  d3_5 = SEQ(SLICE(d3, word16, 16), tmp_3)
    uses: Mem6[a2 + 4<32>:byte] = (byte) tmp_3
Mem6: orig: Mem0
    def:  Mem6[a2 + 4<32>:byte] = (byte) tmp_3
// ProcedureBuilder
// Return size: 0
define ProcedureBuilder
ProcedureBuilder_entry:
	def a2
	def Mem0
	def d3
	// succ:  l1
l1:
	tmp_3 = Mem0[a2:word16]
	d3_5 = SEQ(SLICE(d3, word16, 16), tmp_3)
	Mem6[a2 + 4<32>:byte] = (byte) tmp_3
ProcedureBuilder_exit:
";

            #endregion

            AssertStringsEqual(sExp, ssa);
        }
Beispiel #8
0
        public void VpLoadDpbSmallerCast()
        {
            var m   = new ProcedureBuilder();
            var a2  = m.Reg32("a2", 10);
            var d3  = m.Reg32("d3", 3);
            var tmp = m.Temp(PrimitiveType.Word16, "tmp");

            m.Assign(tmp, m.LoadW(a2));
            m.Assign(d3, m.Dpb(d3, tmp, 0));
            m.Store(m.IAdd(a2, 4), m.Cast(PrimitiveType.Byte, d3));

            SsaState ssa = RunTest(m);

            var sExp =
                #region Expected
                @"a2:a2
    def:  def a2
    uses: tmp_2 = Mem0[a2:word16]
          Mem5[a2 + 0x00000004:byte] = (byte) tmp_2
Mem0:Global memory
    def:  def Mem0
    uses: tmp_2 = Mem0[a2:word16]
tmp_2: orig: tmp
    def:  tmp_2 = Mem0[a2:word16]
    uses: d3_4 = DPB(d3, tmp_2, 0)
          Mem5[a2 + 0x00000004:byte] = (byte) tmp_2
d3:d3
    def:  def d3
    uses: d3_4 = DPB(d3, tmp_2, 0)
d3_4: orig: d3
    def:  d3_4 = DPB(d3, tmp_2, 0)
Mem5: orig: Mem0
    def:  Mem5[a2 + 0x00000004:byte] = (byte) tmp_2
// ProcedureBuilder
// Return size: 0
void ProcedureBuilder()
ProcedureBuilder_entry:
	def a2
	def Mem0
	def d3
	// succ:  l1
l1:
	tmp_2 = Mem0[a2:word16]
	d3_4 = DPB(d3, tmp_2, 0)
	Mem5[a2 + 0x00000004:byte] = (byte) tmp_2
ProcedureBuilder_exit:
";

            #endregion

            AssertStringsEqual(sExp, ssa);
        }
Beispiel #9
0
        public void BwReg_00121()
        {
            var d0    = m.Reg32("d0", 0);
            var d3    = m.Reg32("d3", 3);
            var a5    = m.Reg32("a5", 5);
            var v38   = m.Temp(PrimitiveType.Word16, "v38");
            var v39   = m.Temp(PrimitiveType.Byte, "v39");
            var v40   = m.Temp(PrimitiveType.Word16, "v40");
            var VZN   = m.Flags("VZN");
            var ZN    = m.Flags("ZN");
            var C     = m.Flags("C");
            var V     = m.Flags("V");
            var CVZN  = m.Flags("CVZN");
            var CVZNX = m.Flags("CVZNX");

            m.Assign(d0, d3);
            m.Assign(CVZN, m.Cond(d0));
            m.Assign(v38, m.And(m.Cast(PrimitiveType.Word16, d0), 0xF0));
            m.Assign(d0, m.Dpb(d0, v38, 0));
            m.Assign(ZN, m.Cond(v38));
            m.Assign(C, false);
            m.Assign(V, false);
            m.Assign(v39, m.Shl(m.Cast(PrimitiveType.Byte, d0), 2));
            m.Assign(d0, m.Dpb(d0, v39, 0));
            m.Assign(CVZNX, m.Cond(v39));
            m.Assign(v40, m.ISub(m.Cast(PrimitiveType.Word16, d0), 44));
            m.Assign(CVZN, m.Cond(v40));
            m.BranchIf(m.Test(ConditionCode.GT, VZN), "lDefault");
            m.Assign(a5, m.Mem32(m.IAdd(Address.Ptr32(0x0000C046), d0)));
            var xfer = new RtlCall(a5, 4, RtlClass.Transfer);

            var bw = new Backwalker <Block, Instruction>(host, xfer, expSimp);

            Assert.IsTrue(bw.CanBackwalk());
            Assert.AreEqual("a5", bw.Index.Name);
            bw.BackWalk(m.Block);
            Assert.AreEqual("v40", bw.IndexExpression.ToString());
        }