菜鸟问题。。。。(200分)

  • 主题发起人 主题发起人 pertty
  • 开始时间 开始时间
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> &nbsp;first unit in your library's USES clause AND your project's (select<br> &nbsp;Project-View Source) USES clause if your DLL exports any procedures or<br> &nbsp;functions that pass strings as parameters or function results. This<br> &nbsp;applies to all strings passed to and from your DLL--even those that<br> &nbsp;are nested in records and classes. ShareMem is the interface unit to<br> &nbsp;the BORLNDMM.DLL shared memory manager, which must be deployed along<br> &nbsp;with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> &nbsp;using PChar or ShortString parameters. }<br><br>uses<br> &nbsp;SysUtils,<br> &nbsp;Classes,<br> &nbsp;Unit2 in 'Unit2.pas',<br> &nbsp;Unit1 in 'Unit1.pas' {Form1};<br>var<br><br>{$R *.res}<br>exports<br> &nbsp;CreateKeyboardHook,<br> &nbsp;DestroyKeyboardHook;<br>begin<br> &nbsp;hNextHookProc := 0;<br> &nbsp;procSaveExit := ExitProc;<br> &nbsp;ExitProc := @KeyboardHookExit;<br>end.<br><br><br>dll中键盘钩子unit:<br><br><br>unit Unit2;<br><br>interface<br><br>uses<br> &nbsp;Windows, SysUtils,forms;<br>var<br> &nbsp;hNextHookProc: HHook;<br> &nbsp;procSaveExit: Pointer;<br><br>function KeyboardHookProc(code: Integer; wparam: WPARAM;<br> &nbsp;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> &nbsp;hthradhandle:dword;<br> &nbsp;dwthradid:dword;<br>function KeyboardHookProc(code: Integer; wparam: WPARAM;<br> &nbsp;lparam: LPARAM): LRESULT;<br>const<br> &nbsp;_KeyProcessMask = $80000000;<br>var<br> &nbsp; &nbsp;GameSwitch: Word; &nbsp; &nbsp;//程序热键<br> &nbsp; &nbsp;hwnd:dword;<br> &nbsp; &nbsp;classname: pchar;<br>begin<br> &nbsp;Result := 0;<br> &nbsp;if code &lt; 0 then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := Windows.CallNextHookEx(hNextHookProc, code, wparam, lparam);<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br> &nbsp;hwnd:=findwindow(nil,'Element Client');<br> &nbsp;if ((lparam and _KeyProcessMask) = 0) and (wparam = GameSwitch) then<br> &nbsp;begin<br> &nbsp; &nbsp;hwnd:=getforegroundwindow (); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //获取当前窗体句柄<br> &nbsp; &nbsp;GetMem (classname, 255);<br> &nbsp; &nbsp;getclassname (hwnd, classname, 255);<br> &nbsp; &nbsp;if form1 &lt;&gt; nil then Form1.show &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //如果dll窗体加载了就显示<br> &nbsp; &nbsp;else begin<br> &nbsp; &nbsp; &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp;Form1 := TForm1.CreateParented (hwnd) ; &nbsp; &nbsp; &nbsp; //dllform创建<br> &nbsp; &nbsp; &nbsp; &nbsp;Form1.Show;<br> &nbsp; &nbsp; &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp; &nbsp;Form1.free;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp;freeMem(classname);<br> &nbsp;end;<br>end;<br><br>function CreateKeyboardHook: BOOL;<br>begin<br> &nbsp;Result := false;<br> &nbsp;if hNextHookProc &lt;&gt; 0 then<br> &nbsp; &nbsp;exit;<br> &nbsp;hNextHookProc := Windows.SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc,<br> &nbsp; &nbsp;hInstance, 0);<br> &nbsp;Result := hNextHookProc &lt;&gt; 0;<br>end;<br><br>function DestroyKeyboardHook: BOOL;<br>begin<br> &nbsp;if hNextHookProc &lt;&gt; 0 then<br> &nbsp;begin<br> &nbsp; &nbsp;Windows.UnhookWindowsHookEx(hNextHookProc);<br> &nbsp; &nbsp;hNextHookProc := 0;<br> &nbsp;end;<br> &nbsp;Result := hNextHookProc = 0;<br>end;<br><br>procedure KeyboardHookExit;<br>begin<br> &nbsp;if hNextHookProc &lt;&gt; 0 then<br> &nbsp; &nbsp;DestroyKeyboardHook;<br> &nbsp;ExitProc := procSaveExit;<br>end;<br><br> &nbsp;GameSwitch := VK_HOME; &nbsp;//定义程序热键<br> &nbsp;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> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>var<br> &nbsp;Form1: TForm1;<br>implementation<br>{$R *.dfm}<br>end.<br><br>下面是调用主程序工程文件代码:<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, Buttons;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;BitBtn1: TBitBtn;<br> &nbsp; &nbsp;BitBtn2: TBitBtn;<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;procedure BitBtn1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure FormDestroy(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;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; &nbsp; //提升程序权限过程<br>var<br> &nbsp;hToken: THandle;<br> &nbsp;tkp: TTokenPrivileges;<br> &nbsp;retval: dword;<br>begin<br> &nbsp;If (OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)) then<br> &nbsp;begin<br> &nbsp; &nbsp;LookupPrivilegeValue(nil, 'SeDebugPrivilege' &nbsp;, tkp.Privileges[0].Luid);<br> &nbsp; &nbsp;tkp.PrivilegeCount := 1;<br> &nbsp; &nbsp;tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;<br> &nbsp; &nbsp;AdjustTokenPrivileges(hToken, False, tkp, 0, nil, retval);<br> &nbsp;end;<br>end;<br><br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>var<br> &nbsp;h:longword; //放句柄,中间顺便暂放下PID<br> &nbsp;tmp:longword;//这个专门来占格式收集垃圾<br> &nbsp;DllName:pchar;<br> &nbsp;Mysize:longword;//放字符串长度<br> &nbsp;Parameter:pointer;//放那个参数的指针(位置在目标进程内)<br>begin<br> &nbsp;GetDebugPrivs; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //提升权限<br> &nbsp;DLLName:=pchar(extractfilepath(paramstr(0))+'drHook.dll'); &nbsp;//下面是代码注入<br> &nbsp;Mysize:=strlen(Dllname)+1;<br> &nbsp;GetWindowThreadProcessId(FindWindow('Element Client', nil), @h);<br> &nbsp;h:=OpenProcess(PROCESS_ALL_ACCESS, False, h);<br> &nbsp;Parameter:= VirtualAllocEx(h, nil, Mysize, MEM_COMMIT, PAGE_READWRITE);<br> &nbsp;WriteProcessMemory(h, Parameter, Pointer(DllName), MySize, tmp);<br> &nbsp;CreateRemoteThread(h,nil, &nbsp;0, GetProcAddress(GetModuleHandle &nbsp; &nbsp; &nbsp; &nbsp; ('KERNEL32.DLL'), 'LoadLibraryA'), Parameter, 0 , tmp);<br>end;<br><br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> &nbsp; DestroyKeyboardHook;<br>end;<br><br>end.<br><br><br>这个该死的问题已经困扰我n天了。。。谁能帮我解决就给分。 &nbsp;就是一个在游戏中调出窗口的问题。。我这个要用到dll注入。。当然如果有其他的方法也可以!<br><br>QQ 378798095
 
居然没有人知道。。。。。
 
我比你菜鸟多了!!!
 
[:D]看不懂,菜鸟来学习
 
我也是菜鸟
 
受不了你们了。。。
 
往代码里专是没用的,关键是你懂了理原没……
 
嗯,有道理,但是我就是写不了啊。。。<br>还有,什么书比较全点的介绍delphi
 

Similar threads

后退
顶部