怎样修改系统函数?(300!!!)(300分)

  • 主题发起人 主题发起人 chenke
  • 开始时间 开始时间
这个问题已经很老了吧。我把NT下面hook text的Source给贴出来吧:<br><br>下面是数据定义文件:<br>unit U_Def;<br><br>interface<br><br>uses<br>&nbsp; Messages, Windows;<br><br>const<br>&nbsp; WM_MOUSEPT = WM_USER + 1000 + Ord('M') + Ord('P') + Ord('T');<br>&nbsp; MappingFileName = 'Mapping File By Raphael';<br>&nbsp; MaxStringLen = 50;<br>&nbsp; CodeJump = $E9909090;<br><br>type<br>&nbsp; PInt = ^integer;<br>&nbsp; _ExtTextOutA = function (theDC :HDC; nXStart, nYStart :integer; toOptions : Longint; rect : PRect;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpStr :PAnsiChar; nCount :integer; Dx : PInteger):BOOL; stdcall;<br>&nbsp; _PExtTextOutA = ^_ExtTextOutA; &nbsp;<br><br>&nbsp; TLongJump = packed record<br>&nbsp; &nbsp; JmpOp : Cardinal;<br>&nbsp; &nbsp; Addr : Pointer;<br>&nbsp; end;<br><br>&nbsp; TShareMem = packed record<br>&nbsp; &nbsp; hProcWnd : HWND; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The main window of the program<br>&nbsp; &nbsp; hHookWnd : HWND; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The window currently being hooked<br>&nbsp; &nbsp; hWndPseudo : HWND; &nbsp; &nbsp; &nbsp; &nbsp; //The pseudo window used to repaint the other window<br>&nbsp; &nbsp; hProc : THandle; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The process ID of the main program<br>&nbsp; &nbsp; pMouse : TPoint; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //the mouse position<br>&nbsp; &nbsp; fStrMouseQueue : array [0..MaxStringLen] of Char; //mouse info<br>&nbsp; &nbsp; nTimePassed : integer; &nbsp; &nbsp; //the time passed since last time's mousemove<br>&nbsp; &nbsp; bCanSpyNow : Boolean;<br>&nbsp; &nbsp; bHookExtTextOutA : Boolean;<br>&nbsp; &nbsp; pOldExtTextOutA : TLongJump;<br>&nbsp; &nbsp; fStrExtTextOutA : array [0..MaxStringLen] of Char;<br>&nbsp; end;<br>&nbsp; PShareMem = ^TShareMem;<br><br>implementation<br><br>end.<br><br><br><br>Dll的Source(用来hook mouse和截获ExtTextOutA的):<br><br>library dll_HookMouse;<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; Windows,<br>&nbsp; Classes,<br>&nbsp; Messages,<br>&nbsp; Math,<br>&nbsp; Dialogs,<br>&nbsp; U_Def in 'U_Def.pas';<br><br>{$R *.RES}<br><br>var<br>&nbsp; hMouseHook : HHOOK;<br>&nbsp; SpyInstalled : Boolean;<br>&nbsp; fTimerID : Cardinal;<br>&nbsp; pShMem : PShareMem;<br>&nbsp; hMappingFile : THandle;<br><br>function InstallSpy:Boolean; forward;<br>function UnWiseSpy:Boolean; forward;<br><br>function fExtTextOutA(theDC :HDC; nXStart, nYStart :integer; toOptions : Longint; rect : PRect;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpStr :PAnsiChar; nCount :Longint; Dx: PInteger):BOOL; stdcall;<br>var<br>&nbsp; dwBytes, dwCallingProc : DWORD;<br>&nbsp; pOldExtTextOut : _ExtTextOutA;<br>&nbsp; hModuleGDI : THandle;<br>&nbsp; poOri, poDC, poText, poMouse : TPoint;<br>&nbsp; Size : TSize;<br>begin<br>&nbsp; UnWiseSpy;<br><br>&nbsp; GetWindowThreadProcessID(pShMem^.hHookWnd, @dwCallingProc);<br>&nbsp; try<br>&nbsp; &nbsp; if pShMem^.bCanSpyNow and (dwCallingProc &lt;&gt; pShMem^.hProc) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; dwBytes := Min(nCount, MaxStringLen);<br>&nbsp; &nbsp; &nbsp; CopyMemory(@(pShMem^.fStrExtTextOutA), lpStr, dwBytes);<br>&nbsp; &nbsp; &nbsp; //Get lpStr Content<br>&nbsp; &nbsp; &nbsp; //The following codes for get the right text<br>&nbsp; &nbsp; &nbsp; GetDCOrgEx(theDC, poOri);<br>&nbsp; &nbsp; &nbsp; // 取得本窗口设备相关坐标原点的全局逻辑坐标<br>&nbsp; &nbsp; &nbsp; poDC.x := nXStart;<br>&nbsp; &nbsp; &nbsp; poDC.y := nYStart;<br>&nbsp; &nbsp; &nbsp; //<br>&nbsp; &nbsp; &nbsp; LPToDP(theDC, poDC, 1);<br>&nbsp; &nbsp; &nbsp; //全局逻辑坐标转化为设备相关坐标<br>&nbsp; &nbsp; &nbsp; GetCursorPos(poMouse);<br><br>&nbsp; &nbsp; &nbsp; poText.x := poDC.x + poOri.x;<br>&nbsp; &nbsp; &nbsp; poText.y := poDC.y + poOri.y;<br><br>&nbsp; &nbsp; &nbsp; if (GetTextAlign(theDC) and TA_UPDATECP) &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; GetCurrentPositionEx(theDC, @poOri);<br>&nbsp; &nbsp; &nbsp; &nbsp; poText.x := poText.x + poOri.x;<br>&nbsp; &nbsp; &nbsp; &nbsp; poText.y := poText.y + poOri.y;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; GetTextExtentPoint(theDC, lpStr, nCount, Size);<br>&nbsp; &nbsp; &nbsp; // 取得要输出的字符串的实际显示大小<br>&nbsp; &nbsp; &nbsp; if (poMouse.x &gt;= poText.x) and (poMouse.x &lt;= poText.x + Size.cx) and<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(poMouse.y &gt;= poText.y) and (poMouse.y &lt;= poText.y + Size.cy) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; pShMem^.bCanSpyNow := False;<br>&nbsp; &nbsp; &nbsp; &nbsp; pShMem^.nTimePassed := -1;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; pShMem^.fStrExtTextOutA[dwBytes] := Chr(0);<br>&nbsp; &nbsp; &nbsp; FlushViewOfFile(pShMem, 0);<br>&nbsp; &nbsp; &nbsp; PostMessage(pShMem^.hProcWnd, WM_MOUSEPT, 2, 2);<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; if (dwCallingProc = pShMem^.hProc) or pShMem^.bHookExtTextOutA then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; hModuleGDI := GetModuleHandle(PChar('GDI32'));<br>&nbsp; &nbsp; &nbsp; @pOldExtTextOut := GetProcAddress(hModuleGDI, PChar('ExtTextOutA'));<br>&nbsp; &nbsp; &nbsp; Result := pOldExtTextOut(theDC, nXStart, nYStart, toOptions, rect, lpStr, nCount, Dx);<br>&nbsp; &nbsp; end else<br>&nbsp; &nbsp; &nbsp; Result := True;<br><br>&nbsp; except<br>&nbsp; &nbsp; Result := False;<br>&nbsp; end;<br>&nbsp; SpyInstalled := True;<br><br>&nbsp; InstallSpy;<br>end;<br><br>function UnWiseSpy:Boolean;<br>var<br>&nbsp; dwBytesWritten, dwOldProtect : DWORD;<br>&nbsp; pOldExtTextOut : _ExtTextOutA;<br>&nbsp; hModuleGDI : THandle;<br>begin<br>&nbsp; hModuleGDI := GetModuleHandle(PChar('GDI32'));<br>&nbsp; @pOldExtTextOut := GetProcAddress(hModuleGDI, PChar('ExtTextOutA'));<br>&nbsp; if not VirtualProtect(@pOldExtTextOut, SizeOf(TLongJump), PAGE_EXECUTE_READWRITE, @dwOldProtect) then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; if not WriteProcessMemory(GetCurrentProcess, @pOldExtTextOut, @pShMem^.pOldExtTextOutA, SizeOf(TLongJump), dwBytesWritten) then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; if not VirtualProtect(@pOldExtTextOut, SizeOf(TLongJump), dwOldProtect, @dwBytesWritten) then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; Result := True;<br>end;<br><br>function InstallSpy:Boolean;<br>var<br>&nbsp; dwBytesWritten, dwOldProtect : DWORD;<br>&nbsp; ljHere : TLongJump;<br>&nbsp; pOldExtTextOut : _ExtTextOutA;<br>&nbsp; hModuleGDI : THandle;<br>begin<br>&nbsp; hModuleGDI := GetModuleHandle(PChar('GDI32'));<br>&nbsp; @pOldExtTextOut := GetProcAddress(hModuleGDI, PChar('ExtTextOutA'));<br>&nbsp; if not VirtualProtect(@pOldExtTextOut, SizeOf(TLongJump), PAGE_EXECUTE_READWRITE, @dwOldProtect) then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; ljHere.JmpOp := CodeJump;<br>&nbsp; ljHere.Addr := Pointer( Cardinal(@fExtTextOutA) - Cardinal(@pOldExtTextOut) - SizeOf(TLongJump) );<br>&nbsp; if not WriteProcessMemory(GetCurrentProcess, @pOldExtTextOut, @ljHere, SizeOf(TLongJump), dwBytesWritten) then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; if not VirtualProtect(@pOldExtTextOut, SizeOf(TLongJump), dwOldProtect, @dwBytesWritten) then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; Result := True;<br>end;<br><br>function MouseHookProc(nCode : integer; wPar : WParam; lPar : LParam) : lResult; stdcall;<br>var<br>&nbsp; pMouseInf : TMouseHookStruct;<br>begin<br>&nbsp; if (not SpyInstalled) and pShMem^.bHookExtTextOutA then<br>&nbsp; &nbsp; InstallSpy;<br><br>&nbsp; if SpyInstalled and (not pShMem^.bHookExtTextOutA) then<br>&nbsp; begin<br>&nbsp; &nbsp; UnwiseSpy;<br>&nbsp; &nbsp; SpyInstalled := False;<br>&nbsp; end;<br><br>&nbsp; pShMem^.nTimePassed := 0 ;<br><br>&nbsp; if (nCode &gt;= 0) and (wPar = WM_MOUSEMOVE) then<br>&nbsp; begin<br>&nbsp; &nbsp; pMouseInf := (PMouseHookStruct(lPar))^;<br>&nbsp; &nbsp; if (pShMem^.pMouse.x &lt;&gt; pMouseInf.pt.x) or<br>&nbsp; &nbsp; &nbsp; &nbsp;(pShMem^.pMouse.y &lt;&gt; pMouseInf.pt.y) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if nCode = HC_NOREMOVE then<br>&nbsp; &nbsp; &nbsp; &nbsp; pShMem^.fStrMouseQueue := 'Not removed from the queue'<br>&nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//then HC_ACTION<br>&nbsp; &nbsp; &nbsp; &nbsp; pShMem^.fStrMouseQueue := 'Removed from the queue';<br>&nbsp; &nbsp; &nbsp; pShMem^.pMouse := pMouseInf.pt;<br>&nbsp; &nbsp; &nbsp; pShMem^.hHookWnd := pMouseInf.hwnd;<br>&nbsp; &nbsp; &nbsp; PostMessage(pShMem^.hProcWnd, WM_MOUSEPT, 1, 1); //1 indicates mouse message<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br><br>&nbsp; FlushViewOfFile(pShMem, 0);<br>&nbsp; Result := CallNextHookEx(hMouseHook, nCode, wPar, lPar);<br>end;<br><br>procedure fOnTimer(theWnd : HWND; msg, idTimer : Cardinal; dwTime : DWORD);far pascal; //CallBack Type<br>begin<br>&nbsp; if pShMem^.nTimePassed = -1 then<br>&nbsp; &nbsp; Exit;<br><br>&nbsp; pShMem^.nTimePassed := pShMem^.nTimePassed + 1;<br>&nbsp; if pShMem^.nTimePassed &gt; 21 then<br>&nbsp; begin<br>&nbsp; &nbsp; pShMem^.nTimePassed := 21;<br>&nbsp; &nbsp; FlushViewOfFile(pShMem, 0);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; if pShMem^.nTimePassed &gt; 20 then<br>&nbsp; begin<br>&nbsp; &nbsp; pShMem^.bCanSpyNow := True;<br>&nbsp; &nbsp; FlushViewOfFile(pShMem, 0);<br>&nbsp; &nbsp; SetWindowPos(pShMem^.hWndPseudo, HWND_TOPMOST, pShMem^.pMouse.x, pShMem^.pMouse.y, 1, 8, SWP_NOACTIVATE or SWP_SHOWWINDOW);<br>&nbsp; &nbsp; ShowWindow(pShMem^.hWndPseudo , SW_HIDE);<br>&nbsp; end;<br>end;<br><br>function MouseWndProc(theWnd : HWND; theMess : Cardinal; wPar : wParam; lPar : lParam): LResult;stdcall;<br>begin<br>&nbsp; case theMess of<br>&nbsp; &nbsp; WM_CLOSE :<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DestroyWindow(theWnd);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostQuitMessage(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := DefWindowProc(theWnd, theMess, wPar, lPar);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; end;<br>&nbsp; Result := 0;<br>end;<br><br>function InstallMouseHook(hInst : LongWord):Boolean;<br>begin<br>&nbsp; hMouseHook := SetWindowsHookEx(WH_MOUSE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MouseHookProc,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetModuleHandle(PChar('dll_HookMouse')),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0);<br>&nbsp; if hMouseHook = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; pShMem^.hWndPseudo := CreateWindowEx(WS_EX_TOPMOST or WS_EX_TOOLWINDOW,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'ZL_MOUSE_WND_PSEUDO',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'ZL_MOUSE_WND_PSEUDO',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WS_CLIPSIBLINGS or WS_POPUP ,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, 0, 1, 8,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hInst,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil);<br>&nbsp; ShowWindow(pShMem^.hWndPseudo, SW_HIDE);<br>&nbsp; UpdateWindow(pShMem^.hWndPseudo);<br>&nbsp; fTimerID := SetTimer(0, 0, 10, @fOnTimer);<br>&nbsp; FlushViewOfFile(pShMem, 0);<br>&nbsp; Result := True;<br>end;<br><br>function UnWiseMouseHook:Boolean;<br>begin<br>&nbsp; KillTimer(0, fTimerID);<br>&nbsp; DestroyWindow(pShMem^.hWndPseudo);<br>&nbsp; if SpyInstalled then<br>&nbsp; &nbsp; UnWiseSpy;<br><br>&nbsp; pShMem^.bHookExtTextOutA := False;<br>&nbsp; FlushViewOfFile(pShMem, 0);<br>&nbsp; Result := UnHookWindowsHookEx(hMouseHook);<br>end;<br><br>procedure DllEntry(nReason : integer);<br>begin<br>&nbsp; case nReason Of<br>&nbsp; &nbsp; DLL_PROCESS_ATTACH:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; hMappingFile := CreateFileMapping($FFFFFFFF,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PAGE_READWRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SizeOf(TShareMem),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PChar(MappingFileName));<br>&nbsp; &nbsp; &nbsp; &nbsp; if hMappingFile&lt;&gt;0 then //if h..=0 , the work is done by OS<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pShMem := PShareMem( MapViewOfFile(hMappingFile,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_MAP_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, //hi_order offset where mapping begins<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, //lo_order offset where mapping begins<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0) ); //Size of the mapping<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if pShMem = nil then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hMappingFile);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('Cannot create the Share Memory Block!');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('Cannot create the Share Memory Block!');<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; DLL_PROCESS_DETACH:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; UnwiseSpy;<br>&nbsp; &nbsp; &nbsp; &nbsp; UnMapViewOfFile(pShMem);<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hMappingFile);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; else;<br>&nbsp; end;<br>end;<br><br>exports<br>&nbsp; MouseWndProc,<br>&nbsp; InstallMouseHook,<br>&nbsp; UnWiseMouseHook;<br><br>begin<br>&nbsp; DllProc := @DllEntry;<br>&nbsp; DllEntry(DLL_PROCESS_ATTACH);<br>end.<br><br>下面是EXE的Source:<br>unit U_MouseHook;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, U_Def;<br><br>type<br>&nbsp; TF_MouseHook = class(TForm)<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; e_MouseInfo: TEdit;<br>&nbsp; &nbsp; btn_HookMouse: TButton;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; e_ExtTextOutA: TEdit;<br>&nbsp; &nbsp; btn_HookExtTextOutA: TButton;<br>&nbsp; &nbsp; procedure btn_HookMouseClick(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure btn_HookExtTextOutAClick(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; fWndClosed, fbMouseHookInstalled : Boolean;<br>&nbsp; &nbsp; hMapObj : THandle;<br>&nbsp; &nbsp; pShMem : PShareMem;<br>&nbsp; &nbsp; procedure getMouseInfo(var theMess:TMessage); message WM_MOUSEPT;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>function InstallMouseHook(hInst : LongWord) : Boolean; external 'dll_HookMouse.dll';<br>function UnWiseMouseHook : Boolean; external 'dll_HookMouse.dll';<br>function MouseWndProc(theWnd : HWND; theMess : Cardinal; wPar : wParam; lPar : lParam): LResult; stdcall; external 'dll_HookMouse.dll';<br><br>var<br>&nbsp; F_MouseHook: TF_MouseHook;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TF_MouseHook.btn_HookMouseClick(Sender: TObject);<br>begin<br>&nbsp; if not fbMouseHookInstalled then<br>&nbsp; begin<br>&nbsp; &nbsp; fbMouseHookInstalled := InstallMouseHook(hInstance);<br>&nbsp; &nbsp; if fbMouseHookInstalled then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; btn_HookMouse.Caption := 'Stop!';<br>&nbsp; &nbsp; &nbsp; btn_HookExtTextOutA.Enabled := True;<br>&nbsp; &nbsp; end &nbsp;else<br>&nbsp; &nbsp; &nbsp; ShowMessage('Cannot hook mouse!');<br>&nbsp; end else<br>&nbsp; begin<br>&nbsp; &nbsp; fbMouseHookInstalled := not UnWiseMouseHook;<br>&nbsp; &nbsp; if not fbMouseHookInstalled then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; btn_HookMouse.Caption := 'Hook Mouse';<br>&nbsp; &nbsp; &nbsp; btn_HookExtTextOutA.Enabled := False;<br>&nbsp; &nbsp; &nbsp; btn_HookExtTextOutA.Caption := 'Hook ExtTextOutA';<br>&nbsp; &nbsp; &nbsp; pShMem^.bHookExtTextOutA := False;<br>&nbsp; &nbsp; &nbsp; FlushViewOfFile(pShMem, 0);<br>&nbsp; &nbsp; end else<br>&nbsp; &nbsp; &nbsp; ShowMessage('Cannot unhook mouse!');<br>&nbsp; end;<br>end;<br><br>procedure TF_MouseHook.getMouseInfo(var theMess : TMessage);<br>begin<br>&nbsp; if fWndClosed then<br>&nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; <br>&nbsp; if theMess.LParam = 1 then //Get the Mouse info to display<br>&nbsp; &nbsp; e_MouseInfo.Text := 'X:' + IntToStr(pShMem^.pMouse.x) + ' ' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Y:' + IntToStr(pShMem^.pMouse.y) + ' ' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'HWND:0x' + IntToHex(pShMem^.hHookWnd, 8) + ' ' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pShMem^.fStrMouseQueue<br>&nbsp; else if theMess.LParam = 2 then //Get the ExtTextOutA display<br>&nbsp; &nbsp; e_ExtTextOutA.Text := pShMem^.fStrExtTextOutA;<br>end;<br><br>procedure TF_MouseHook.FormCreate(Sender: TObject);<br>var<br>&nbsp; hModuleGDI : THandle;<br>&nbsp; wc : TWndClass;<br>begin<br>&nbsp; hMapObj := OpenFileMapping(FILE_MAP_WRITE, &nbsp; &nbsp; //Get full access of the mapping file<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;False, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Not inheritable<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LPCTSTR(MappingFileName)); &nbsp; //Name of the mapping file<br>&nbsp; if hMapObj = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('Cannot locate the Share Memory Block!');<br>&nbsp; &nbsp; Halt;<br>&nbsp; end;<br><br>&nbsp; pShMem := PShareMem( MapViewOfFile(hMapObj,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_MAP_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, //hi_order offset where mapping begins<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, //lo_order offset where mapping begins<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0) ); //Size of the mapping<br>&nbsp; if pShMem = nil then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('Map File Mapping Failed! Error '+ IntToStr(GetLastError));<br>&nbsp; &nbsp; CloseHandle(hMapObj);<br>&nbsp; &nbsp; Halt;<br>&nbsp; end;<br><br>&nbsp; FillChar(pShMem^, SizeOf(TShareMem), 0);<br>&nbsp; hModuleGDI := GetModuleHandle(PChar('GDI32'));<br>&nbsp; if hModuleGDI = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('Cannot get module GDI32! Error ' + IntToStr(GetLastError));<br>&nbsp; &nbsp; UnmapViewOfFile(pShMem);<br>&nbsp; &nbsp; CloseHandle(hMapObj);<br>&nbsp; &nbsp; Halt;<br>&nbsp; end;<br><br>&nbsp; CopyMemory(@pShMem^.pOldExtTextOutA, GetProcAddress(hModuleGDI, PChar('ExtTextOutA')), SizeOf(TLongJump));<br>&nbsp; pShMem^.hProcWnd := Self.Handle;<br>&nbsp; GetWindowThreadProcessID(Self.Handle, @pShMem^.hProc);<br>&nbsp; pShMem^.bHookExtTextOutA := False;<br>&nbsp; pShMem^.bCanSpyNow := False;<br>&nbsp; fbMouseHookInstalled := False;<br>&nbsp; FlushViewOfFile(pShMem, 0);<br><br>&nbsp; wc.style &nbsp; &nbsp; &nbsp; &nbsp; := 0;<br>&nbsp; wc.lpfnWndProc &nbsp; := TFNWndProc(@MouseWndProc);<br>&nbsp; wc.cbClsExtra &nbsp; &nbsp;:= 0;<br>&nbsp; wc.cbWndExtra &nbsp; &nbsp;:= 0;<br>&nbsp; wc.hInstance &nbsp; &nbsp; := HInstance;<br>&nbsp; wc.hIcon &nbsp; &nbsp; &nbsp; &nbsp; := 0 ;<br>&nbsp; wc.hCursor &nbsp; &nbsp; &nbsp; := 0 ;<br>&nbsp; wc.hbrBackground := 0 ;<br>&nbsp; wc.lpszMenuName &nbsp;:= nil;<br>&nbsp; wc.lpszClassName := 'ZL_MOUSE_WND_PSEUDO';<br>&nbsp; // register the class for the main window<br>&nbsp; Windows.RegisterClass(wc);<br>&nbsp; fWndClosed := False;<br>end;<br><br>procedure TF_MouseHook.FormClose(Sender: TObject;<br>&nbsp; var Action: TCloseAction);<br>begin<br>&nbsp; if fbMouseHookInstalled then<br>&nbsp; &nbsp; UnWiseMouseHook;<br>&nbsp; UnMapViewOfFile(pShMem);<br>&nbsp; CloseHandle(hMapObj);<br>&nbsp; Windows.UnRegisterClass('ZL_MOUSE_WND_PSEUDO', hInstance);<br>&nbsp; fWndClosed := True;<br>end;<br><br>procedure TF_MouseHook.btn_HookExtTextOutAClick(Sender: TObject);<br>begin<br>&nbsp; if pShMem^.bHookExtTextOutA then<br>&nbsp; &nbsp; btn_HookExtTextOutA.Caption := 'Hook ExtTextOutA'<br>&nbsp; else<br>&nbsp; &nbsp; btn_HookExtTextOutA.Caption := 'Stop!';<br><br>&nbsp; pShMem^.bHookExtTextOutA := not pShMem^.bHookExtTextOutA;<br>&nbsp; FlushViewOfFile(pShMem, 0);<br>end;<br>//RaiseLastWin32Error can be used to create a GetLastError<br>//Message<br><br>end.<br><br>
 
这个东西是从GUIHook95和GUIhookNT下面转过来的。<br>但是由于不用Delphi1.0已经很久了,所以没有工夫去作<br>16位下面的东西了。<br><br>看大家这么热情,就把这个TaoChen的C程序作化为Delphi<br>的把。
 
很深,看来屏幕取词,是很多地方都要用的技术啊。我关注。正在学,所以没什么好的建议
 
接受答案了.
 
API HOOK、屏幕取词的完整解决方案见我的《delphi深入windows核心编程》一书,<br>解决了IE、win98下的高技术难题,支持windows98/2000/xp,<br>我的主页http://wenjinshan.yeah.net
 
API HOOK、屏幕取词的完整解决方案见我的《delphi深入windows核心编程》一书,<br>解决了IE、win98下的高技术难题,支持windows98/2000/xp,<br>我的主页http://wenjinshan.yeah.net
 
后退
顶部