public void Setup()
		{
            mr = new MockRepository();
            form = new MainForm();
            sc = new ServiceContainer();
            loader = mr.StrictMock<ILoader>();
            dec = mr.StrictMock<IDecompiler>();
            sc = new ServiceContainer();
            uiSvc = new FakeShellUiService();
            host = mr.StrictMock<DecompilerHost>();
            memSvc = mr.StrictMock<ILowLevelViewService>();
            var image = new LoadedImage(Address.Ptr32(0x10000), new byte[1000]);
            var imageMap = image.CreateImageMap();
            var arch = mr.StrictMock<IProcessorArchitecture>();
            arch.Stub(a => a.CreateRegisterBitset()).Return(new BitSet(32));
            arch.Replay();
            var platform = mr.StrictMock<Platform>(null, arch);
            arch.BackToRecord();
            program = new Program(image, imageMap, arch, platform);
            project = new Project { Programs = { program } };

            browserSvc = mr.StrictMock<IProjectBrowserService>();

            sc.AddService<IDecompilerUIService>(uiSvc);
            sc.AddService(typeof(IDecompilerShellUiService), uiSvc);
            sc.AddService(typeof(IDecompilerService), new DecompilerService());
            sc.AddService(typeof(IWorkerDialogService), new FakeWorkerDialogService());
            sc.AddService(typeof(DecompilerEventListener), new FakeDecompilerEventListener());
            sc.AddService(typeof(IProjectBrowserService), browserSvc);
            sc.AddService(typeof(ILowLevelViewService), memSvc);
            sc.AddService<ILoader>(loader);

            i = new TestInitialPageInteractor(sc, dec);

		}
Пример #2
0
        public void HSC_x86_FindCallsToProcedure()
        {
#if OLD
            var image = new LoadedImage(Address.Ptr32(0x001000), new byte[] {
                0xE8, 0x0B, 0x00, 0x00,  0x00, 0xE8, 0x07, 0x00,
                0x00, 0x00, 0xC3, 0x00,  0x00, 0x00, 0x00, 0x00,
                0xC3, 0xC3                                      // 1010, 1011
            });
            prog = new Program
            {
                Image = image,
                ImageMap = image.CreateImageMap(),
                Architecture = new IntelArchitecture(ProcessorMode.Protected32),
            };
#else
            Given_Image32(0x001000, 
                "E8 0B 00 00 00 E8 07 00 " +
                "00 00 C3 00 00 00 00 00 " +
                "C3 C3 ");                                     // 1010, 1011
            Given_x86_32();
#endif
            Given_RewriterHost();
            mr.ReplayAll();

            Assert.AreEqual(18, prog.Image.Length);

            var hsc = new HeuristicScanner(prog, host);
            var linAddrs = hsc.FindCallOpcodes(new Address[]{
                Address.Ptr32(0x1010),
                Address.Ptr32(0x1011)}).ToList();

            Assert.AreEqual(2, linAddrs.Count);
            Assert.IsTrue(linAddrs.Contains(Address.Ptr32(0x1000)));
            Assert.IsTrue(linAddrs.Contains(Address.Ptr32(0x1005)));
        }
Пример #3
0
 private void BuildTest(params uint[] words)
 {
     var bytes = words
         .SelectMany(u => new byte[] { (byte) u, (byte) (u >> 8), (byte) (u >> 16), (byte) (u >> 24) })
         .ToArray();
     image = new LoadedImage(Address.Ptr32(0x00100000), bytes);
 }
Пример #4
0
 private static SparcInstruction DisassembleWord(uint instr)
 {
     var bytes = new byte[4];
     new BeImageWriter(bytes).WriteBeUInt32(0, instr);
     var img = new LoadedImage(Address.Ptr32(0x00100000), bytes);
     return Disassemble(img);
 }
