CopyFunction fails with memory access exception on x64

delphi package - getting into other processes
Post Reply
wassily
Posts: 12
Joined: Sun Dec 16, 2012 6:37 pm

CopyFunction fails with memory access exception on x64

Post by wassily »

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

Code: Select all

STDMETHODIMP DropTargetProxy_DragLeave(IDropTargetProxy *self)
{
    return self->DropTarget->DragLeave();
}
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

Code: Select all

	PVOID copy = CopyFunction(DropTargetProxy_DragLeave, NULL, TRUE);
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
madshi
Site Admin
Posts: 10334
Joined: Sun Mar 21, 2004 5:25 pm

Re: CopyFunction fails with memory access exception on x64

Post by madshi »

Hello,

and sorry for the late reply. Would it be possible for you to create a (very) small test project with which I could reproduce the issue? That would help a lot!
Post Reply