I have a third party function
function DataCompare(const S1, S2: string; APartial: Boolean): Boolean;
begin
...
end;
It is used in another third party unit.
I wish to replace the body of the function at runtime with another new implementation.
Is this possible? I guess there will be a need of some hack (ala VirtualMemoryUnprotect). A non-assembler solution is very welcome.
Yes you can do that, using the
ReadProcessMemoryandWriteProcessMemoryfunctions to patch the code of the current process. Basically, you get the address of the procedure or function to patch and then insert a Jump instruction to the address of the new procedure.Check this code
Now every time you execute your app and a call to the
DataComparefunction was made, the jump instruction (to he new address) will be executed causing which theDataCompareHackfunction will be called instead.