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);
		}
예제 #2
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);
        }
		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);

		}
예제 #4
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, eventListener);
            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)));
        }
예제 #5
0
        public void DecSvc_DecompilerProjectName()
        {
            IDecompilerService svc = new DecompilerService();
            var loader = mr.StrictMock<ILoader>();
            var host = mr.StrictMock<DecompilerHost>();
            var arch = mr.StrictMock<IProcessorArchitecture>();
            var platform = mr.StrictMock<Platform>(sc, arch);
            var fileName = "foo\\bar\\baz.exe";
            var bytes = new byte[100];
            var image = new LoadedImage(Address.Ptr32(0x1000), bytes);
            var imageMap = image.CreateImageMap();
            var prog = new Program(image, imageMap, arch, platform);
            loader.Stub(l => l.LoadImageBytes(fileName, 0)).Return(bytes);
            loader.Stub(l => l.LoadExecutable(fileName, bytes, null)).Return(prog);
            loader.Replay();
            var dec = new DecompilerDriver(loader, host, sc);
            mr.ReplayAll();

            svc.Decompiler = dec;
            svc.Decompiler.Load(fileName);

            Assert.IsNotNull(svc.Decompiler.Project);
            Assert.AreEqual("baz.exe",  svc.ProjectName, "Should have project name available.");
            mr.VerifyAll();
        }
예제 #6
0
 public ProgramBuilder(LoadedImage loadedImage)
 {
     Program = new Program
     {
         Image = loadedImage,
         ImageMap = loadedImage.CreateImageMap(),
         Architecture = new FakeArchitecture()
     };
 }
예제 #7
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 Reko.Arch.X86.X86ArchitectureFlat32();
     var program = new Core.Program(image, imageMap, arch, new DefaultPlatform(null, arch));
     var project = new Project { Programs = { program } };
     pbs.Load(project);
 }
예제 #8
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));
 }
예제 #9
0
 public Program GetImage()
 {
     var image = new LoadedImage(BaseAddress, Emitter.GetBytes());
     return new Program(
         image,
         image.CreateImageMap(),
         arch, 
         new DefaultPlatform(null, arch));
 }
예제 #10
0
 internal void Given_ImageSeg(ushort seg, ushort offset, string sBytes)
 {
     var bytes = HexStringToBytes(sBytes);
     var imag = new LoadedImage(Address.SegPtr(seg, offset), bytes);
     prog = new Program
     {
         Image = imag,
         ImageMap = imag.CreateImageMap()
     };
 }
예제 #11
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(),
     };
 }
예제 #12
0
 public override Program Load(Address addrLoad)
 {
     if (addrLoad == null)
         addrLoad = PreferredBaseAddress;
     var image = new LoadedImage(addrLoad, imageBytes);
     return new Program(
         image,
         image.CreateImageMap(),
         Architecture,
         Platform ?? new DefaultPlatform(Services, Architecture));
 }
예제 #13
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);
 }
예제 #14
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);
 }
예제 #15
0
 public void Setup()
 {
     this.sc = new ServiceContainer();
     this.mr = new MockRepository();
     var image = new LoadedImage(Address.SegPtr(0x0C00, 0), new byte[100]);
     this.program = new Program
     {
         Image = image,
         ImageMap = image.CreateImageMap()
     };
 }
예제 #16
0
 private void Given_Image(params byte[] bytes)
 {
     var image = new LoadedImage(Address.Ptr32(0x00400000), bytes);
     arch.Stub(a => a.CreateImageReader(image, null))
         .IgnoreArguments()
         .Return(new LeImageReader(image, image.BaseAddress));
     this.program = new Program
     {
         Image = image,
         ImageMap = image.CreateImageMap(),
         Architecture = arch
     };
 }
예제 #17
0
 public override Program Load(Address addrLoad)
 {
     ldr = CreateParser();
     uint ncmds = ldr.ParseHeader(addrLoad);
     ldr.ParseLoadCommands(ncmds);
     var image = new LoadedImage(addrLoad, RawImage);
     return new Program {
         Architecture = ldr.arch,
         Image = image,
         ImageMap = image.CreateImageMap(),
         Platform = new DefaultPlatform(Services, ldr.arch)
     };
 }
