How to access the replaced procedure after FastcodeAddressPatch

I tried replacing the Delphi built-in function with my own on-the-fly version.

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 the fix, the original function is no longer available. Is access to it possible?

+3
source share
1 answer

I'm afraid not: the first bytes are overwritten with a jump to a new function.

You can use KOLDetours.pas: it returns a pointer to the trampoline (the initial first few bytes that are overwritten by bypass). http://code.google.com/p/asmprofiler/source/browse/trunk/SRC/KOLDetours.pas

For instance:

type
  TNowFunction = function:TDatetime;
var
  OrgNow: TNowFunction;
function NowExact: TDatetime;
begin
  //exact time using QueryPerformanceCounter
end; 

initialization
  OrgNow := KOLDetours.InterceptCreate(@Now, @NowExact);
  Now()     -> executes NowExact() 
  OrgNow()  -> executes original Now() before the hook 
+6
source

All Articles