Пример #5
0
        public override Program Load(Address addrLoad)
        {
            BinHexDecoder dec = new BinHexDecoder(new StringReader(Encoding.ASCII.GetString(RawImage)));
            IEnumerator<byte> stm = dec.GetBytes().GetEnumerator();
            BinHexHeader hdr = LoadBinHexHeader(stm);
            byte[] dataFork = LoadFork(hdr.DataForkLength, stm);
            byte[] rsrcFork = LoadFork(hdr.ResourceForkLength, stm);

            var arch = new M68kArchitecture();
            var platform = new MacOSClassic(Services, arch);
            if (hdr.FileType == "PACT")
            {
                Cpt.CompactProArchive archive = new Cpt.CompactProArchive();
                List<ArchiveDirectoryEntry> items = archive.Load(new MemoryStream(dataFork));
                IArchiveBrowserService abSvc = Services.GetService<IArchiveBrowserService>();
                if (abSvc != null)
                {
                    var selectedFile = abSvc.UserSelectFileFromArchive(items);
                    if (selectedFile != null)
                    {
                        var image = selectedFile.GetBytes();
                        this.rsrcFork = new ResourceFork(image, arch);
                        this.image = new LoadedImage(addrLoad, image);
                        this.imageMap = new ImageMap(addrLoad, image.Length);
                        return new Program(this.image, this.imageMap, arch, platform);
                    }
                }
            }

            var li = new LoadedImage(addrLoad, dataFork);
            return new Program(li, li.CreateImageMap(), arch, platform);
        }
Пример #6
0
 private void BuildTest(params string[] bitStrings)
 {
     var bytes = bitStrings.Select(bits => base.ParseBitPattern(bits))
         .SelectMany(u => new byte[] { (byte) u, (byte) (u >> 8), (byte) (u >> 16), (byte) (u >> 24) })
         .ToArray();
     image = new LoadedImage(Address.Ptr32(0x00100000), bytes);
 }
		public void Setup()
		{
            var image = new LoadedImage(Address.Ptr32(0x00100000), new byte[1024]);
            var arch = new FakeArchitecture();
            var program = new Program
            {
                Image = image,
                Architecture = arch,
                ImageMap = image.CreateImageMap(),
                Platform = new DefaultPlatform(null, arch),
            };
            store = program.TypeStore;
            factory = program.TypeFactory;
            globals = program.Globals;
			store.EnsureExpressionTypeVariable(factory, globals);

			StructureType s = new StructureType(null, 0);
			s.Fields.Add(0x00100000, PrimitiveType.Word32, null);

			TypeVariable tvGlobals = store.EnsureExpressionTypeVariable(factory, globals);
			EquivalenceClass eqGlobals = new EquivalenceClass(tvGlobals);
			eqGlobals.DataType = s;
			globals.TypeVariable.DataType = new Pointer(eqGlobals, 4);
			globals.DataType = globals.TypeVariable.DataType;

            tcr = new TypedConstantRewriter(program);
		}
Пример #8
0
 private IntelInstruction Disassemble64(params byte[] bytes)
 {
     var img = new LoadedImage(Address.Ptr64(0x10000), bytes);
     var rdr = img.CreateLeReader(img.BaseAddress);
     var dasm = new X86Disassembler(rdr, PrimitiveType.Word32, PrimitiveType.Word64, true);
     return dasm.First();
 }
Пример #9
0
		public void UShortFixup()
		{
			var bytes = new byte[] { 0x01, 0x02, 0x03 };
			var img = new LoadedImage(Address.SegPtr(0x0C00, 0), bytes);
			ushort newSeg = img.FixupLeUInt16(1, 0x4444);
			Assert.AreEqual(0x4746, newSeg);
		}
Пример #10
0
 public Program(LoadedImage image, ImageMap imageMap, IProcessorArchitecture arch, Platform platform) : this()
 {
     this.Image = image;
     this.ImageMap = imageMap;
     this.Architecture = arch;
     this.Platform = platform;
 }