예제 #18
0
 private void Given_Program(byte [] bytes)
 {
     var arch = mr.Stub<IProcessorArchitecture>();
     arch.Stub(a => a.ReadCodeAddress(0, null, null)).IgnoreArguments()
         .Do(new Func<int, ImageReader, ProcessorState, Address>(
             (s, r, st) => Address.Ptr32(r.ReadLeUInt32())));
     var image = new LoadedImage(Address.Ptr32(0x00010000), bytes);
     this.program = new Program
     {
         Architecture = arch,
         Image = image,
         ImageMap = image.CreateImageMap(),
     };
 }
예제 #19
0
파일: HunkLoader.cs 프로젝트: melbcat/reko
        public override Program Load(Address addrLoad)
        {
            arch = new M68kArchitecture();
            var imgReader = new BeImageReader(RawImage, 0);
            var parse = new HunkFileParser(imgReader, false);
            this.hunkFile = parse.Parse();
            BuildSegments();
            this.firstCodeHunk = parse.FindFirstCodeHunk();
            var image = new LoadedImage(addrLoad, RelocateBytes(addrLoad));

            return new Program(
                image,
                image.CreateImageMap(),
                arch,
                new AmigaOSPlatform(Services, arch));
        }
 public void Setup()
 {
     var image = new LoadedImage(Address.Ptr32(0x00400000), new byte[1024]);
     var arch = new FakeArchitecture();
     program = new Program
     {
         Architecture = arch,
         Image = image,
         ImageMap = image.CreateImageMap(),
         Platform = new DefaultPlatform(null, arch)
     };
     store = program.TypeStore;
     factory = program.TypeFactory;
     point = new StructureType(null, 0);
     point.Fields.Add(0, PrimitiveType.Word32, null);
     point.Fields.Add(4, PrimitiveType.Word32, null);
 }
예제 #21
0
        public override Program Load(Address addrLoad)
        {
            var cfgSvc = Services.RequireService<IConfigurationService>();
            arch = (M68kArchitecture) cfgSvc.GetArchitecture("m68k");
            var imgReader = new BeImageReader(RawImage, 0);
            var parse = new HunkFileParser(imgReader, false);
            this.hunkFile = parse.Parse();
            BuildSegments();
            this.firstCodeHunk = parse.FindFirstCodeHunk();
            var image = new LoadedImage(addrLoad, RelocateBytes(addrLoad));

            return new Program(
                image,
                image.CreateImageMap(),
                arch,
                cfgSvc.GetEnvironment("amigaOS").Load(Services, arch));
        }
예제 #22
0
        public override Program Load(Address addrLoad)
        {
            if (!ParseDMKHeader())
                return null;

            var tracks = BuildTrackList(TrackLength);
            var bytes = tracks.SelectMany(t => t.Sectors)
                .SelectMany(s => s.GetData())
                .ToArray();
            var image = new LoadedImage(addrLoad, bytes);
            return new Program
            {
                Architecture = new Z80ProcessorArchitecture(),
                Image = image,
                ImageMap = image.CreateImageMap(),
            };
        }
예제 #23
0
        private void LoadFromFile(TextReader rdr)
        {
            var arch = GetArchitecture(ReadLine(rdr).Trim());
            for (; ; )
            {
                var line = ReadLine(rdr);
                if (line == null)
                    break;
                ProcessLine(line);
            }
            var img = new LoadedImage(addrStart, memStm.ToArray());
            results = new Program(
                img,
                img.CreateImageMap(),
                arch,
                new DefaultPlatform(Services, arch));

        }
예제 #24
0
        public void Setup()
        {
            arch = new IntelArchitecture(ProcessorMode.Real);
            var image = new LoadedImage(Address.Ptr32(0x10000), new byte[4]);
            var prog = new Program(
                image,
                image.CreateImageMap(),
                arch,
                null);
            var procAddress = Address.Ptr32(0x10000000);
            instr = new X86Instruction(Opcode.nop, PrimitiveType.Word16, PrimitiveType.Word16)
            {
                Address = procAddress,
            };

            proc = Procedure.Create(procAddress, arch.CreateFrame());
            orw = new OperandRewriter16(arch, proc.Frame, new FakeRewriterHost(prog));
            state = (X86State)arch.CreateProcessorState();
        }
