当前位置: 首页>>代码示例>>C#>>正文


C# IScanner.Stub方法代码示例

本文整理汇总了C#中IScanner.Stub方法的典型用法代码示例。如果您正苦于以下问题:C# IScanner.Stub方法的具体用法?C# IScanner.Stub怎么用?C# IScanner.Stub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IScanner的用法示例。


在下文中一共展示了IScanner.Stub方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
 }
开发者ID:relaxar,项目名称:reko,代码行数:31,代码来源:BlockWorkitemTests.cs

示例2: 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);
 }
开发者ID:relaxar,项目名称:reko,代码行数:53,代码来源:BlockWorkitem.X86Tests.cs

示例3: 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();
        }
开发者ID:gitter-badger,项目名称:reko,代码行数:32,代码来源:BlockWorkitemTests.cs

示例4: Bwi_CallingAllocaWithNonConstant

        public void Bwi_CallingAllocaWithNonConstant()
        {
            scanner = mr.StrictMock<IScanner>();
            arch = new IntelArchitecture(ProcessorMode.Protected32);
            program.Platform = new DefaultPlatform(null, arch);

            var sig = CreateSignature(Registers.esp, Registers.eax);
            var alloca = new ExternalProcedure("alloca", sig, new ProcedureCharacteristics
            {
                IsAlloca = true
            });

            trace.Add(m => m.Call(Address.Ptr32(0x2000), 4));

            using (mr.Record())
            {
                scanner.Stub(x => x.FindContainingBlock(
                    Arg<Address>.Is.Anything)).Return(block);
                scanner.Expect(x => x.GetImportedProcedure(
                    Arg<Address>.Is.Equal(Address.Ptr32(0x2000u)),
                    Arg<Address>.Is.NotNull)).Return(alloca);
                scanner.Stub(x => x.GetTrace(null, null, null)).IgnoreArguments().Return(trace);
                    
            }
            var wi = CreateWorkItem(Address.Ptr32(0x1000), new FakeProcessorState(arch));
            wi.ProcessInternal();
            mr.VerifyAll();
            Assert.AreEqual(1, block.Statements.Count);
            Assert.AreEqual("esp = alloca(eax)", block.Statements.Last.ToString());
        }
开发者ID:gitter-badger,项目名称:reko,代码行数:30,代码来源:BlockWorkitemTests.cs

示例5: Bwi_CallingAllocaWithConstant

        public void Bwi_CallingAllocaWithConstant()
        {
            scanner = mr.StrictMock<IScanner>();
            prog.Architecture = new IntelArchitecture(ProcessorMode.Protected32);

            var sig = CreateSignature(Registers.esp, Registers.eax);
            var alloca = new ExternalProcedure("alloca", sig);
            alloca.Characteristics = new ProcedureCharacteristics
            {
                IsAlloca = true
            };

            using (mr.Record())
            {
                scanner.Stub(x => x.FindContainingBlock(
                    Arg<Address>.Is.Anything)).Return(block);
                scanner.Expect(x => x.GetImportedProcedure(
                    Arg<Address>.Matches(a => a.ToLinear() == 0x2000u),
                    Arg<Address>.Is.NotNull)).Return(alloca);
                scanner.Stub(x => x.GetTrace(null, null, null)).IgnoreArguments().Return(trace);
            }
            trace.Add(m => m.Call(Address.Ptr32(0x2000), 4));
            var state = new FakeProcessorState(prog.Architecture);
            state.SetRegister(Registers.eax, Constant.Word32(0x0400));
            var wi = CreateWorkItem(Address.Ptr32(0x1000), state);
            wi.ProcessInternal();

            mr.VerifyAll();
            Assert.AreEqual(1, block.Statements.Count);
            Assert.AreEqual("esp = esp - 0x00000400", block.Statements.Last.ToString());
        }
开发者ID:feelworld,项目名称:reko,代码行数:31,代码来源:BlockWorkitemTests.cs

示例6: 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);
        }
开发者ID:killbug2004,项目名称:reko,代码行数:44,代码来源:BlockWorkitem.X86Tests.cs


注:本文中的IScanner.Stub方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。