本文整理汇总了C#中Procedure.AddBlock方法的典型用法代码示例。如果您正苦于以下问题:C# Procedure.AddBlock方法的具体用法?C# Procedure.AddBlock怎么用?C# Procedure.AddBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Procedure
的用法示例。
在下文中一共展示了Procedure.AddBlock方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public void Setup()
{
mr = new MockRepository();
program = new Program();
proc = new Procedure("testProc", new Frame(PrimitiveType.Word32));
block = proc.AddBlock("l00100000");
trace = new RtlTrace(0x00100000);
r0 = new Identifier("r0", PrimitiveType.Word32, new RegisterStorage("r0", 0, 0, PrimitiveType.Word32));
r1 = new Identifier("r1", PrimitiveType.Word32, new RegisterStorage("r1", 1, 0, PrimitiveType.Word32));
r2 = new Identifier("r2", PrimitiveType.Word32, new RegisterStorage("r2", 2, 0, PrimitiveType.Word32));
sp = new Identifier("sp", PrimitiveType.Word32, new RegisterStorage("sp", 15, 0, PrimitiveType.Word32));
grf = proc.Frame.EnsureFlagGroup(Registers.eflags, 3, "SCZ", PrimitiveType.Byte);
var sc = new ServiceContainer();
var listener = mr.Stub<DecompilerEventListener>();
scanner = mr.StrictMock<IScanner>();
arch = mr.Stub<IProcessorArchitecture>();
program.Architecture = arch;
program.SegmentMap = new SegmentMap(
Address.Ptr32(0x00100000),
new ImageSegment(
".text",
new MemoryArea(Address.Ptr32(0x00100000), new byte[0x20000]),
AccessMode.ReadExecute));
arch.Replay();
program.Platform = new DefaultPlatform(null, arch);
arch.BackToRecord();
arch.Stub(s => s.StackRegister).Return((RegisterStorage)sp.Storage);
arch.Stub(s => s.PointerType).Return(PrimitiveType.Pointer32);
scanner.Stub(s => s.Services).Return(sc);
sc.AddService<DecompilerEventListener>(listener);
}
示例2: Setup
public void Setup()
{
mr = new MockRepository();
program = new Program();
proc = new Procedure("testProc", new Frame(PrimitiveType.Word32));
block = proc.AddBlock("l00100000");
trace = new RtlTrace(0x00100000);
r0 = new Identifier("r0", PrimitiveType.Word32, new RegisterStorage("r0", 0, 0, PrimitiveType.Word32));
r1 = new Identifier("r1", PrimitiveType.Word32, new RegisterStorage("r1", 1, 0, PrimitiveType.Word32));
r2 = new Identifier("r2", PrimitiveType.Word32, new RegisterStorage("r2", 2, 0, PrimitiveType.Word32));
grf = proc.Frame.EnsureFlagGroup(Registers.eflags, 3, "SCZ", PrimitiveType.Byte);
scanner = mr.StrictMock<IScanner>();
arch = mr.DynamicMock<IProcessorArchitecture>();
arch.Stub(s => s.PointerType).Return(PrimitiveType.Pointer32);
program.Architecture = arch;
arch.Replay();
program.Platform = new DefaultPlatform(null, arch);
arch.BackToRecord();
}
示例3: TrfPropagateToSuccessorBlocks
public void TrfPropagateToSuccessorBlocks()
{
Procedure proc = new Procedure("test", program.Architecture.CreateFrame());
var frame = proc.Frame;
Identifier ecx = m.Register(1);
Identifier edx = m.Register(2);
Identifier ebx = m.Register(3);
Block b = proc.AddBlock("b");
Block t = proc.AddBlock("t");
Block e = proc.AddBlock("e");
proc.ControlGraph.AddEdge(b, e);
proc.ControlGraph.AddEdge(b, t);
flow[t] = new BlockFlow(t, null, new SymbolicEvaluationContext(program.Architecture, frame));
flow[e] = new BlockFlow(e, null, new SymbolicEvaluationContext(program.Architecture, frame));
trf = CreateTrashedRegisterFinder(program);
CreateBlockFlow(b, frame);
trf.StartProcessingBlock(b);
trf.RegisterSymbolicValues[(RegisterStorage) ecx.Storage] = Constant.Invalid;
trf.RegisterSymbolicValues[(RegisterStorage) edx.Storage] = ebx;
flow[e].SymbolicIn.RegisterState[(RegisterStorage) ecx.Storage] = edx;
flow[e].SymbolicIn.RegisterState[(RegisterStorage) edx.Storage] = ebx;
flow[t].SymbolicIn.RegisterState[(RegisterStorage) ecx.Storage] = Constant.Invalid;
flow[t].SymbolicIn.RegisterState[(RegisterStorage) edx.Storage] = edx;
trf.PropagateToSuccessorBlock(e);
trf.PropagateToSuccessorBlock(t);
Assert.AreEqual(2, proc.ControlGraph.Successors(b).Count);
Assert.AreEqual("<invalid>", flow[e].SymbolicIn.RegisterState[(RegisterStorage) ecx.Storage].ToString(), "trash & r2 => trash");
Assert.AreEqual("ebx", flow[e].SymbolicIn.RegisterState[(RegisterStorage) edx.Storage].ToString(), "ebx & ebx => ebx");
Assert.AreEqual("<invalid>", flow[e].SymbolicIn.RegisterState[(RegisterStorage) ecx.Storage].ToString(), "trash & r2 => trash");
Assert.AreEqual("ebx", flow[e].SymbolicIn.RegisterState[(RegisterStorage) edx.Storage].ToString(), "ebx & ebx => ebx");
Assert.AreEqual("<invalid>", flow[t].SymbolicIn.RegisterState[(RegisterStorage) ecx.Storage].ToString(), "trash & trash => trash");
Assert.AreEqual("<invalid>", flow[t].SymbolicIn.RegisterState[(RegisterStorage) edx.Storage].ToString(), "r3 & r2 => trash");
}
示例4: CreateCallRetThunk
/// <summary>
/// Creates a small basic block, consisting solely of a 'call' followed by a 'return'
/// instruction.
/// </summary>
/// <param name="addrFrom"></param>
/// <param name="procOld"></param>
/// <param name="procNew"></param>
/// <returns></returns>
public Block CreateCallRetThunk(Address addrFrom, Procedure procOld, Procedure procNew)
{
var blockName = string.Format(
"{0}_thunk_{1}",
GenerateBlockName(addrFrom),
procNew.Name);
var callRetThunkBlock = procOld.AddBlock(blockName);
callRetThunkBlock.Statements.Add(0, new CallInstruction(
new ProcedureConstant(program.Platform.PointerType, procNew),
new CallSite(procNew.Signature.ReturnAddressOnStack, 0)));
program.CallGraph.AddEdge(callRetThunkBlock.Statements.Last, procNew);
callRetThunkBlock.Statements.Add(0, new ReturnInstruction());
procOld.ControlGraph.AddEdge(callRetThunkBlock, procOld.ExitBlock);
SetProcedureReturnAddressBytes(procOld, procNew.Frame.ReturnAddressSize, addrFrom);
return callRetThunkBlock;
}
示例5: BuildTest
private void BuildTest(IntelArchitecture arch, Address addr, IPlatform platform, Action<X86Assembler> m)
{
proc = new Procedure("test", arch.CreateFrame());
block = proc.AddBlock("testblock");
this.state = arch.CreateProcessorState();
var asm = new X86Assembler(sc, new DefaultPlatform(sc, arch), addr, new List<ImageSymbol>());
scanner = mr.StrictMock<IScanner>();
scanner.Stub(s => s.Services).Return(sc);
m(asm);
lr = asm.GetImage();
host = new RewriterHost(
asm.ImportReferences,
new Dictionary<string, FunctionType>
{
{
"GetDC",
new FunctionType(
new Identifier("", new Pointer(VoidType.Instance, 4), new RegisterStorage("eax", 0, 0, PrimitiveType.Word32)),
new [] {
new Identifier("arg",
new TypeReference(
"HWND",
new Pointer(VoidType.Instance, 4)),
new StackArgumentStorage(4, new TypeReference(
"HWND",
new Pointer(VoidType.Instance, 4))))
})
{
StackDelta = 4,
}
}
},
new Dictionary<string, DataType>());
var rw = arch.CreateRewriter(
lr.SegmentMap.Segments.Values.First().MemoryArea.CreateLeReader(addr),
this.state,
proc.Frame,
host);
this.program = new Program
{
Architecture = arch,
SegmentMap = lr.SegmentMap,
ImageMap = lr.ImageMap,
Platform = platform,
};
using (mr.Record())
{
scanner.Stub(x => x.FindContainingBlock(Arg<Address>.Is.Anything)).Return(block);
scanner.Stub(x => x.GetTrace(null, null, null)).IgnoreArguments().Return(rw);
scanner.Stub(x => x.Services).Return(sc);
}
wi = new BlockWorkitem(scanner, program, state, addr);
}
示例6: Bwi_CallTerminatingProcedure_StopScanning
public void Bwi_CallTerminatingProcedure_StopScanning()
{
proc = Procedure.Create("proc", Address.Ptr32(0x002000), new Frame(PrimitiveType.Pointer32));
var terminator = Procedure.Create("terminator", Address.Ptr32(0x0001000), new Frame(PrimitiveType.Pointer32));
terminator.Characteristics = new ProcedureCharacteristics {
Terminates = true,
};
block = proc.AddBlock("the_block");
scanner = mr.StrictMock<IScanner>();
arch.Stub(a => a.PointerType).Return(PrimitiveType.Word32);
scanner.Stub(s => s.FindContainingBlock(Arg<Address>.Is.Anything)).Return(block);
scanner.Stub(s => s.GetCallSignatureAtAddress(Arg<Address>.Is.Anything)).Return(null);
scanner.Stub(s => s.GetImportedProcedure(Arg<Address>.Is.Anything, Arg<Address>.Is.NotNull)).Return(null);
scanner.Expect(s => s.ScanProcedure(
Arg<Address>.Is.Anything,
Arg<string>.Is.Anything,
Arg<ProcessorState>.Is.Anything))
.Return(terminator);
scanner.Expect(s => s.TerminateBlock(Arg<Block>.Is.NotNull, Arg<Address>.Is.NotNull));
arch.Stub(a => a.FramePointerType).Return(PrimitiveType.Pointer32);
scanner.Stub(s => s.GetTrace(null, null, null)).IgnoreArguments().Return(trace);
mr.ReplayAll();
trace.Add(m => m.Call(Address.Ptr32(0x0001000), 4));
trace.Add(m => m.SideEffect(new ProcedureConstant(VoidType.Instance, new PseudoProcedure("shouldnt_decompile_this", VoidType.Instance, 0))));
var wi = CreateWorkItem(Address.Ptr32(0x2000), new FakeProcessorState(arch));
wi.ProcessInternal();
Assert.AreEqual(1, block.Statements.Count, "Should only have rewritten the Call to 'terminator'");
mr.VerifyAll();
}
示例7: CreateCallRetThunk
/// <summary>
/// Creates a small basic block, consisting solely of a 'call' followed by a 'return'
/// instruction.
/// </summary>
/// <param name="addrFrom"></param>
/// <param name="procOld"></param>
/// <param name="procNew"></param>
/// <returns></returns>
public Block CreateCallRetThunk(Address addrFrom, Procedure procOld, Procedure procNew)
{
//$BUG: ReturnAddressOnStack property needs to be properly set, the
// EvenOdd sample shows how this doesn't work currently.
var blockName = string.Format(
"{0}_thunk_{1}",
Block.GenerateName(addrFrom),
procNew.Name);
var callRetThunkBlock = procOld.AddBlock(blockName);
callRetThunkBlock.IsSynthesized = true;
var linFrom = addrFrom.ToLinear();
callRetThunkBlock.Statements.Add(
addrFrom.ToLinear(),
new CallInstruction(
new ProcedureConstant(program.Platform.PointerType, procNew),
new CallSite(
procNew.Signature.ReturnAddressOnStack,
0)));
program.CallGraph.AddEdge(callRetThunkBlock.Statements.Last, procNew);
callRetThunkBlock.Statements.Add(linFrom, new ReturnInstruction());
procOld.ControlGraph.AddEdge(callRetThunkBlock, procOld.ExitBlock);
SetProcedureReturnAddressBytes(procOld, procNew.Frame.ReturnAddressSize, addrFrom);
return callRetThunkBlock;
}
示例8: BuildTest
private void BuildTest(IntelArchitecture arch, Address addr, Platform platform, Action<X86Assembler> m)
{
this.arch = new IntelArchitecture(ProcessorMode.Protected32);
proc = new Procedure("test", arch.CreateFrame());
block = proc.AddBlock("testblock");
this.state = arch.CreateProcessorState();
var asm = new X86Assembler(arch, addr, new List<EntryPoint>());
scanner = repository.StrictMock<IScanner>();
m(asm);
lr = asm.GetImage();
host = new RewriterHost(asm.ImportReferences,
new Dictionary<string, ProcedureSignature>
{
{
"GetDC",
new ProcedureSignature(
new Identifier("", new Pointer(VoidType.Instance, 4), new RegisterStorage("eax", 0, PrimitiveType.Word32)),
new Identifier("arg",
new TypeReference(
"HWND",
new Pointer(VoidType.Instance, 4)),
new StackArgumentStorage(0, new TypeReference(
"HWND",
new Pointer(VoidType.Instance, 4)))))
{
StackDelta = 4,
}
}
});
var rw = arch.CreateRewriter(lr.Image.CreateLeReader(addr), this.state, proc.Frame, host);
var prog = new Program
{
Architecture = arch,
Image = lr.Image,
ImageMap = lr.ImageMap,
Platform = platform,
};
using (repository.Record())
{
scanner.Stub(x => x.FindContainingBlock(Arg<Address>.Is.Anything)).Return(block);
scanner.Stub(x => x.GetTrace(null, null, null)).IgnoreArguments().Return(rw);
}
wi = new BlockWorkitem(scanner, prog, state, addr);
}