Example #1
0
 public void Setup()
 {
     sc = new ServiceContainer();
     mr = new MockRepository();
     addrLoad = Address.Ptr32(0x00100000);
     fileImage = new byte[0x4000];
     writer = new LeImageWriter(fileImage);
 }
 private ImageWriter Memory(uint address)
 {
     mem = new MemoryArea(Address.Ptr32(address), new byte[1024]);
     imageMap = new SegmentMap(
         mem.BaseAddress,
         new ImageSegment(".data", mem, AccessMode.ReadWrite));
     var writer = new LeImageWriter(mem.Bytes);
     return writer;
 }
Example #3
0
 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;
 }
Example #4
0
 protected LoadedImage CreateImage(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 LoadedImage(addr, bytes);
 }
Example #5
0
 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();
 }
Example #6
0
 public void Setup()
 {
     sc = new ServiceContainer();
     mr = new MockRepository();
     addrLoad = Address.Ptr32(0x00100000);
     fileImage = new byte[0x4000];
     writer = new LeImageWriter(fileImage);
     var cfgSvc = mr.StrictMock<IConfigurationService>();
     Given_i386_Architecture();
     cfgSvc.Stub(c => c.GetArchitecture("x86-protected-32")).Return(arch_386);
     sc.AddService<IConfigurationService>(cfgSvc);
 }
Example #7
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 LoadedImage(Address.Ptr16(0x200), bytes);
     var rdr = new LeImageReader(image, 0);
     var arch = new Pdp11Architecture();
     var dasm = new Pdp11Disassembler(rdr, arch);
     return dasm.First();
 }
Example #8
0
 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;
 }
Example #9
0
 public void Setup()
 {
     sc = new ServiceContainer();
     mr = new MockRepository();
     addrLoad = Address.Ptr32(0x00100000);
     fileImage = new byte[0x4000];
     writer = new LeImageWriter(fileImage);
     var cfgSvc = mr.StrictMock<IConfigurationService>();
     Given_i386_Architecture();
     var win32 = new Win32Platform(sc, arch_386);
     var win32Env = mr.Stub<OperatingEnvironment>();
     cfgSvc.Stub(c => c.GetArchitecture("x86-protected-32")).Return(arch_386);
     cfgSvc.Stub(c => c.GetEnvironment("win32")).Return(win32Env);
     win32Env.Stub(w => w.Load(null, null)).IgnoreArguments().Return(win32);
     sc.AddService<IConfigurationService>(cfgSvc);
 }
Example #10
0
 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;
 }
Example #11
0
 public void Setup()
 {
     sc = new ServiceContainer();
     mr = new MockRepository();
     addrLoad = Address.Ptr32(0x00100000);
     fileImage = new byte[0x4000];
     writer = new LeImageWriter(fileImage);
     var cfgSvc = mr.StrictMock<IConfigurationService>();
     var dcSvc = mr.Stub<DecompilerEventListener>();
     Given_i386_Architecture();
     this.win32 = mr.PartialMock<Win32Platform>(sc, arch_386);
     // Avoid complications with the FindMainProcedure call.
     this.win32.Stub(w => w.FindMainProcedure(null, null)).IgnoreArguments().Return(null);
     var win32Env = mr.Stub<OperatingEnvironment>();
     cfgSvc.Stub(c => c.GetArchitecture("x86-protected-32")).Return(arch_386);
     cfgSvc.Stub(c => c.GetEnvironment("win32")).Return(win32Env);
     win32Env.Stub(w => w.Load(null, null)).IgnoreArguments().Return(win32);
     sc.AddService<IConfigurationService>(cfgSvc);
     sc.AddService<DecompilerEventListener>(dcSvc);
 }
Example #12
0
 private ImageWriter Memory(uint address)
 {
     image = new LoadedImage(Address.Ptr32(address), new byte[1024]);
     var mem = new LeImageWriter(image.Bytes);
     return mem;
 }
 private void Given_String(string str, uint addr)
 {
     var w = new LeImageWriter(mem.Bytes, addr - (uint)mem.BaseAddress.ToLinear());
     w.WriteString(str, Encoding.ASCII);
 }
Example #14
0
 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);
     }
 }
Example #15
0
 public override ImageWriter Clone()
 {
     var w = new LeImageWriter(Bytes, (uint)Position);
     w.MemoryArea = this.MemoryArea;
     return w;
 }
Example #16
0
 private ImageWriter Given_Memory(uint address)
 {
     this.mem = new MemoryArea(Address.Ptr32(address), new byte[1024]);
     var mem = new LeImageWriter(this.mem.Bytes);
     return mem;
 }
Example #17
0
        public override ImageWriter Clone()
        {
            var w = new LeImageWriter(Bytes, (uint)Position);

            return(w);
        }
Example #18
0
 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);
     }
 }