Skip to content

Instantly share code, notes, and snippets.

@toptensoftware
Last active October 11, 2016 04:04
Show Gist options
  • Select an option

  • Save toptensoftware/f82c5535edbedfb1caef67a581cf634b to your computer and use it in GitHub Desktop.

Select an option

Save toptensoftware/f82c5535edbedfb1caef67a581cf634b to your computer and use it in GitHub Desktop.
Example relocations
// InternalReference links to another segment in this module
if (reloc.type == RelocationType.InternalReference)
{
var targetSegment = segments[reloc.param1 - 1];
ApplyRelocations(data, reloc.offset, (uint)(targetSegment.globalHandle << 16 | reloc.param2), additive);
}
// ImportedOrdinal links to an entry point in another module
if (reloc.type == RelocationType.ImportedOrdinal)
{
// Get the proc address
var moduleName = _neFile.ModuleReferenceTable[reloc.param1 - 1];
var module = machine.ModuleManager.GetModule(moduleName);
uint farProc = module.GetProcAddress(reloc.param2);
if (farProc == 0)
throw new VirtualException("Module link failed, function ordinal #{0:X4} not found in module '{1}'", reloc.param2, moduleName);
ApplyRelocations(data, reloc.offset, farProc, additive);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment