搞定了:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br><br> TInstallHook=function :Boolean;Stdcall;<br> TUnHook=function :Boolean;Stdcall;<br><br> PJmpCode = ^TJmpCode;<br> TJmpCode = packed record<br> JmpCode: BYTE;<br> Address: Dword;<br> end;<br><br> TForm1 = class(TForm)<br> Button1: TButton;<br> Memo1: TMemo;<br> procedure Button1Click(Sender: TObject);<br> procedure FormShow(Sender: TObject);<br> private<br> { Private declarations }<br> InstallHook,InstallHook1:TInstallHook;<br> UnHook:TUnHook;<br> JmpCode:TJmpCode;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>function ElevPrivileges(): Boolean;<br>const<br> ADJUST_PRIV = TOKEN_QUERY or TOKEN_ADJUST_PRIVILEGES;<br> PRIV_SIZE = SizeOf(TTokenPrivileges);<br>var<br> Len : DWORD;<br> TokenPriv, Dummy : TTokenPrivileges;<br> Token : THandle;<br>begin<br> Result:=False;<br> try<br> if not OpenProcessToken(GetCurrentProcess(), ADJUST_PRIV, Token) then Exit;<br> if not LookupPrivilegeValue(nil,<br> 'SeDebugPrivilege',<br> TokenPriv.Privileges[0].Luid) then exit;<br> TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br> TokenPriv.PrivilegeCount := 1; <br> if not AdjustTokenPrivileges(Token, False, TokenPriv, PRIV_SIZE,Dummy, Len) then Exit;<br> Result:=True;<br> except<br> end; <br>end;<br><br>function MyInstallHook:Boolean;Stdcall;<br>begin<br> form1.Memo1.Text:='ok';<br> result:=true;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> DllHandle:LongWord;<br> dwSize: cardinal;<br>begin<br> DllHandle:=LoadLibrary('Hook.dll');<br> if DllHandle>0 then<br> begin<br> @InstallHook:=GetProcAddress(DllHandle,'InstallHook');<br> @UnHook:=GetProcAddress(DllHandle,'UnHook');<br> @InstallHook1:=GetProcAddress(DllHandle,'InstallHook1');<br> if (@InstallHook=Nil) or (@UnHook=nil) or (@InstallHook1=Nil) then<br> begin<br> showmessage('No Add');<br> Exit;<br> end else<br> begin<br> ReadProcessMemory(OpenProcess(PROCESS_ALL_ACCESS, True, GetCurrentProcessId),<br> @InstallHook,<br> @JmpCode,<br> 5,<br> dwSize);<br> JmpCode.JmpCode:=233;<br> //JmpCode.Address := @InstallHook1;<br> JmpCode.Address := Integer(@InstallHook1)-Integer(@InstallHook) -5;<br> WriteProcessMemory(OpenProcess(PROCESS_ALL_ACCESS, True, GetCurrentProcessId),<br> @InstallHook,<br> {@InstallHook1}@JmpCode,<br> {Integer(@InstallHook1)-Integer(@InstallHook)}5,<br> dwSize);<br> sleep(100);<br> InstallHook;<br> end;<br> end else<br> begin <br> showmessage('no Dll');<br> Exit;<br> end;<br>end;<br><br>procedure TForm1.FormShow(Sender: TObject);<br>begin<br>ElevPrivileges;<br>end;<br><br>end.<br><br>我的DLL:<br>library Hook;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> first unit in your library's USES clause AND your project's (select<br> Project-View Source) USES clause if your DLL exports any procedures or<br> functions that pass strings as parameters or function results. This<br> applies to all strings passed to and from your DLL--even those that<br> are nested in records and classes. ShareMem is the interface unit to<br> the BORLNDMM.DLL shared memory manager, which must be deployed along<br> with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> using PChar or ShortString parameters. }<br><br>uses<br> SysUtils,<br> windows,<br> Messages,<br> Controls,<br> ExtCtrls;<br><br>var<br> HookHandle:LongWord;<br><br>{$R *.res}<br>function replace:Boolean;<br>begin<br> if Not FileExists('abcd.txt') then<br> begin<br> FileCreate('abcd.txt');<br> end;<br> Result:=True;<br>end;<br><br>function InstallHook:Boolean;Stdcall;<br>begin<br> if Not FileExists('abc.txt') then<br> begin<br> FileCreate('abc.txt');<br> end;<br> Result:=True;<br>end;<br><br>function InstallHook1:Boolean;Stdcall;<br> type TInstallHool=Function:Boolean;<br>begin<br> TInstallHool(@replace);<br> result:=True;<br>end;<br><br>function UnHook:Boolean;Stdcall;<br>begin<br> UnhookWindowsHookEx(HookHandle);<br> Result:=True;<br>end;<br><br>exports<br> InstallHook,UnHook,InstallHook1;<br> <br>begin<br>end.