Пример #11
0
 private MachineInstruction RunTest(params byte [] bytes)
 {
     var image = new LoadedImage(Address.Ptr16(0x0100), bytes);
     var rdr = new LeImageReader(image, 0);
     var dasm = new Z80Disassembler(rdr);
     return dasm.First();
 }
Пример #12
0
 public void ValidateImage()
 {
     Program prog = new Program();
     LoadedImage rawImage = new LoadedImage(Address.SegPtr(0x0C00, 0), CreateMsdosHeader());
     ExeImageLoader exe = new ExeImageLoader(null, "foo.exe", rawImage.Bytes);
     Assert.IsTrue(PkLiteUnpacker.IsCorrectUnpacker(exe, rawImage.Bytes));
 }
Пример #13
0
 private IntelInstruction Disassemble16(params byte[] bytes)
 {
     LoadedImage img = new LoadedImage(Address.SegPtr(0xC00, 0), bytes);
     ImageReader rdr = img.CreateLeReader(img.BaseAddress);
     var dasm = new X86Disassembler(rdr, PrimitiveType.Word16, PrimitiveType.Word16, false);
     return dasm.First();
 }
Пример #14
0
		public void ReadLeUInt32()
		{
			LoadedImage img = new LoadedImage(Address.Ptr32(0x10000), new byte[] {
				0x78, 0x56, 0x34, 0x12 });
			Constant c = img.ReadLe(0, PrimitiveType.Word32);
			Assert.AreSame(PrimitiveType.Word32, c.DataType);
			Assert.AreEqual("0x12345678", c.ToString());
		}
Пример #15
0
 private void RunTest(string sExp, params byte[] bytes)
 {
     var image = new LoadedImage(Address.Ptr32(0x0100000), bytes);
     var dasm = new CilDisassembler(image.CreateLeReader(0)).GetEnumerator();
     Assert.IsTrue(dasm.MoveNext());
     var instr = dasm.Current;
     Assert.AreEqual(sExp, instr.ToString());
 }
Пример #16
0
		public void ReadLeNegativeInt()
		{
			LoadedImage img = new LoadedImage(Address.Ptr32(0x10000), new byte[] {
				0xFE, 0xFF, 0xFF, 0xFF });
			Constant c = img.ReadLe(0, PrimitiveType.Int32);
			Assert.AreSame(PrimitiveType.Int32, c.DataType);
			Assert.AreEqual("-2", c.ToString());
		}
Пример #17
0
 public X86Emulator(IntelArchitecture arch, LoadedImage loadedImage, IPlatformEmulator envEmulator)
 {
     this.arch = arch;
     this.img = loadedImage;
     this.Registers = new ulong[40];
     this.Valid = new bool[40];
     this.envEmulator = envEmulator;
 }
Пример #18
0
 private void CreateDisassembler32(LoadedImage image)
 {
     dasm = new X86Disassembler(
         image.CreateLeReader(image.BaseAddress),
         PrimitiveType.Word32,
         PrimitiveType.Word32,
         false);
 }
Пример #19
0
 public void Setup()
 {
     mr = new MockRepository();
     sc = new ServiceContainer();
     var image = new LoadedImage(Address.SegPtr(0xC00, 0), Enumerable.Range(0x0, 0x100).Select(b => (byte)b).ToArray());
     var imageMap = image.CreateImageMap();
     var arch = new Mocks.FakeArchitecture();
     this.program = new Program(image, imageMap, arch, new DefaultPlatform(sc, arch));
 }
Пример #20
0
 public ProgramBuilder(LoadedImage loadedImage)
 {
     Program = new Program
     {
         Image = loadedImage,
         ImageMap = loadedImage.CreateImageMap(),
         Architecture = new FakeArchitecture()
     };
 }
Пример #21
0
 private void btnLoad_Click(object sender, EventArgs e)
 {
     var image = new LoadedImage(Address.Ptr32(0x12312300),new byte[0x1000]);
     var imageMap = image.CreateImageMap();
     var arch = new Decompiler.Arch.X86.X86ArchitectureFlat32();
     var program = new Core.Program(image, imageMap, arch, new DefaultPlatform(null, arch));
     var project = new Project { Programs = { program } };
     pbs.Load(project);
 }
