Exemplo n.º 1
0
        public void BwIndexInMemoryAddress()
        {
            // samples of switch statement emitted
            // by the Microsoft VC compiler

            var ebp = m.Frame.EnsureRegister(Registers.ebp);
            var eax = m.Frame.EnsureRegister(Registers.eax);
            var edx = m.Frame.EnsureRegister(Registers.edx);

            // cmp [ebp-66],1D

            m.Assign(SCZO, m.Cond(m.ISub(m.Mem32(m.ISub(ebp, 0xC4)), 0x1D)));
            var block0 = m.CurrentBlock;

            m.BranchIf(new TestCondition(ConditionCode.UGT, SCZO), "default");

            // mov edx,[ebp-66]
            // movzx eax,byte ptr [edx + 0x10000]
            // jmp [eax + 0x12000]

            m.Assign(edx, m.Mem32(m.ISub(ebp, 0xC4)));
            m.Assign(eax, m.Convert(m.Mem8(m.IAdd(edx, 0x10000)), PrimitiveType.Byte, PrimitiveType.Word32));
            var xfer = new RtlGoto(m.Mem32(m.IAdd(eax, 0x12000)), InstrClass.Transfer);

            var block1 = m.CurrentBlock;
            var bw     = new Backwalker <Block, Instruction>(host, xfer, expSimp);
            var ret    = bw.BackwalkInstructions(Registers.eax, block1);

            Assert.AreEqual("None", bw.Index.ToString());
            Assert.AreEqual("Mem0[ebp - 0xC4<32>:word32]", bw.IndexExpression.ToString());
            Assert.AreEqual(4, bw.JumpSize);
            Assert.IsTrue(ret);

            ret = bw.BackwalkInstructions(null, block0);
        }
Exemplo n.º 2
0
        public void BwInc()
        {
            var        state = arch.CreateProcessorState();
            var        di    = new Identifier("di", Registers.di.DataType, Registers.di);
            Backwalker bw    = new Backwalker(host, new RtlGoto(new MemoryAccess(di, di.DataType), RtlClass.Transfer),
                                              new ExpressionSimplifier(state, new FakeDecompilerEventListener()));
            var instrs = new StatementList(new Block(null, "foo"));

            instrs.Add(0, new Assignment(di, new BinaryExpression(Operator.IAdd, di.DataType, di, Constant.Word16(1))));
            bw.BackwalkInstructions(Registers.di, instrs);
            Assert.AreSame(Registers.di, bw.Index);
            Assert.AreEqual("+ 1", bw.Operations[0].ToString());
        }
Exemplo n.º 3
0
        public void BwIndexInMemoryAddress()
        {
            // samples of switch statement emitted
            // by the Microsoft VC compiler

            var ebp  = m.Frame.EnsureRegister(Registers.ebp);
            var eax  = m.Frame.EnsureRegister(Registers.eax);
            var edx  = m.Frame.EnsureRegister(Registers.edx);
            var dl   = m.Frame.EnsureRegister(Registers.dl);
            var SCZO = m.Frame.EnsureFlagGroup((uint)(FlagM.SF | FlagM.CF | FlagM.ZF | FlagM.OF), "SCZO", PrimitiveType.Byte);

            // cmp [ebp-66],1D

            m.Assign(SCZO, m.Cond(m.ISub(m.LoadDw(m.ISub(ebp, 0xC4)), 0x1D)));
            var block0 = m.CurrentBlock;

            m.BranchIf(new TestCondition(ConditionCode.UGT, SCZO), "default");


            // mov edx,[ebp-66]
            // movzx eax,byte ptr [edx + 0x10000]
            // jmp [eax + 0x12000]

            m.Assign(edx, m.LoadDw(m.ISub(ebp, 0xC4)));
            m.Assign(eax, m.Cast(PrimitiveType.Word32, m.LoadB(m.IAdd(edx, 0x10000))));
            var block1 = m.CurrentBlock;

            var bw  = new Backwalker(host, new RtlGoto(m.LoadDw(m.IAdd(eax, 0x12000)), RtlClass.Transfer), expSimp);
            var ret = bw.BackwalkInstructions(Registers.eax, block1);

            Assert.AreEqual("None", bw.Index.ToString());
            Assert.AreEqual("Mem0[ebp - 0x000000C4:word32]", bw.IndexExpression.ToString());
            Assert.AreEqual(4, bw.JumpSize);
            Assert.IsTrue(ret);

            ret = bw.BackwalkInstructions(null, block0);
        }