我尝试用我自己的版本即时替换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);
Run Code Online (Sandbox Code Playgroud)
修补后,无法再访问原始功能.无论如何都可以访问它?
我不敢这样做:跳转到新函数会覆盖第一个字节.
您可以使用KOLDetours.pas:它返回指向trampoline的指针(原始的前几个字节被绕行覆盖). 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
447 次 |
| 最近记录: |