private void AddConditional(RtlInstruction rtlInstr) { if (instr.Cond != Condition.al) { rtlInstr = new RtlIf(TestCond(instr.Cond), rtlInstr); } ric.Instructions.Add(rtlInstr); }
private void AddConditional(RtlInstruction rtlInstr) { if (instr.ArchitectureDetail.CodeCondition != ArmCodeCondition.AL) { rtlInstr = new RtlIf(TestCond(instr.ArchitectureDetail.CodeCondition), rtlInstr); } ric.Instructions.Add(rtlInstr); }
private void Predicate(ArmCodeCondition cond, RtlInstruction instr) { if (cond == ArmCodeCondition.AL) { emitter.Emit(instr); } else { emitter.If(TestCond(cond), instr); } }
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); }
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; }
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); }
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); } }
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); }
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); }
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."); }
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. "); }
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); }
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; } } }
public RtlInstruction Emit(RtlInstruction instr) { stms.Add(new RtlInstructionCluster(Address.Ptr32(linAddress), 4, instr)); linAddress += 4; return(instr); }
private bool IsTransfer(RtlInstructionCluster i, RtlInstruction r) { return(r is RtlGoto || r is RtlCall); }
public void Emit(RtlInstruction instr) { instrs.Add(instr); }
public RtlEmitter If(Expression test, RtlInstruction rtl) { instrs.Add(new RtlIf(test, rtl)); return this; }
public override SystemService FindService(RtlInstruction rtl, ProcessorState state) { return(base.FindService(rtl, state)); }
public SystemService FindService(RtlInstruction call, ProcessorState state) { throw new NotImplementedException(); }
public virtual SystemService FindService(RtlInstruction rtl, ProcessorState state) { return(null); }
public RtlInstruction Emit(RtlInstruction instr) { stms.Add(new RtlInstructionCluster(Address.Ptr32(linAddress), 4, instr)); linAddress += 4; return instr; }
public virtual SystemService FindService(RtlInstruction rtl, ProcessorState state) { return null; }
private bool IsTransfer(RtlInstructionCluster i, RtlInstruction r) { return r is RtlGoto || r is RtlCall; }
public override SystemService FindService(RtlInstruction rtl, ProcessorState state) { return base.FindService(rtl, state); }