CopyFunction fails with memory access exception on x64
Posted: Mon Dec 24, 2012 5:21 pm
As the subject says, my attempt to copy functions in x64 builds fail while everything works perfect for x86 builds. I use VC++ 2010 compiler and the copied functions are (mostly) simple thunks like
It is necessary to set "acceptUnknownTargets" to true for such code, and I want copy inside of the current process so the call looks like
Stepping into the implemention with the built in debugger shows that my function is copied just fine but after calling VirtualProtectEx(copyBuffer, ...) CopyFunction tries to write a value by pointer equal to 1 (ProcessMemory[1] = value), and naturally everything breaks
Code: Select all
STDMETHODIMP DropTargetProxy_DragLeave(IDropTargetProxy *self)
{
return self->DropTarget->DragLeave();
}
Code: Select all
PVOID copy = CopyFunction(DropTargetProxy_DragLeave, NULL, TRUE);