【问题标题】:How to access replaced procedure after FastcodeAddressPatch如何在 FastcodeAddressPatch 之后访问替换过程
【发布时间】:2012-05-15 09:05:40
【问题描述】:

我试图用我自己的版本即时替换 Delphi 内置函数。

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);

打补丁后,原来的功能已经无法使用了。 无论如何都可以访问它?

【问题讨论】:

标签: delphi


【解决方案1】:

恐怕不会:第一个字节会被新函数的跳转覆盖。

您可以使用 KOLDetours.pas:它返回指向蹦床的指针(原来的前几个字节被绕道覆盖)。 http://code.google.com/p/asmprofiler/source/browse/trunk/SRC/KOLDetours.pas

例如:

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 

【讨论】:

  • KOLDetours 完美适用于 32 位编译器,但在 64 位编译器上存在一些问题。我没有找到 64 位的任何更新。
  • 我发现一个补丁版本Cromis.Detours 与 x64 兼容。希望这些信息对大家有所帮助。
  • @stanleyxu2005 你确定它在 64 位上工作吗?因为它是同一个单元(koldetours 的副本),对于处理 64 位特定的东西没有任何变化。或者你能发布一个补丁版本的链接吗?
  • 这里是链接code.google.com/p/native-look-vcl 我被管理使用 KOLDetours 让它工作。但是我的应用程序无法在 x64 平台上编译,直到我切换到 Cromis.Detours。它的原始主页可以在谷歌中搜索到。
  • @stanleyxu2005 好的,所以它可以编译,但它也适用于 64 位吗?我怀疑它确实......
猜你喜欢
  • 2020-11-09
  • 1970-01-01
  • 2018-06-27
  • 1970-01-01
  • 2010-09-17
  • 2020-08-26
  • 2013-07-30
  • 2021-08-26
  • 2021-06-15
相关资源
最近更新 更多