Last active
October 8, 2016 23:57
-
-
Save toptensoftware/98c6299487b3b7127a019fd3cf8b17ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| List<Action> _systemThunkHanders = new List<Action>(); | |
| public uint CreateSystemThunk(Action handler, ushort popStack) | |
| { | |
| // Capture address of this thunk | |
| ushort address = _systemCodeGenPos; | |
| // Store the handler | |
| ushort thunkIndex = (ushort)_systemThunkHanders.Count; | |
| _systemThunkHanders.Add(handler); | |
| // Get memory buffer | |
| byte[] mem = _globalHeap.GetBuffer(_systemCodeSelector); | |
| // MOV AX, thunk index | |
| mem[_systemCodeGenPos++] = 0xb8; | |
| mem[_systemCodeGenPos++] = (byte)(thunkIndex & 0xFF); | |
| mem[_systemCodeGenPos++] = (byte)(thunkIndex >> 8); | |
| // INT 80h | |
| mem[_systemCodeGenPos++] = 0xCD; | |
| mem[_systemCodeGenPos++] = 0x80; | |
| // RETF | |
| mem[_systemCodeGenPos++] = 0xCA; | |
| mem[_systemCodeGenPos++] = (byte)(popStack & 0xFF); | |
| mem[_systemCodeGenPos++] = (byte)(popStack >> 8); | |
| // Return seg:offset address of thunk | |
| return (uint)(_systemCodeSelector << 16 | address); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment