I tried to replace Delphi build-in function with my own version on-the-fly.
function ShortCutToTextOverride(ShortCut: TShortCut): string;
begin
if SomeCondition then
Result := Menus.ShortCutToText // after patching the pointer equals ShortCutToTextOverride
else
begin
// My own code goes here
end;
end;
FastcodeAddressPatch(@Menus.ShortCutToText, @ShortCutToTextOverride);
After patching, the original function is no longer accessible.
It is possible access it anyway?
I’m afraid not: the first bytes are overwritten by a jump to the new function.
You can use KOLDetours.pas: it returns the pointer to the trampoline (original first few bytes that are overwritten by the detour).
http://code.google.com/p/asmprofiler/source/browse/trunk/SRC/KOLDetours.pas
For example: