P
pertty
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是dll工程文件:<br><br>library drHook;<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> Classes,<br> Unit2 in 'Unit2.pas',<br> Unit1 in 'Unit1.pas' {Form1};<br>var<br><br>{$R *.res}<br>exports<br> CreateKeyboardHook,<br> DestroyKeyboardHook;<br>begin<br> hNextHookProc := 0;<br> procSaveExit := ExitProc;<br> ExitProc := @KeyboardHookExit;<br>end.<br><br><br>dll中键盘钩子unit:<br><br><br>unit Unit2;<br><br>interface<br><br>uses<br> Windows, SysUtils,forms;<br>var<br> hNextHookProc: HHook;<br> procSaveExit: Pointer;<br><br>function KeyboardHookProc(code: Integer; wparam: WPARAM;<br> lparam: LPARAM): LRESULT stdcall; export;<br>function CreateKeyboardHook: BOOL; stdcall; export;<br>function DestroyKeyboardHook: BOOL; stdcall; export;<br>procedure KeyboardHookExit;<br><br>implementation<br><br>uses Unit1;<br><br>var<br><br> hthradhandle:dword;<br> dwthradid:dword;<br>function KeyboardHookProc(code: Integer; wparam: WPARAM;<br> lparam: LPARAM): LRESULT;<br>const<br> _KeyProcessMask = $80000000;<br>var<br> GameSwitch: Word; //程序热键<br> hwnd:dword;<br> classname: pchar;<br>begin<br> Result := 0;<br> if code < 0 then<br> begin<br> Result := Windows.CallNextHookEx(hNextHookProc, code, wparam, lparam);<br> Exit;<br> end;<br> hwnd:=findwindow(nil,'Element Client');<br> if ((lparam and _KeyProcessMask) = 0) and (wparam = GameSwitch) then<br> begin<br> hwnd:=getforegroundwindow (); //获取当前窗体句柄<br> GetMem (classname, 255);<br> getclassname (hwnd, classname, 255);<br> if form1 <> nil then Form1.show //如果dll窗体加载了就显示<br> else begin<br> try<br> Form1 := TForm1.CreateParented (hwnd) ; //dllform创建<br> Form1.Show;<br> except<br> Form1.free;<br> end;<br> end;<br><br> freeMem(classname);<br> end;<br>end;<br><br>function CreateKeyboardHook: BOOL;<br>begin<br> Result := false;<br> if hNextHookProc <> 0 then<br> exit;<br> hNextHookProc := Windows.SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc,<br> hInstance, 0);<br> Result := hNextHookProc <> 0;<br>end;<br><br>function DestroyKeyboardHook: BOOL;<br>begin<br> if hNextHookProc <> 0 then<br> begin<br> Windows.UnhookWindowsHookEx(hNextHookProc);<br> hNextHookProc := 0;<br> end;<br> Result := hNextHookProc = 0;<br>end;<br><br>procedure KeyboardHookExit;<br>begin<br> if hNextHookProc <> 0 then<br> DestroyKeyboardHook;<br> ExitProc := procSaveExit;<br>end;<br><br> GameSwitch := VK_HOME; //定义程序热键<br> hthradhandle := createthread(nil,0,@CreateKeyboardHook,nil,0,dwthradid);<br><br>end.<br><br>dll中窗体unit:<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs;<br><br>type<br> TForm1 = class(TForm)<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br>var<br> Form1: TForm1;<br>implementation<br>{$R *.dfm}<br>end.<br><br>下面是调用主程序工程文件代码:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, Buttons;<br><br>type<br> TForm1 = class(TForm)<br> BitBtn1: TBitBtn;<br> BitBtn2: TBitBtn;<br> Memo1: TMemo;<br> procedure BitBtn1Click(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>function CreateKeyboardHook: BOOL; external 'drHook.dll';<br>function DestroyKeyboardHook: BOOL; external 'drHook.dll';<br><br>procedure GetDebugPrivs; //提升程序权限过程<br>var<br> hToken: THandle;<br> tkp: TTokenPrivileges;<br> retval: dword;<br>begin<br> If (OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)) then<br> begin<br> LookupPrivilegeValue(nil, 'SeDebugPrivilege' , tkp.Privileges[0].Luid);<br> tkp.PrivilegeCount := 1;<br> tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br> AdjustTokenPrivileges(hToken, False, tkp, 0, nil, retval);<br> end;<br>end;<br><br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br> h:longword; //放句柄,中间顺便暂放下PID<br> tmp:longword;//这个专门来占格式收集垃圾<br> DllNamechar;<br> Mysize:longword;//放字符串长度<br> Parameterointer;//放那个参数的指针(位置在目标进程内)<br>begin<br> GetDebugPrivs; //提升权限<br> DLLName:=pchar(extractfilepath(paramstr(0))+'drHook.dll'); //下面是代码注入<br> Mysize:=strlen(Dllname)+1;<br> GetWindowThreadProcessId(FindWindow('Element Client', nil), @h);<br> h:=OpenProcess(PROCESS_ALL_ACCESS, False, h);<br> Parameter:= VirtualAllocEx(h, nil, Mysize, MEM_COMMIT, PAGE_READWRITE);<br> WriteProcessMemory(h, Parameter, Pointer(DllName), MySize, tmp);<br> CreateRemoteThread(h,nil, 0, GetProcAddress(GetModuleHandle ('KERNEL32.DLL'), 'LoadLibraryA'), Parameter, 0 , tmp);<br>end;<br><br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> DestroyKeyboardHook;<br>end;<br><br>end.<br><br><br>这个该死的问题已经困扰我n天了。。。谁能帮我解决就给分。 就是一个在游戏中调出窗口的问题。。我这个要用到dll注入。。当然如果有其他的方法也可以!<br><br>QQ 378798095