public HunkFileParser(BeImageReader f, bool? v37_compat = null) { this.f = f; this.v37_compat = v37_compat; // Commodore famously used ISO 8859-1 for the Amiga. Different // national variants may need to override this. this.textEncoding = Encoding.GetEncoding("ISO_8859-1"); this.hunk_file = new HunkFile(); this.hunks = hunk_file.hunks; }
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 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 HunkShow(HunkFile hunk_file, bool show_relocs = false, bool show_debug = false, bool disassemble = false, uint disassemble_start = 0, bool hexdump = false, bool brief = false, bool use_objdump = false, string cpu = "68000") { this.hunk_file = hunk_file; // clone file refs this.header = hunk_file.header; this.segments = hunk_file.segments; this.overlay = hunk_file.overlay; this.overlay_headers = hunk_file.overlay_headers; this.overlay_segments = hunk_file.overlay_segments; this.libs = hunk_file.libs; this.units = hunk_file.units; this.show_relocs = show_relocs; this.show_debug = show_debug; this.disassemble = disassemble; this.disassemble_start = disassemble_start; this.use_objdump = use_objdump; this.cpu = cpu; this.hexdump = hexdump; this.brief = brief; }
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 platform = cfgSvc.GetEnvironment("amigaOS").Load(Services, arch); var imageMap = platform.CreateAbsoluteMemoryMap(); var mem = new MemoryArea(addrLoad, RelocateBytes(addrLoad)); return new Program( new SegmentMap( mem.BaseAddress, new ImageSegment( "code", mem, AccessMode.ReadWriteExecute)), arch, platform); }
public object handle_file(string path, HunkFile hunk_file) { bool ok = true; Console.WriteLine(path); // if verbose then print block structure if (this.args["--verbose"].IsTrue) { Console.WriteLine(); //Console.WriteLine(" hunks: ", hunk_file.get_hunk_summary()); if (args["--dump"].IsTrue) { //print_pretty(hunk_file.hunks); } Console.WriteLine(" type: "); // build segments from hunks } Console.WriteLine(hunk_file.type.ToString()); // if verbose then print hunk structure if (this.args["--verbose"].IsTrue) { //Console.WriteLine(); //Console.WriteLine(" segments: ", hunk_file.get_segment_summary()); //Console.WriteLine(" overlays: ", hunk_file.get_overlay_segment_summary()); //Console.WriteLine(" libs: ", hunk_file.get_libs_summary()); //Console.WriteLine(" units: ", hunk_file.get_units_summary()); //if (args.dump) //{ // print_pretty(hunk_file.hunks); //} } else { Console.WriteLine(); // do special processing on hunk file for command } ok = this.handle_hunk_file(path, hunk_file); return ok; }
// Generate signatures to Output. public override bool handle_hunk_file(string s, HunkFile hunk_file) { if (hunk_file.type == FileType.TYPE_UNIT) { foreach (var unit in hunk_file.units) { foreach (var segment in unit.segments) { var main = segment[0]; if (main.HunkType == HunkType.HUNK_CODE && main.Data != null && main.Data.Length != 0) { GenerateSignature(segment); } } } } if (hunk_file.type == FileType.TYPE_LIB) { foreach (var lib in hunk_file.libs) { foreach (var unit in lib.units) { foreach (var segment in unit.segments) { var main = segment[0]; if (main.HunkType == HunkType.HUNK_CODE && main.Data != null && main.Data.Length != 0) { GenerateSignature(segment); } } } } } return true; }
public HunkLoader(IServiceProvider services, string filename, byte[] imgRaw) : base(services, filename, imgRaw) { this.arch = null !; this.hunkFile = null !; }
public void hunktool_signature() { // # 48 UNIT //#3 CODE size 00000000 alloc size 00000028 file header @ 'romhunks' // 48 E7 00 3A 26 6F 00 14 20 6F 00 18 43 EF 00 1C // 45 FA 00 12 2C 79 00 00 00 00 4E AE 00 00 4C DF // 5C 00 4E 75 16 C0 4E 75 // ext ext // 00000000 _sprintf def // 00000016 _AbsExecBase absref32 // 0000001C _LVORawDoFmt relref16 // symbol symbol // 00000000 _sprintf // 00000024 stuffChar var unit = new Unit { segments = new List<List<Hunk>> { new List<Hunk> { new Hunk { HunkType = HunkType.HUNK_CODE, Data = MakeBytes( "48 E7 00 3A 26 6F 00 14 20 6F 00 18 43 EF 00 1C" + "45 FA 00 12 2C 79 00 00 00 00 4E AE 00 00 4C DF" + "5C 00 4E 75 16 C0 4E 75"), }, new ExtHunk { ext_def = new List<ExtObject> { new ExtObject { def = 0, type = ExtType.EXT_DEF, name = "_sprintf" } }, ext_ref = new List<ExtObject> { new ExtObject {type = ExtType.EXT_ABSREF32, name= "_AbsExecBase", refs = new List<uint> { 0x16 } }, new ExtObject {type = ExtType.EXT_RELREF16, name= "_LVORawDoFmt", refs = new List<uint> { 0x1C } } } } } } }; var file = new HunkFile { type = FileType.TYPE_UNIT, units = new List<Unit> { unit } }; var sw = new StringWriter(); var segs = new SignatureGenerator(new Dictionary<string, ValueObject>()); segs.Output = sw; segs.handle_hunk_file("foo.lib", file); var sGen = sw.ToString(); var sExp = "48E7003A266F0014206F001843EF001C45FA00122C79........4EAE....4CDF _sprintf" + nl; if (sExp != sGen) Debug.Print(sGen); Assert.AreEqual(sExp, sGen); }
public HunkRelocator(HunkFile hunk_file) { this.hunk_file = hunk_file; }
public HunkLoader(IServiceProvider services, ImageLocation imageLocation, byte[] imgRaw) : base(services, imageLocation, imgRaw) { this.arch = null !; this.hunkFile = null !; }
public abstract bool handle_hunk_file(string s, HunkFile hunk_file);
public override bool handle_hunk_file(string path, HunkFile hunk_file) { // object base_addr; // object datas; // object rel; // if (hunk_file.type != FileType.TYPE_LOADSEG) // { // Console.WriteLine("ERROR: can only relocate LoadSeg()able files:", path); // return false; // } // var rel = new HunkRelocate(hunk_file, verbose = this.args.verbose); // // get sizes of all segments // var sizes = rel.get_sizes(); // // calc begin addrs for all segments // base_addr = this.args.base_address; // IEnumerable<uint> addrs = rel.get_seq_addrs(base_addr); // // relocate and return data of segments // datas = rel.relocate(addrs); // if (datas == null) // { // Console.WriteLine("ERROR: relocation failed:", path); // return false; // } // else // { // Console.WriteLine("Relocate to base address", base_addr); // Console.WriteLine("Bases: ", string.Join(" ", addrs.Select(x => String.Format("%06x", x), addrs))); // Console.WriteLine("Sizes: ", string.Join(" ", sizes.Select(x => String.Format("%06x", x), sizes))); // Console.WriteLine("Data: ", string.Join(" ", (map(x => String.Format("%06x", len(x)), datas))); // Console.WriteLine("Total: ", String.Format("%06x", rel.get_total_size())); // if (args["hexdump"].IsTrue) // { // foreach (var d in datas) // { // print_hex(d); // } // } // return true; // } //} return true; }
public override bool handle_hunk_file(string path, HunkFile hunk_file) { // verbose all hunk var hs = new HunkShow( hunk_file, show_relocs: args["--show-relocs"].IsTrue, show_debug: args["--show-debug"].IsTrue, disassemble: args["--disassemble"].IsTrue, disassemble_start: args["--disassemble-start"] != null ? UInt32.Parse( (string)args["--disassemble-start"].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture) : 0, use_objdump: args["--use-objdump"].IsTrue, cpu: args["--cpu"] != null ? (string)args["--cpu"].Value : "", hexdump: args["--hexdump"].IsTrue, brief: args["--brief"].IsTrue); hs.show_segments(); return true; }
public override bool handle_hunk_file(string path, HunkFile hunk_file) { // do nothing extra return true; // ----- Info ----- }