public void ApplyRelocation(uint baseOfImage, uint page, ImageReader rdr, RelocationDictionary relocations) { ushort fixup = rdr.ReadLeUInt16(); switch (fixup >> 12) { case RelocationAbsolute: // Used for padding to 4-byte boundary, ignore. break; case RelocationHighLow: { uint offset = page + (fixup & 0x0FFFu); uint n = (uint)(imgLoaded.ReadLeUInt32(offset) + (baseOfImage - preferredBaseOfImage.ToLinear())); imgLoaded.WriteLeUInt32(offset, n); relocations.AddPointerReference(offset, n); break; } case 0xA: break; default: throw new NotImplementedException(string.Format("Fixup type: {0:X}", fixup >> 12)); } }
public override void ApplyRelocation(Address baseOfImage, uint page, EndianImageReader rdr, RelocationDictionary relocations) { ushort fixup = rdr.ReadLeUInt16(); Address offset = baseOfImage + page + (fixup & 0x0FFFu); var arch = program.Architecture; var imgR = program.CreateImageReader(arch, offset); var imgW = program.CreateImageWriter(arch, offset); switch (fixup >> 12) { case RelocationAbsolute: // Used for padding to 4-byte boundary, ignore. break; case RelocationHighLow: { uint n = (uint)(imgR.ReadUInt32() + (baseOfImage - program.ImageMap.BaseAddress)); imgW.WriteUInt32(n); relocations.AddPointerReference(offset.ToLinear(), n); break; } case 0xA: break; default: dcSvc.Warn( dcSvc.CreateAddressNavigator(program, offset), string.Format( "Unsupported i386 PE fixup type: {0:X}", fixup >> 12)); break; } }
public void AddressNotInDictionary() { RelocationDictionary rd = new RelocationDictionary(); rd.AddPointerReference(0x020, 0x12312312); Assert.IsNull(rd[0x3243232]); Assert.IsFalse(rd.Contains(0x2341231)); }
public void AddPointerRelocation() { RelocationDictionary rd = new RelocationDictionary(); rd.AddPointerReference(0x100400, 0x100500); Assert.AreEqual(1, rd.Count); Constant c = rd[0x0100400]; Assert.AreEqual("ptr32", c.DataType.ToString()); }
public void Reld_Overlaps() { var rd = new RelocationDictionary(); rd.AddPointerReference(0x2000, 0x12312312); Assert.IsFalse(rd.Overlaps(Address.Ptr32(0x1FFC), 4)); Assert.IsFalse(rd.Overlaps(Address.Ptr32(0x2004), 1)); Assert.IsTrue(rd.Overlaps(Address.Ptr32(0x2003), 1)); Assert.IsTrue(rd.Overlaps(Address.Ptr32(0x1FFC), 5)); Assert.IsFalse(rd.Overlaps(Address.Ptr32(0x1FFF), 5)); Assert.IsFalse(rd.Overlaps(Address.Ptr32(0x2000), 4)); Assert.IsFalse(rd.Overlaps(Address.Ptr32(0x2000), 8)); Assert.IsFalse(rd.Overlaps(Address.Ptr32(0x1FFC), 8)); }
public void Shsc_Relocation_CrossesInstruction() { Given_x86_Image( 0x01, 0x02, 0xC3, 0x04, 0x4); rd.AddPointerReference(0x10001, 0x11000000); Given_Scanner(); var seg = program.SegmentMap.Segments.Values.First(); var scseg = this.sh.ScanRange(seg.MemoryArea, seg.Address, seg.Size, 0); Assert.AreEqual(new byte[] { 0, 0, 0, 0, 0 }, scseg); }
public void ApplyRelocation(uint baseOfImage, uint page, ImageReader rdr, RelocationDictionary relocations) { ushort fixup = rdr.ReadLeUInt16(); uint offset = page + (fixup & 0x0FFFu); switch (fixup >> 12) { case RelocationAbsolute: // Used for padding to 4-byte boundary, ignore. break; case RelocationHighLow: { uint n = (uint) (imgLoaded.ReadLeUInt32(offset) + (baseOfImage - preferredBaseOfImage.ToLinear())); imgLoaded.WriteLeUInt32(offset, n); relocations.AddPointerReference(offset, n); break; } case 0xA: break; default: var dcSvc = Services.RequireService<DecompilerEventListener>(); dcSvc.Warn( dcSvc.CreateAddressNavigator(program, Address.Ptr32(offset)), string.Format( "Unsupported PE fixup type: {0:X}", fixup >> 12)); break; } #if I386 // // I386 relocation types. // const static final ushort IMAGE_REL_I386_ABSOLUTE = 0x0000; // Reference is absolute, no relocation is necessary const static final ushort IMAGE_REL_I386_DIR16 = 0x0001; // Direct 16-bit reference to the symbols virtual address const static final ushort IMAGE_REL_I386_REL16 = 0x0002; // PC-relative 16-bit reference to the symbols virtual address const static final ushort IMAGE_REL_I386_DIR32 = 0x0006; // Direct 32-bit reference to the symbols virtual address const static final ushort IMAGE_REL_I386_DIR32NB = 0x0007; // Direct 32-bit reference to the symbols virtual address, base not included const static final ushort IMAGE_REL_I386_SEG12 = 0x0009; // Direct 16-bit reference to the segment-selector bits of a 32-bit virtual address const static final ushort IMAGE_REL_I386_SECTION = 0x000A; const static final ushort IMAGE_REL_I386_SECREL = 0x000B; const static final ushort IMAGE_REL_I386_TOKEN = 0x000C; // clr token const static final ushort IMAGE_REL_I386_SECREL7 = 0x000D; // 7 bit offset from base of section containing target const static final ushort IMAGE_REL_I386_REL32 = 0x0014; // PC-relative 32-bit reference to the symbols virtual address