예제 #25
0
 private void GenerateSimulatedProgram()
 {
     var row = Enumerable.Range(0, 0x100).Select(b => (byte)b).ToArray();
     var image = new LoadedImage(
             Address.Ptr32(0x0010000),
             Enumerable.Repeat(
                 row,
                 40).SelectMany(r => r).ToArray());
     var imageMap = image.CreateImageMap();
     var addrCode = Address.Ptr32(0x0010008);
     var addrData = Address.Ptr32(0x001001A);
     imageMap.AddItemWithSize(addrCode, new ImageMapBlock { Address = addrCode, Size = 0x0E });
     imageMap.AddItemWithSize(addrData, new ImageMapItem { Address = addrData, DataType = PrimitiveType.Byte, Size = 0x0E });
     var arch = dlg.Services.RequireService<IConfigurationService>().GetArchitecture("x86-protected-32");
     this.program = new Program
     {
         Image = image,
         ImageMap = imageMap,
         Architecture = arch,
     };
 }
예제 #26
0
파일: D64Loader.cs 프로젝트: melbcat/reko
 /// <summary>
 /// Load a Basic PRG.
 /// </summary>
 /// <param name="imageBytes"></param>
 /// <returns></returns>
 private Program LoadPrg(byte[] imageBytes)
 {
     var stm = new MemoryStream();
     ushort preferredAddress = LoadedImage.ReadLeUInt16(imageBytes, 0);
     ushort alignedAddress = (ushort) (preferredAddress & ~0xF);
     int pad = preferredAddress - alignedAddress;
     while (pad-- > 0)
         stm.WriteByte(0);
     stm.Write(imageBytes, 2, imageBytes.Length - 2);
     var loadedBytes = stm.ToArray();
     var image = new LoadedImage(
         Address.Ptr16(alignedAddress),
         loadedBytes);
     var rdr = new C64BasicReader(image, 0x0801);
     var prog = rdr.ToSortedList(line => (ushort)line.Address.ToLinear(), line => line);
     var arch = new C64Basic(prog);
     image = new LoadedImage(
         Address.Ptr16(prog.Keys[0]),
         new byte[0xFFFF]);
     var program = new Program(
         image,
         image.CreateImageMap(),
         arch,
         new C64Platform(Services, null));
     program.EntryPoints.Add(new EntryPoint(image.BaseAddress, arch.CreateProcessorState()));
     return program;
 }
예제 #27
0
파일: D64Loader.cs 프로젝트: melbcat/reko
 private Program LoadImage(Address addrPreferred, D64FileEntry selectedFile)
 {
     byte[] imageBytes = selectedFile.GetBytes();
     switch (selectedFile.FileType & FileType.FileTypeMask)
     {
     case FileType.PRG:
         return LoadPrg(imageBytes);
     case FileType.SEQ:
         var image = new LoadedImage(addrPreferred, imageBytes);
         var arch = new Mos6502ProcessorArchitecture();
         return new Program(
             image,
             image.CreateImageMap(),
             arch,
             new DefaultPlatform(Services, arch));
     default:
         throw new NotImplementedException();
     }
 }
예제 #28
0
파일: D64Loader.cs 프로젝트: melbcat/reko
 public override Program Load(Address addrLoad)
 {
     List<ArchiveDirectoryEntry> entries = LoadDiskDirectory();
     IArchiveBrowserService abSvc = Services.GetService<IArchiveBrowserService>();
     if (abSvc != null)
     {
         var selectedFile = abSvc.UserSelectFileFromArchive(entries) as D64FileEntry;
         if (selectedFile != null)
         {
             this.program = LoadImage(addrLoad, selectedFile);
             return program;
         }
     }
     var arch = new Mos6502ProcessorArchitecture();
     var image = new LoadedImage(Address.Ptr16(0), RawImage);
     return new Program {
         Image = image,
         ImageMap = image.CreateImageMap(),
         Architecture = arch,
         Platform = new DefaultPlatform(Services, arch)
     };
 }
예제 #29
0
 private TestScanner CreateScanner(uint startAddress, int imageSize)
 {
     var image = new LoadedImage(Address.Ptr32(startAddress), new byte[imageSize]);
     program = new Program(
         image,
         image.CreateImageMap(),
         arch,
         new FakePlatform(null, arch));
     return new TestScanner(
         program,
         callSigs,
         importResolver,
         sc);
 }
예제 #30
0
 private void Given_Program(Address address)
 {
     var image = new LoadedImage(address, new byte[1]);
     var imageMap = image.CreateImageMap();
     this.program = new Program
     {
         Architecture = arch,
         Image = image,
         ImageMap = imageMap,
         Platform = new FakePlatform(null, arch)
     };
 }