看看我的源程序:<br>unit APIHook;<br>interface<br>uses<br> SysUtils,<br> Windows, shellapi, Dialogs;<br>type<br> //要HOOK的API函数定义<br> TFileoperate = function(var lpFileOp: TSHFileOpStructW): Integer; stdcall;<br> PJmpCode = ^TJmpCode;<br> TJmpCode = packed record<br> OrderCode: BYTE;<br> Address: TFileoperate;<br> MovEAX: array[0..2] of BYTE;<br> end;<br> //--------------------函数声明---------------------------<br>procedure HookAPI;<br>procedure UnHookAPI;<br>var<br> OldSHFileOperationW: TFileoperate; //原来的API地址<br> OldProc,NewProc : TJmpCode;<br> Add_SHFileOperationW: pointer; //API地址<br> TmpJmp : TJmpCode;<br> ProcessHandle : THandle;<br>implementation<br><br>function MySHFileOperationW(var lpFileOp: TSHFileOpStructW):<br> Integer; stdcall;<br>var<br> dwSize : cardinal;<br>begin<br> showmessage('dd');<br> WriteProcessMemory(ProcessHandle, Add_SHFileOperationW, @OldProc, 8,<br> dwSize);<br> Result := OldSHFileOperationW(lpFileOp);<br> NewProc.Address := @MySHFileOperationW;<br> WriteProcessMemory(ProcessHandle, Add_SHFileOperationW, @NewProc, 8,<br> dwSize);<br>end;<br>{------------------------------------}<br>{过程功能:HookAPI<br>{过程参数:无<br>{------------------------------------}<br><br>procedure HookAPI;<br>var<br> DLLModule : THandle;<br> dwSize : cardinal;<br>begin<br> ProcessHandle := GetCurrentProcess;<br> DLLModule := LoadLibrary('shell32.dll');<br> Add_SHFileOperationW := GetProcAddress(DLLModule, 'SHFileOperationW'); //取得API地址<br> NewProc.OrderCode := $B8;<br> NewProc.MovEAX[0] := $FF;<br> NewProc.MovEAX[1] := $E0;<br> NewProc.MovEAX[2] := 0;<br> ReadProcessMemory(ProcessHandle, Add_SHFileOperationW, @OldProc, 8,<br> dwSize);<br> NewProc.Address := @MySHFileOperationW;<br> WriteProcessMemory(ProcessHandle, Add_SHFileOperationW, @NewProc, 8,<br> dwSize);<br> OldSHFileOperationW := MySHFileOperationW;<br>end;<br>{------------------------------------}<br>{过程功能:取消HOOKAPI<br>{过程参数:无<br>{------------------------------------}<br><br>procedure UnHookAPI;<br>var<br> dwSize : Cardinal;<br>begin<br> WriteProcessMemory(ProcessHandle, Add_SHFileOperationW, @OldProc, 8,<br> dwSize);<br>end;<br>end.