Skip to content

Instantly share code, notes, and snippets.

@toptensoftware
Created October 11, 2016 02:34
Show Gist options
  • Select an option

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

Select an option

Save toptensoftware/918226d72e2b5aeb19427bfa39ecb6dd to your computer and use it in GitHub Desktop.
public override void Init(Machine machine)
{
if (IsDll)
{
// Save DS
var saveds = machine.ds;
// Call Library entry point
machine.di = hModule;
machine.ds = DataSegment == null ? (ushort)0 : DataSegment.globalHandle;
machine.cx = _neFile.Header.InitHeapSize;
// Find entry point
var ip = (ushort)(_neFile.Header.EntryPoint & 0xFFFF);
var cs = _neFile.Segments[(int)((_neFile.Header.EntryPoint >> 16) - 1)].globalHandle;
// Call it
machine.FarCall(BitUtils.MakeDWord(ip, cs));
// Success?
if (machine.ax==0)
throw new VirtualException("LibMain failed");
// Restore DS
machine.ds = saveds;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment