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 }
private void Given_UInt32_At(uint bits, uint addr) { var w = new LeImageWriter( bmem.Bytes, addr - (uint)bmem.BaseAddress.ToLinear()); w.WriteLeUInt32(bits); }
public void DynLink_LP32_weirdness() { var memText = new ByteMemoryArea(Address.Ptr64(0x00123400), new byte[100]); var memGot = new ByteMemoryArea(Address.Ptr64(0x00200000), new byte[100]); var wr = new LeImageWriter(memGot.Bytes); wr.WriteLeUInt32(0x00300000); wr.WriteLeUInt32(0x00300004); var arch = new FakeArchitecture64(new ServiceContainer()); //var arch = new Mock<IProcessorArchitecture>(); //arch.Setup(a => a.Endianness).Returns(EndianServices.Little); //arch.Setup(a => a.Name).Returns("fakeArch"); //arch.Setup(a => a.PointerType).Returns(PrimitiveType.Ptr64); //arch.Setup(a => a.MakeAddressFromConstant( // It.IsAny<Constant>(), // It.IsAny<bool>())).Returns((Constant c, bool b) => // Address.Ptr64(c.ToUInt32())); var project = new Project(); var sc = new ServiceContainer(); var program = new Program { Architecture = arch, Platform = new DefaultPlatform(sc, arch), SegmentMap = new SegmentMap(memGot.BaseAddress, new ImageSegment(".text", memText, AccessMode.ReadExecute), new ImageSegment(".got", memGot, AccessMode.Read)), }; program.ImportReferences.Add( Address.Ptr32(0x00200000), new NamedImportReference( Address.Ptr32(0x00200000), null, "my_global_var", SymbolType.Data)); var dynlink = new DynamicLinker(project, program, new FakeDecompilerEventListener()); var m = new ExpressionEmitter(); var addr = Address.Ptr64(0x00123000); var proc = program.EnsureProcedure(program.Architecture, addr, "foo_proc"); var block = new Block(proc, addr, "foo"); var stm = new Statement(0x00123400, new Store(m.Word64(0x00123400), Constant.Real32(1.0F)), block); var result = dynlink.ResolveToImportedValue(stm, Constant.Word32(0x00200000)); Assert.AreEqual("0x300000<64>", result.ToString()); //$LIT: pointer? p64? }
private void Given_Table_UInt32(Address address, params uint[] entries) { ImageSegment seg; program.SegmentMap.Segments.TryGetValue(address, out seg); var writer = new LeImageWriter(seg.MemoryArea, address); foreach (uint entry in entries) { writer.WriteLeUInt32(entry); } }
protected MemoryArea CreateMemoryArea(Address addr, params uint[] opcodes) { byte[] bytes = new byte[0x20]; var writer = new LeImageWriter(bytes); uint offset = 0; for (int i = 0; i < opcodes.Length; ++i, offset += 4) { writer.WriteLeUInt32(offset, opcodes[i]); } return(new MemoryArea(addr, bytes)); }
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); }
protected MachineInstruction DisassembleBits(string bitPattern) { var image = new MemoryArea(Address.Ptr32(0x00100000), new byte[4]); LeImageWriter w = new LeImageWriter(image.Bytes); uint instr = ParseBitPattern(bitPattern); w.WriteLeUInt32(0, instr); var b = image.Bytes; //Debug.Print("Instruction bytes: {0:X2} {1:X2} {2:X2} {3:X2}", b[0], b[1], b[2], b[3]); // Spews in the unit tests var arch = CreateArchitecture(); var dasm = arch.CreateDisassembler(image.CreateLeReader(0)); return(dasm.First()); }
protected MachineInstruction Disassemble32(uint instr) { var image = new MemoryArea(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()); this.armInstr = (AArch32Instruction)dasm.Current; dasm.Dispose(); return(armInstr); }
private void Given_IndirectTable_UInt32(Address address, Address addrIndirect, params uint[] entries) { ImageSegment seg; program.SegmentMap.Segments.TryGetValue(address, out seg); var writer = new LeImageWriter(seg.MemoryArea, address); foreach (uint entry in entries) { writer.WriteLeUInt32(entry); } writer = new LeImageWriter(seg.MemoryArea, addrIndirect); for (int i = 0; i < entries.Length; ++i) { writer.WriteByte((byte)i); } }
// PE section headers are always 40 bytes. private void Given_Section(string section, uint virtAddress, uint rvaData) { var bytes = Encoding.UTF8.GetBytes(section); writer.WriteBytes(bytes).WriteBytes(0, 8 - (uint)bytes.Length); writer.WriteLeUInt32(0x1000); // Section size in memory writer.WriteLeUInt32(virtAddress); // Where to load this writer.WriteLeUInt32(0x1000); // raw data writer.WriteLeUInt32(rvaData); // rva to raw data writer.WriteLeInt32(0); // relocs writer.WriteLeInt32(0); // line numbers writer.WriteLeInt16(0); // #relocs writer.WriteLeInt16(0); // #line numbers writer.WriteLeInt32(0); // characteristics // Increment the section count in the optional header. short sections = MemoryArea.ReadLeInt16(fileImage, RvaPeHdr + 6); MemoryArea.WriteLeInt16(fileImage, RvaPeHdr + 6, (short)(sections + 1)); }
private Action DW(uint n) { return(() => { writer.WriteLeUInt32(n); }); }