private void Given_Omf(RecordType rt, ushort length, params Action [] mutators) { writer.WriteByte((byte)rt); writer.WriteLeUInt16(length); foreach (var mutator in mutators) { mutator(); } }
private void Given_Pe32Header(uint uAddrBase) { writer.Position = RvaPeHdr; writer.WriteBytes(new byte[] { 0x50, 0x45, 0, 0 }); var p = writer.Position; writer.WriteLeInt16(0x14C); writer.WriteLeInt16(0); // sections. writer.WriteLeInt32(0); // timestamp. writer.WriteLeInt32(0); // COFF symbol writer.WriteLeInt32(0); // #of symbols var rvaOptionalHeaderSize = writer.Position; writer.WriteLeInt16(0); // optionalHeaderSize writer.WriteLeInt16(0); // short fileFlags // Optional header var rvaOptHdr = writer.Position; writer.WriteLeInt16(0x010B); writer.WriteLeInt16(0); // linker writer.WriteLeInt32(0); // size of code writer.WriteLeInt32(0); // size of init data writer.WriteLeInt32(0); // size of uninit data writer.WriteLeUInt32(RvaText); // RVA of entry point. writer.WriteLeUInt32(RvaText); // RVA of base of code. writer.WriteLeUInt32(RvaData); // RVA of base of data. writer.WriteLeUInt32(uAddrBase); // preferred image base. writer.WriteLeUInt32(0); // section alignment writer.WriteLeUInt32(0); // file alignment writer.WriteLeUInt32(0); // OS version writer.WriteLeUInt32(0); // image version writer.WriteLeUInt32(0); // subsystem version writer.WriteLeUInt32(0); // Win32 version writer.WriteLeUInt32(0); // size of image writer.WriteLeUInt32(0); // size of headers writer.WriteLeUInt32(0); // checksum writer.WriteLeUInt16(0); // subsystem writer.WriteLeUInt16(0); // DLL characeristics writer.WriteLeUInt32(0); // stack reserve writer.WriteLeUInt32(0); // stack commit writer.WriteLeUInt32(0); // heap reserve writer.WriteLeUInt32(0); // heap commit writer.WriteLeUInt32(0); // loader flags writer.WriteLeUInt32(2); // number of data directory entries rvaDirectories = (int)writer.Position; writer.Position = rvaDirectories + 2 * 12; var optHdrSize = writer.Position - rvaOptHdr; var rvaSections = writer.Position; writer.Position = rvaOptionalHeaderSize; writer.WriteLeInt16((short)optHdrSize); writer.Position = rvaSections; }
private void Given_MzExeProgram(uint size) { this.writer = new LeImageWriter(); writer.WriteBytes(0, size); var pos = writer.Position; writer.Position = 0; writer.WriteString("MZ", Encoding.ASCII); uint cPages = size / ExeImageLoader.CbPageSize; uint cbLastPage = size % ExeImageLoader.CbPageSize; if (cbLastPage > 0) { ++cPages; } writer.WriteLeUInt16((ushort)cbLastPage); writer.WriteLeUInt16((ushort)cPages); writer.Position = pos; }
/// <summary> /// Create a segment for the MS-DOS program segment prefix (PSP). /// </summary> /// <param name="addrPsp">The address of the PSP</param> /// <param name="segMemTop">The segment address (paragraph) of the first byte /// beyond the image.</param> /// <returns> /// An <see cref="ImageSegment"/> that can be added to a <see cref="SegmentMap"/>. /// </returns> private ImageSegment MakeProgramSegmentPrefix(Address addrPsp, ushort segMemTop) { var mem = new ByteMemoryArea(addrPsp, new byte[0x100]); var w = new LeImageWriter(mem, 0); w.WriteByte(0xCD); w.WriteByte(0x20); w.WriteLeUInt16(segMemTop); // Some unpackers rely on this value. return(new ImageSegment("PSP", mem, AccessMode.ReadWriteExecute)); }
/// <summary> /// Establishes a disassembler instance for further tests. /// </summary> /// <param name="instrs"></param> private void Given_Instructions(params ushort[] instrs) { var w = new LeImageWriter(); foreach (var instr in instrs) { w.WriteLeUInt16(instr); } var image = new MemoryArea(Address.Ptr32(0x00100000), w.ToArray()); var arch = CreateArchitecture(); this.dasm = CreateDisassembler(arch, image.CreateLeReader(0)); }
private MachineInstruction RunTest(params ushort[] words) { var bytes = new byte[words.Length * 2]; LeImageWriter writer = new LeImageWriter(bytes); foreach (ushort word in words) { writer.WriteLeUInt16(word); } var image = new MemoryArea(Address.Ptr16(0x200), bytes); var rdr = new LeImageReader(image, 0); var arch = new Pdp11Architecture(new ServiceContainer(), "pdp11"); var dasm = new Pdp11Disassembler(rdr, arch); return(dasm.First()); }
private MachineInstruction[] DisassembleWords(params ushort[] words) { var bytes = new byte[words.Length * 2]; LeImageWriter writer = new LeImageWriter(bytes); foreach (ushort word in words) { writer.WriteLeUInt16(word); } var image = new MemoryArea(Address.Ptr16(0x200), bytes); var rdr = new LeImageReader(image, 0); var arch = new Pdp11Architecture(); var dasm = new Pdp11Disassembler(rdr, arch); return(dasm.ToArray()); }
private byte[] CreateMsdosHeader() { ImageWriter stm = new LeImageWriter(new byte[16]); stm.WriteByte(0x4D); // MZ stm.WriteByte(0x5A); stm.WriteBytes(0xCC, 4); stm.WriteLeUInt16(0x0090); stm.WriteBytes(0xCC, 0x12); stm.WriteByte(0x00); stm.WriteByte(0x00); stm.WriteByte(0x05); stm.WriteByte(0x21); stm.WriteString("PKLITE", Encoding.ASCII); stm.WriteBytes(0xCC, 0x0C); return(stm.Bytes); }
protected MachineInstruction Disassemble16(params ushort[] instrs) { var image = new MemoryArea(Address.Ptr32(0x00100000), new byte[4]); LeImageWriter w = new LeImageWriter(image.Bytes); foreach (var instr in instrs) { w.WriteLeUInt16(instr); } var arch = CreateArchitecture(); var dasm = CreateDisassembler(arch, image.CreateLeReader(0)); Assert.IsTrue(dasm.MoveNext()); var armInstr = dasm.Current; dasm.Dispose(); return(armInstr); }
private void Given_Bundle(byte nEntries, byte iSeg, params BundleEntry[] entries) { writer.WriteByte(nEntries); writer.WriteByte(iSeg); foreach (var entry in entries) { writer.WriteByte(entry.flags); if (entry.flags == 0) { break; } if (entry.iSeg != 0) { writer.WriteBeUInt16(0xCD3F); // INT 3F [sic] writer.WriteByte(entry.iSeg); } writer.WriteLeUInt16(entry.offset); } }
public void Given_DebugHeader(short nSymbols, short nTypes) { writer.WriteLeUInt16(SymbolLoader.MagicNumber); // magic_number writer.WriteLeUInt16(0); // version_id // Remember this position so we can backpatch later. this.offNames = writer.Position; writer.WriteLeUInt32(0); // names writer.WriteLeUInt16(0); // names_count writer.WriteLeInt16(nTypes); // types_count writer.WriteLeUInt16(0); // members_count writer.WriteLeInt16(nSymbols); // symbols_count writer.WriteLeUInt16(0); // globals_count writer.WriteLeUInt16(0); // modules_count writer.WriteLeUInt16(0); // locals_count writer.WriteLeUInt16(0); // scopes_count writer.WriteLeUInt16(0); // lines_count writer.WriteLeUInt16(0); // source_count writer.WriteLeUInt16(0); // segment_count writer.WriteLeUInt16(0); // correlation_count writer.WriteUInt32(0); // image_size writer.WriteUInt32(0); // /*void far * */debugger_hook writer.WriteByte(0); // program_flags writer.WriteLeUInt16(0); // stringsegoffset writer.WriteLeUInt16(0); // data_count writer.WriteByte(0); // filler writer.WriteLeUInt16(0x00); // extension_size }