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)); } }
private void Write(MachineOperand op, TWord w) { var r = op as RegisterOperand; if (r != null) { WriteRegister(r.Register, w); return; } var m = op as MemoryOperand; if (m != null) { var ea = GetEffectiveAddress(m); switch (op.Width.Size) { case 1: img.WriteByte(Address.Ptr32(ea), (byte)w); return; case 4: img.WriteLeUInt32(Address.Ptr32(ea), (UInt32)w); return; } throw new NotImplementedException(); } throw new NotImplementedException(); }
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