Example #1
0
        private void BuildTest(IntelArchitecture arch, Address addr, IPlatform platform, Action <X86Assembler> m)
        {
            proc  = new Procedure(arch, "test", addr, arch.CreateFrame());
            block = proc.AddBlock("testblock");
            var asm = new X86Assembler(sc, new DefaultPlatform(sc, arch), addr, new List <ImageSymbol>());

            scanner = new Mock <IScanner>();
            scanner.Setup(s => s.Services).Returns(sc);
            m(asm);
            lr         = asm.GetImage();
            this.state = arch.CreateProcessorState();
            host       = new RewriterHost(
                asm.ImportReferences,
                new Dictionary <string, FunctionType>
            {
                {
                    "GetDC",
                    new FunctionType(
                        new Identifier("", new Pointer(VoidType.Instance, 32), new RegisterStorage("eax", 0, 0, PrimitiveType.Word32)),
                        new [] {
                        new Identifier("arg",
                                       new TypeReference(
                                           "HWND",
                                           new Pointer(VoidType.Instance, 32)),
                                       new StackArgumentStorage(4, new TypeReference(
                                                                    "HWND",
                                                                    new Pointer(VoidType.Instance, 32))))
                    })
                    {
                        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,
            };

            scanner.Setup(x => x.FindContainingBlock(It.IsAny <Address>())).Returns(block);
            scanner.Setup(x => x.GetTrace(
                              It.IsAny <IProcessorArchitecture>(),
                              It.IsAny <Address>(),
                              It.IsAny <ProcessorState>(),
                              It.IsAny <IStorageBinder>())).Returns(rw);
            scanner.Setup(x => x.Services).Returns(sc);

            wi = new BlockWorkitem(scanner.Object, program, arch, state, addr);
        }
Example #2
0
        private void BuildTest(IntelArchitecture arch, Address addr, IPlatform platform, Action <X86Assembler> m)
        {
            this.arch  = new X86ArchitectureFlat32();
            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>();
            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, 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.SegmentMap.Segments.Values.First().MemoryArea.CreateLeReader(addr),
                this.state,
                proc.Frame,
                host);
            var prog = 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);
            }
            wi = new BlockWorkitem(scanner, prog, state, addr);
        }
Example #3
0
 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);
 }
Example #4
0
 public override BlockWorkitem CreateBlockWorkItem(Address addrStart, Procedure proc, ProcessorState state)
 {
     Test_LastBlockWorkitem = base.CreateBlockWorkItem(addrStart, proc, state);
     return(Test_LastBlockWorkitem);
 }
        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);
        }
Example #6
0
 public override BlockWorkitem CreateBlockWorkItem(Address addrStart, Procedure proc, ProcessorState state)
 {
     Test_LastBlockWorkitem = base.CreateBlockWorkItem(addrStart, proc, state);
     return Test_LastBlockWorkitem;
 }