rocedure API_Hookup;
begin
if @OldMessageBoxA = nil then
@OldMessageBoxA := TrueFunctionAddress(@messageboxA);
if @OldMessageBoxW = nil then
@OldMessageBoxW := TrueFunctionAddress(@messageboxW);
PermuteFunction(FuncMessageboxA.AddressOfPointerToFunction, @MyBoxA);
PermuteFunction(FuncMessageboxW.AddressOfPointerToFunction, @MyBoxW);
end;
procedure Un_API_hook;
begin
If @OldMessageBoxA <> nil then begin
PermuteFunction(FuncMessageboxA.AddressOfPointerToFunction,
@OldMessageboxA);
PermuteFunction(FuncMessageboxW.AddressOfPointerToFunction,
@OldMessageboxW);
end;
end;
initialization
FuncMessageboxA := @MessageboxA;
FuncMessageboxW := @MessageboxW;
end.
在主窗体上添加三个按钮,添加Onclick 代码,如下:
procedure TForm1.Button1Click( Sender : TObject);
begin
API_HookUp;
end;
procedure TForm1.Button3Click( Sender : TObject);
begin
Un_API_Hook;
end;
procedure TForm1.Button2Click( Sender : TObject);
begin
MessageBoxA(Form1.Handle,'NO HOOK UP A','MessageBoxA',MB_OK);
MessageBoxW(Form1.Handle,'NO HOOK UP W','MessageBoxW',MB_OK);
end;
记得要保存,在后面我们还要使用它们。编译一下,
运行..啊哈,成功了!且慢,别高兴得太早。如果现在新建
一个Application TestTry,在Form 上添加一个按钮,Onclick事
件如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
MessageBoxA(Form1.Handle,'NO HOOK UP A','MessageBoxA',MB_OK);
MessageBoxW(Form1.Handle,'NO HOOK UP W','MessageBoxW',MB_OK);
MessageBox (Form1.Handle,'NO HOOK UP BOX','MessageBox',MB_OK);