Пример #22
0
 protected ImageReader(LoadedImage img, ulong off)
 {
     if (img == null)
         throw new ArgumentNullException("img");
     this.image = img;
     this.bytes = img.Bytes;
     this.addrStart = img.BaseAddress + off;
     this.off = offStart = off;
 }
Пример #23
0
 public Program GetImage()
 {
     var image = new LoadedImage(BaseAddress, emitter.GetBytes());
     return new Program(
         image,
         image.CreateImageMap(),
         arch,
         new DefaultPlatform(null, arch));
 }
Пример #24
0
 protected MachineInstruction Disassemble(uint instr)
 {
     var image = new LoadedImage(Address.Ptr32(0x00100000), new byte[4]);
     LeImageWriter w = new LeImageWriter(image.Bytes);
     w.WriteLeUInt32(0, instr);
     var arch = CreateArchitecture();
     var dasm = CreateDisassembler(arch, image.CreateLeReader(0));
     Assert.IsTrue(dasm.MoveNext());
     return dasm.Current;
 }
Пример #25
0
 private void Rewrite(params ushort[] opcodes)
 {
     byte[] bytes = new byte[opcodes.Length * 2];
     var writer = new BeImageWriter(bytes);
     foreach (ushort opcode in opcodes)
     {
         writer.WriteBeUInt16(opcode);
     }
     image = new LoadedImage(addrBase, bytes);
 }
Пример #26
0
 protected void Given_Image32(uint addr, string sBytes)
 {
     var bytes = HexStringToBytes(sBytes);
     var imag = new LoadedImage(Address.Ptr32(addr), bytes);
     prog = new Program
     {
         Image = imag,
         ImageMap = imag.CreateImageMap()
     };
 }
Пример #27
0
 protected override IEnumerable<RtlInstructionCluster> GetInstructionStream(Frame frame, IRewriterHost host)
 {
     var addr = Address.Ptr16(10);
     var image = new LoadedImage(addr, new byte[1]);
     return arch.CreateRewriter(
         arch.CreateImageReader(image, addr),
         arch.CreateProcessorState(),
         frame,
         host);
 }
Пример #28
0
 private void BuildTest32(Address addrBase, params byte[] bytes)
 {
     arch = new M68kArchitecture();
     var image = new LoadedImage(addrBase, bytes);
     program = new Program(
         image,
         image.CreateImageMap(),
         arch,
         new DefaultPlatform(null, arch));
     RunTest(addrBase);
 }
Пример #29
0
 public override Program Load(Address addrLoad)
 {
     int iImageStart = (exe.e_cparHeader * 0x10);
     int cbImageSize = exe.e_cpImage * ExeImageLoader.CbPageSize - iImageStart;
     byte[] bytes = new byte[cbImageSize];
     int cbCopy = Math.Min(cbImageSize, RawImage.Length - iImageStart);
     Array.Copy(RawImage, iImageStart, bytes, 0, cbCopy);
     imgLoaded = new LoadedImage(addrLoad, bytes);
     imgLoadedMap = imgLoaded.CreateImageMap();
     return new Program(imgLoaded, imgLoadedMap, arch, platform);
 }
Пример #30
0
        public Win32Emulator(LoadedImage img, Platform platform, Dictionary<Address, ImportReference> importReferences)
        {
            this.img = img;
            this.platform = platform;
            this.uPseudoFn = 0xDEAD0000u;   // unlikely to be a real pointer to a function
            this.InterceptedCalls = new Dictionary<uint, ExternalProcedure>();

            modules = new Dictionary<string, Module>(StringComparer.InvariantCultureIgnoreCase);
            AddWellKnownProcedures();
            InterceptCallsToImports(importReferences);
        }