public override Program LoadProgram(Address?addrLoad) { addrLoad ??= PreferredBaseAddress; 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 platform = cfgSvc.GetEnvironment("amigaOS").Load(Services, arch); var imageMap = platform.CreateAbsoluteMemoryMap(); var mem = new ByteMemoryArea(addrLoad, RelocateBytes(addrLoad)); var program = new Program( new SegmentMap( mem.BaseAddress, new ImageSegment( "code", mem, AccessMode.ReadWriteExecute)), arch, platform); var sym = ImageSymbol.Procedure(program.Architecture, addrLoad, state: arch.CreateProcessorState()); program.ImageSymbols[sym.Address] = sym; program.EntryPoints[sym.Address] = sym; return(program); }
public void Setup() { this.mr = new MockRepository(); this.fsSvc = mr.StrictMock <IFileSystemService>(); this.tllSvc = mr.Stub <ITypeLibraryLoaderService>(); this.services = mr.StrictMock <IServiceProvider>(); var cfgSvc = mr.Stub <IConfigurationService>(); var env = mr.Stub <OperatingEnvironment>(); this.arch = new M68kArchitecture("m68k"); this.rtls = new List <RtlInstruction>(); this.m = new RtlEmitter(rtls); cfgSvc.Stub(c => c.GetEnvironment("amigaOS")).Return(env); env.Stub(e => e.TypeLibraries).Return(new List <ITypeLibraryElement>()); env.Stub(e => e.CharacteristicsLibraries).Return(new List <ITypeLibraryElement>()); env.Stub(e => e.Options).Return(new Dictionary <string, object> { { "versionDependentLibraries", new Dictionary <string, object> { { "33", new List <object> { "exec_v33", "dos_v33" } }, { "34", new List <object> { "exec_v34", "dos_v34" } }, } } }); this.services.Stub(s => s.GetService(typeof(IConfigurationService))).Return(cfgSvc); this.services.Stub(s => s.GetService(typeof(IFileSystemService))).Return(fsSvc); this.services.Stub(s => s.GetService(typeof(ITypeLibraryLoaderService))).Return(tllSvc); this.binder = new Frame(arch.FramePointerType); }
public void Sgrom_LoadImage() { var sc = new ServiceContainer(); var cfgSvc = new Mock <IConfigurationService>(); var openv = new Mock <PlatformDefinition>(); var listener = new Mock <DecompilerEventListener>(); var arch = new M68kArchitecture(sc, "m68k"); var platform = new SegaGenesisPlatform(sc, arch); cfgSvc.Setup(c => c.GetArchitecture("m68k")).Returns(arch); cfgSvc.Setup(c => c.GetEnvironment("sega-genesis")).Returns(openv.Object); openv.Setup(o => o.Load(sc, arch)).Returns(platform); sc.AddService <IConfigurationService>(cfgSvc.Object); sc.AddService <DecompilerEventListener>(listener.Object); Given_AbsoluteMemoryMap(platform); var rawBytes = new byte[0x300]; var sgrom = new RomLoader(sc, "foo.bin", rawBytes); var program = sgrom.Load(Address.Ptr32(0)); var romSegment = program.SegmentMap.Segments.Values.First(); var bmem = (ByteMemoryArea)romSegment.MemoryArea; Assert.IsNotNull(romSegment.MemoryArea, "ROM image should have been loaded into first segment"); Assert.AreSame(rawBytes, bmem.Bytes, "ROM image should have been loaded into first segment"); Assert.AreEqual(rawBytes.Length, romSegment.ContentSize); var ramSegment = program.SegmentMap.Segments.Values.First(s => s.Name == ".data"); Assert.IsNotNull(ramSegment.MemoryArea, "RAM segment should have a MemoryArea"); }
public void Sgrom_LoadImage() { var sc = new ServiceContainer(); var cfgSvc = mr.Stub <IConfigurationService>(); var openv = mr.Stub <OperatingEnvironment>(); var diagSvc = mr.StrictMock <IDiagnosticsService>(); var arch = new M68kArchitecture("m68k"); var platform = new SegaGenesisPlatform(sc, arch); cfgSvc.Expect(c => c.GetArchitecture("m68k")).Return(arch); cfgSvc.Expect(c => c.GetEnvironment("sega-genesis")).Return(openv); openv.Expect(o => o.Load(sc, arch)).Return(platform); sc.AddService <IConfigurationService>(cfgSvc); sc.AddService <IDiagnosticsService>(diagSvc); Given_AbsoluteMemoryMap(platform); mr.ReplayAll(); var rawBytes = new byte[0x300]; var sgrom = new RomLoader(sc, "foo.bin", rawBytes); var program = sgrom.Load(Address.Ptr32(0)); var romSegment = program.SegmentMap.Segments.Values.First(); Assert.IsNotNull(romSegment.MemoryArea, "ROM image should have been loaded into first segment"); Assert.AreSame(rawBytes, romSegment.MemoryArea.Bytes, "ROM image should have been loaded into first segment"); Assert.AreEqual(rawBytes.Length, romSegment.ContentSize); var ramSegment = program.SegmentMap.Segments.Values.First(s => s.Name == ".data"); Assert.IsNotNull(ramSegment.MemoryArea, "RAM segment should have a MemoryArea"); }
public void Setup() { this.fsSvc = new Mock <IFileSystemService>(); this.tllSvc = new Mock <ITypeLibraryLoaderService>(); this.services = new ServiceContainer(); var cfgSvc = new Mock <IConfigurationService>(); var env = new Mock <OperatingEnvironment>(); this.arch = new M68kArchitecture("m68k"); this.rtls = new List <RtlInstruction>(); this.m = new RtlEmitter(rtls); cfgSvc.Setup(c => c.GetEnvironment("amigaOS")).Returns(env.Object); env.Setup(e => e.TypeLibraries).Returns(new List <ITypeLibraryElement>()); env.Setup(e => e.CharacteristicsLibraries).Returns(new List <ITypeLibraryElement>()); env.Setup(e => e.Options).Returns(new Dictionary <string, object> { { "versionDependentLibraries", new Dictionary <string, object> { { "33", new List <object> { "exec_v33", "dos_v33" } }, { "34", new List <object> { "exec_v34", "dos_v34" } }, } } }); this.services.AddService(typeof(IConfigurationService), cfgSvc.Object); this.services.AddService(typeof(IFileSystemService), fsSvc.Object); this.services.AddService(typeof(ITypeLibraryLoaderService), tllSvc.Object); this.binder = new Frame(arch.FramePointerType); }
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 FuncsFileParser(M68kArchitecture arch, TextReader streamReader) { this.arch = arch; this.streamReader = streamReader; this.FunctionsByLibBaseOffset = new Dictionary <int, AmigaSystemFunction>(); this.lex = null !; }
public void Setup() { var sc = new ServiceContainer(); sc.AddService <ITestGenerationService>(new UnitTestGenerationService(sc)); arch = new M68kArchitecture(sc, "m68k"); asm = new M68kAssembler(arch, Address.Ptr32(0x00010000), new List <ImageSymbol>()); }
public M68kAssembler(M68kArchitecture arch, Address addrBase, List <ImageSymbol> entryPoints) { this.arch = arch; this.BaseAddress = addrBase; this.entryPoints = new List <ImageSymbol>(); this.Emitter = new Emitter(); this.constants = new List <ushort>(); this.Symbols = new SymbolTable(); }
public void Setup() { this.mr = new MockRepository(); this.fsSvc = mr.StrictMock <IFileSystemService>(); this.services = mr.StrictMock <IServiceProvider>(); this.arch = new M68kArchitecture(); this.rtls = new List <RtlInstruction>(); this.m = new RtlEmitter(rtls); this.services.Stub(s => s.GetService(typeof(IFileSystemService))).Return(fsSvc); this.frame = new Frame(arch.FramePointerType); }
public void Ahl_ParseSimpleDef_voidfn() { var arch = new M68kArchitecture(); var platform = new AmigaOSPlatform(null, arch); var ahl = new AmigaHeaderLoader(null, "", Encoding.UTF8.GetBytes( "[[reko::amiga_function_vector(ExecLibrary, -432)]] " + "void FrabDevice([[reko::arg(register, \"A1\")]] struct Device * device);")); var Q = ahl.Load(platform, new TypeLibrary()); var svc = ahl.SystemServices[-432]; Assert.IsNull(svc.Signature.ReturnValue); }
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); }
private void Given_Relocator() { var arch = new M68kArchitecture("m68k"); var platform = new MacOSClassic(null, arch) { A5World = a5world, A5Offset = 2048, }; var rdr = new BeImageReader(platform.A5World.MemoryArea, 0); this.relocator = new A5Relocator(platform, rdr, 1024); }
public void Ahl_ParseSimpleDef_voidfn() { var sc = new ServiceContainer(); var arch = new M68kArchitecture(sc, "m68k", new Dictionary <string, object>()); var platform = new AmigaOSPlatform(sc, arch); var ahl = new AmigaHeaderLoader(sc, "", Encoding.UTF8.GetBytes( "[[reko::amiga_function_vector(ExecLibrary, -432)]] " + "void FrabDevice([[reko::arg(register, \"A1\")]] struct Device * device);")); var Q = ahl.Load(platform, new TypeLibrary()); var svc = ahl.SystemServices[-432]; Assert.IsInstanceOf <VoidType>(svc.Signature.ReturnValue.DataType); }
public void Ahl_ParseSimpleDef() { var arch = new M68kArchitecture(); var platform = new AmigaOSPlatform(null, arch); var ahl = new AmigaHeaderLoader(null, "", Encoding.UTF8.GetBytes( "[[reko::amiga_function_vector(ExecLibrary, -432)]] [[reko::returns(register,\"A0\")]] " + "void * FlobDevice([[reko::arg(register, \"A1\")]] struct Device * device);")); var Q = ahl.Load(platform, new TypeLibrary()); var svc = ahl.SystemServices[-432]; Assert.AreEqual("a0", svc.Signature.ReturnValue.Storage.ToString()); Assert.AreEqual("a1", svc.Signature.Parameters[0].Storage.ToString()); }
private void BuildTest32(Address addrBase, params byte[] bytes) { arch = new M68kArchitecture(sc, "m68k"); var mem = new MemoryArea(addrBase, bytes); program = new Program( new SegmentMap( mem.BaseAddress, new ImageSegment( "code", mem, AccessMode.ReadWriteExecute)), arch, new DefaultPlatform(null, arch)); RunTest(addrBase); }
private void Given_Relocator() { var sc = new ServiceContainer(); var arch = new M68kArchitecture(sc, "m68k", new Dictionary <string, object>()); var platform = new MacOSClassic(sc, arch) { A5World = a5world, A5Offset = 2048, }; var mem = (ByteMemoryArea)platform.A5World.MemoryArea; var rdr = new BeImageReader(mem, 0); this.relocator = new A5Relocator(platform, rdr, 1024); }
public void Ahl_ParseSimpleDef() { var sc = new ServiceContainer(); var arch = new M68kArchitecture(sc, "m68k", new Dictionary <string, object>()); var platform = new AmigaOSPlatform(sc, arch); var ahl = new AmigaHeaderLoader(sc, ImageLocation.FromUri("file:x"), Encoding.UTF8.GetBytes( "[[reko::amiga_function_vector(ExecLibrary, -432)]] [[reko::returns(register,\"A0\")]] " + "void * FlobDevice([[reko::arg(register, \"A1\")]] struct Device * device);")); ahl.Load(platform, new TypeLibrary()); var svc = ahl.SystemServices[-432]; Assert.AreEqual("a0", svc.Signature.ReturnValue.Storage.ToString()); Assert.AreEqual("a1", svc.Signature.Parameters[0].Storage.ToString()); }
public void ReadHeader() { var sc = new ServiceContainer(); var arch = new M68kArchitecture(sc, "m68k", new Dictionary <string, object>()); var macOS = new MacOSClassic(sc, arch); MemoryStream stm = new MemoryStream(); WriteBeUint32(stm, 0x00000010); WriteBeUint32(stm, 0x00000020); WriteBeUint32(stm, 0x00000010); WriteBeUint32(stm, 0x00000010); stm.Write(Encoding.ASCII.GetBytes("Hello world!Hello world!"), 0, 0x10); stm.Write(new byte[0x10], 0, 0x10); // copy of header WriteBeUint32(stm, 0); // next resource map. WriteBeUint16(stm, 0); WriteBeUint16(stm, 0); WriteBeUint16(stm, 0x1C); WriteBeUint16(stm, 0); WriteBeUint16(stm, 0); WriteAsciiString(stm, "CODE"); // 001E: type list WriteBeUint16(stm, 0); WriteBeUint16(stm, 8); WriteBeUint16(stm, 0); // resource ID WriteBeUint16(stm, 0x0C); stm.WriteByte(0); stm.WriteByte(0); stm.WriteByte(0); stm.WriteByte(0x10); WriteBeUint32(stm, 0); stm.WriteByte(4); WriteAsciiString(stm, "Test"); ResourceFork rsrc = new ResourceFork(macOS, stm.GetBuffer()); Assert.AreEqual(1, rsrc.ResourceTypes.Count); IEnumerator <ResourceFork.ResourceType> ert = rsrc.ResourceTypes.GetEnumerator(); Assert.IsTrue(ert.MoveNext()); ResourceFork.ResourceType rt = ert.Current; Assert.AreEqual("CODE", rt.Name); Assert.AreEqual(1, rt.References.Count); }
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 Program Assemble(Address baseAddress, TextReader rdr) { this.addrBase = baseAddress; this.lexer = new Lexer(rdr); this.arch = new M68kArchitecture("m68k"); asm = new M68kAssembler(arch, addrBase, entryPoints); this.emitter = asm.Emitter; // Assemblers are strongly line-oriented. while (lexer.PeekToken().Type != TokenType.EOFile) { ProcessLine(); } asm.ReportUnresolvedSymbols(); //addrStart = addrBase; return(asm.GetImage()); }
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))); }
public void Setup() { this.mr = new MockRepository(); this.fsSvc = mr.StrictMock <IFileSystemService>(); this.tllSvc = mr.Stub <ITypeLibraryLoaderService>(); this.services = mr.StrictMock <IServiceProvider>(); var cfgSvc = mr.Stub <IConfigurationService>(); var env = mr.Stub <OperatingEnvironment>(); this.arch = new M68kArchitecture(); this.rtls = new List <RtlInstruction>(); this.m = new RtlEmitter(rtls); cfgSvc.Stub(c => c.GetEnvironment("amigaOS")).Return(env); env.Stub(e => e.TypeLibraries).Return(new List <ITypeLibraryElement>()); env.Stub(e => e.CharacteristicsLibraries).Return(new List <ITypeLibraryElement>()); this.services.Stub(s => s.GetService(typeof(IConfigurationService))).Return(cfgSvc); this.services.Stub(s => s.GetService(typeof(IFileSystemService))).Return(fsSvc); this.services.Stub(s => s.GetService(typeof(ITypeLibraryLoaderService))).Return(tllSvc); this.frame = new Frame(arch.FramePointerType); }
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 mem = new MemoryArea(addrLoad, RelocateBytes(addrLoad)); return(new Program( new ImageMap( mem.BaseAddress, new ImageSegment( "code", mem, AccessMode.ReadWriteExecute)), arch, cfgSvc.GetEnvironment("amigaOS").Load(Services, arch))); }
private void BuildTest32(Action <M68kAssembler> asmProg) { arch = new M68kArchitecture(sc, "m68k"); BuildTest(Address.Ptr32(0x00100000), new DefaultPlatform(sc, arch), asmProg); }
public void Setup() { this.w = new BeImageWriter(); this.arch = new M68kArchitecture(new ServiceContainer(), "m68k", new Dictionary <string, object>()); }
public M68kPropertiesInteractor(M68kArchitecture arch) { this.arch = arch; }
public HunkLoader(IServiceProvider services, string filename, byte[] imgRaw) : base(services, filename, imgRaw) { this.arch = null !; this.hunkFile = null !; }
public void Setup() { arch = new M68kArchitecture(); state = new M68kState(arch); }
public PascalCallingConventionTests() { this.arch = new M68kArchitecture(); }