Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save toptensoftware/cf263e4730d4525feb65f5272174deb9 to your computer and use it in GitHub Desktop.
Patching exported functions
foreach (var ep in _neFile.GetAllEntryPoints().Where(x=>(x.flags & Win3muCore.NeFile.EntryPoint.FLAG_EXPORTED)!=0))
{
// Get the segment
var segment = segments[ep.segmentNumber - 1].globalHandle;
var data = machine.GlobalHeap.GetBuffer(segment);
// Shared DS?
if ((ep.flags & Win3muCore.NeFile.EntryPoint.FLAG_SHAREDDS)!=0)
{
// Insert MOV AX,xxxx instruction
data[ep.segmentOffset] = 0xb8;
data.WriteWord(ep.segmentOffset + 1, this.DataSelector);
}
else
{
if (!this.IsDll)
{
// NOP out the push ds, pop ax instructions
data[ep.segmentOffset] = 0x90; // NOP
data[ep.segmentOffset+1] = 0x90; // NOP
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment