Esempio n. 1
0
 private void AddConditional(RtlInstruction rtlInstr)
 {
     if (instr.Cond != Condition.al)
     {
         rtlInstr = new RtlIf(TestCond(instr.Cond), rtlInstr);
     }
     ric.Instructions.Add(rtlInstr);
 }
Esempio n. 2
0
 private void AddConditional(RtlInstruction rtlInstr)
 {
     if (instr.ArchitectureDetail.CodeCondition != ArmCodeCondition.AL)
     {
         rtlInstr = new RtlIf(TestCond(instr.ArchitectureDetail.CodeCondition), rtlInstr);
     }
     ric.Instructions.Add(rtlInstr);
 }
Esempio n. 3
0
 private void Predicate(ArmCodeCondition cond, RtlInstruction instr)
 {
     if (cond == ArmCodeCondition.AL)
     {
         emitter.Emit(instr);
     }
     else
     {
         emitter.If(TestCond(cond), instr);
     }
 }
Esempio n. 4
0
 private void AddConditional(RtlInstruction rtlInstr)
 {
     if (instr.ArchitectureDetail.CodeCondition != ArmCodeCondition.AL)
     {
         m.BranchInMiddleOfInstruction(
             TestCond(instr.ArchitectureDetail.CodeCondition).Invert(),
             Address.Ptr32((uint)(instr.Address + instr.Bytes.Length)),
             RtlClass.ConditionalTransfer);
     }
     m.Emit(rtlInstr);
 }
Esempio n. 5
0
 public override SystemService FindService(RtlInstruction rtl, ProcessorState state)
 {
     if (!a6Pattern.Match(rtl))
         return null;
     var reg = ((Identifier) a6Pattern.CapturedExpressions("addrReg")).Storage as RegisterStorage;
     var offset = ((Constant) a6Pattern.CapturedExpressions("offset")).ToInt32();
     if (reg != Registers.a6)
         return null;
     if (funcs == null)
         funcs = LoadFuncs();
     SystemService svc;
     return funcs.TryGetValue(offset, out svc) ? svc : null;
 }
Esempio n. 6
0
 private bool ProcessRtlCluster(RtlInstructionCluster ric)
 {
     state.SetInstructionPointer(ric.Address);
     foreach (var rtlInstr in ric.Instructions)
     {
         ri = rtlInstr;
         if (!ri.Accept(this))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 7
0
 private void Predicate(ArmCodeCondition cond, RtlInstruction instr)
 {
     if (cond == ArmCodeCondition.AL)
     {
         m.Emit(instr);
     }
     else
     {
         m.BranchInMiddleOfInstruction(
             TestCond(cond).Invert(),
             Address.Ptr32((uint)(this.instr.Address + this.instr.Bytes.Length)),
             RtlClass.ConditionalTransfer);
         m.Emit(instr);
     }
 }
Esempio n. 8
0
 private bool ProcessRtlCluster(RtlInstructionCluster ric)
 {
     if (ric.Address.ToLinear() == 0x30C)        //$DEBUG
     {
         ric.Address.ToString();
     }
     state.SetInstructionPointer(ric.Address);
     SetAssumedRegisterValues(ric.Address);
     foreach (var rtlInstr in ric.Instructions)
     {
         ri = rtlInstr;
         if (!ri.Accept(this))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 9
0
        public override SystemService FindService(RtlInstruction rtl, ProcessorState state, SegmentMap segmentMap)
        {
            EnsureTypeLibraries(PlatformIdentifier);
            if (!a6Pattern.Match(rtl))
            {
                return(null);
            }
            var reg    = ((Identifier)a6Pattern.CapturedExpressions("addrReg")).Storage as RegisterStorage;
            var offset = ((Constant)a6Pattern.CapturedExpressions("offset")).ToInt32();

            if (reg != Registers.a6)
            {
                return(null);
            }
            if (funcs == null)
            {
                funcs = LoadLibraryDef("exec", 33, Metadata);
            }
            return(funcs.TryGetValue(offset, out SystemService svc) ? svc : null);
        }
Esempio n. 10
0
        protected void AssertCode(params string[] expected)
        {
            int i        = 0;
            var frame    = Architecture.CreateFrame();
            var host     = CreateRewriterHost();
            var rewriter = GetInstructionStream(frame, host).GetEnumerator();

            while (i < expected.Length && rewriter.MoveNext())
            {
                Assert.AreEqual(expected[i], string.Format("{0}|{1}|{2}", i, RtlInstruction.FormatClass(rewriter.Current.Class), rewriter.Current));
                ++i;
                var ee = rewriter.Current.Instructions.OfType <RtlInstruction>().GetEnumerator();
                while (i < expected.Length && ee.MoveNext())
                {
                    Assert.AreEqual(expected[i], string.Format("{0}|{1}|{2}", i, RtlInstruction.FormatClass(ee.Current.Class), ee.Current));
                    ++i;
                }
            }
            Assert.AreEqual(expected.Length, i, "Expected " + expected.Length + " instructions.");
            Assert.IsFalse(rewriter.MoveNext(), "More instructions were emitted than were expected.");
        }
Esempio n. 11
0
        protected void AssertCode(string mesg, params string[] expected)
        {
            int i        = 0;
            var frame    = Architecture.CreateFrame();
            var host     = CreateRewriterHost();
            var rewriter = GetRtlStream(bmem, frame, host).GetEnumerator();

            while (i < expected.Length && rewriter.MoveNext())
            {
                Assert.AreEqual(expected[i], $"{i}|{RtlInstruction.FormatClass(rewriter.Current.Class)}|{rewriter.Current}", mesg);
                ++i;
                var ee = rewriter.Current.Instructions.OfType <RtlInstruction>().GetEnumerator();
                while (i < expected.Length && ee.MoveNext())
                {
                    Assert.AreEqual(expected[i], $"{i}|{RtlInstruction.FormatClass(ee.Current.Class)}|{ee.Current}", mesg);
                    ++i;
                }
            }
            Assert.AreEqual(expected.Length, i, mesg + " Expected " + expected.Length + " instructions.");
            Assert.IsFalse(rewriter.MoveNext(), mesg + " More instructions were emitted than were expected. ");
        }
Esempio n. 12
0
        public override SystemService FindService(RtlInstruction rtl, ProcessorState state)
        {
            if (!a6Pattern.Match(rtl))
            {
                return(null);
            }
            var reg    = ((Identifier)a6Pattern.CapturedExpressions("addrReg")).Storage as RegisterStorage;
            var offset = ((Constant)a6Pattern.CapturedExpressions("offset")).ToInt32();

            if (reg != Registers.a6)
            {
                return(null);
            }
            if (funcs == null)
            {
                funcs = LoadFuncs();
            }
            SystemService svc;

            return(funcs.TryGetValue(offset, out svc) ? svc : null);
        }
Esempio n. 13
0
        public void ProcessInternal()
        {
            state.ErrorListener = (message) => { scanner.Warn(ric.Address, message); };
            blockCur            = scanner.FindContainingBlock(addrStart);
            if (BlockHasBeenScanned(blockCur))
            {
                return;
            }
            Debug.Print("Scanning jump target {0}", addrStart);
            frame         = blockCur.Procedure.Frame;
            this.stackReg = frame.EnsureRegister(arch.StackRegister);
            rtlStream     = scanner.GetTrace(addrStart, state, frame)
                            .GetEnumerator();

            while (rtlStream.MoveNext())
            {
                ric = rtlStream.Current;
                if (blockCur != scanner.FindContainingBlock(ric.Address))
                {
                    break;
                }
                state.SetInstructionPointer(ric.Address);
                foreach (var rtlInstr in ric.Instructions)
                {
                    ri = rtlInstr;
                    if (!ri.Accept(this))
                    {
                        return;
                    }
                }
                var blNext = FallenThroughNextBlock(ric.Address + ric.Length);
                if (blNext != null)
                {
                    EnsureEdge(blockCur.Procedure, blockCur, blNext);
                    return;
                }
            }
        }
Esempio n. 14
0
 public RtlInstruction Emit(RtlInstruction instr)
 {
     stms.Add(new RtlInstructionCluster(Address.Ptr32(linAddress), 4, instr));
     linAddress += 4;
     return(instr);
 }
Esempio n. 15
0
 private bool IsTransfer(RtlInstructionCluster i, RtlInstruction r)
 {
     return(r is RtlGoto || r is RtlCall);
 }
Esempio n. 16
0
 public void Emit(RtlInstruction instr)
 {
     instrs.Add(instr); 
 }
Esempio n. 17
0
 public RtlEmitter If(Expression test, RtlInstruction rtl)
 {
     instrs.Add(new RtlIf(test, rtl));
     return this;
 }
Esempio n. 18
0
 public override SystemService FindService(RtlInstruction rtl, ProcessorState state)
 {
     return(base.FindService(rtl, state));
 }
Esempio n. 19
0
 public SystemService FindService(RtlInstruction call, ProcessorState state)
 {
     throw new NotImplementedException();
 }
Esempio n. 20
0
 public virtual SystemService FindService(RtlInstruction rtl, ProcessorState state)
 {
     return(null);
 }
Esempio n. 21
0
 public RtlInstruction Emit(RtlInstruction instr)
 {
     stms.Add(new RtlInstructionCluster(Address.Ptr32(linAddress), 4, instr));
     linAddress += 4;
     return instr;
 }
Esempio n. 22
0
 public virtual SystemService FindService(RtlInstruction rtl, ProcessorState state)
 {
     return null;
 }
Esempio n. 23
0
 private bool IsTransfer(RtlInstructionCluster i, RtlInstruction r)
 {
     return r is RtlGoto || r is RtlCall;
 }
Esempio n. 24
0
 public override SystemService FindService(RtlInstruction rtl, ProcessorState state)
 {
     return base.FindService(rtl, state);
 }