FIX x86 COM trampoline
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-12-09 15:47:39 +00:00
parent 6edb6fac17
commit 6f4207dee8

View File

@@ -132,7 +132,7 @@ namespace VisualStudioMock
private static IntPtr CreateThunk(IntPtr @this, IntPtr jmpTarget) private static IntPtr CreateThunk(IntPtr @this, IntPtr jmpTarget)
{ {
int allocSize = Environment.Is64BitProcess ? 22 : 13; int allocSize = Environment.Is64BitProcess ? 22 : 15;
if (_execBlockSize - _execBlockNext < allocSize) if (_execBlockSize - _execBlockNext < allocSize)
{ {
@@ -149,7 +149,7 @@ namespace VisualStudioMock
_execBlockNext = 0; _execBlockNext = 0;
#if LOG_CALLS #if LOG_CALLS
Ext.Log("Allocated thunk page at 0x" + _execBlockBase.ToString("X")); Ext.Log("Allocated thunk page at 0x" + _execBlockBase.ToString("X") + " (" + (Environment.Is64BitProcess ? "x64" : "x86") + ")");
#endif #endif
} }
@@ -175,12 +175,15 @@ namespace VisualStudioMock
else else
{ {
// NOT tested! // NOT tested!
// pop eax // 0x58 pop eax // return address
// push this // 0x59 pop ecx // this to be replaced
Marshal.WriteByte(_execBlockBase, _execBlockNext, 0x58); // 0x68 ... push this
Marshal.WriteByte(_execBlockBase, _execBlockNext + 1, 0x68); // 0x50 push eax // restore return address
Marshal.WriteIntPtr(_execBlockBase, _execBlockNext + 2, @this); Marshal.WriteInt16(_execBlockBase, _execBlockNext, unchecked((short)(0x5958)));
_execBlockNext += 1 + 1 + IntPtr.Size; Marshal.WriteByte(_execBlockBase, _execBlockNext + 2, 0x68);
Marshal.WriteIntPtr(_execBlockBase, _execBlockNext + 3, @this);
Marshal.WriteByte(_execBlockBase, _execBlockNext + 7, 0x50);
_execBlockNext += 3 + IntPtr.Size + 1;
// mov eax target_address // mov eax target_address
// jmp eax // jmp eax