{*******************************************************} { } { WindowCatchWndMsg } { } { Copyright (C) 2012 sunk } { } {*******************************************************} unit WindowCatchWndMsg; interface uses System.SysUtils, System.Classes, Winapi.Windows, Winapi.Messages, Tocsg.CommonData, Tocsg.DllEntry, Tocsg.Trace; /////////////////////////////////////////////////////////////////////////////////////// // Àü¿ª ÈÄÅ· DLL ¸¸µé¶§ ÁÖÀÇ »çÇ× 14_1027 16:43:37 sunk // ¿¹Àü¿¡ ÄÄÆÄÀÏÇØ¼­ ÀߵǴø Àü¿ª ÈÄÅ· DLLÀ» »õ·Î ÄÄÆÄÀÏ ÇØ¼­ »ç¿ë ÇÏ´ÂÁß // ·Îµå±îÁö ÇØ¼­ ÈÄÅ·±â´ÉÀ» Àß ÀÌ¿ëÇϴµ¥ ÇØÁ¦ÇÒ¶§ ÈÄÄ¿°¡ °É·È´ø // ÇÁ·Î±×·¥ÀÌ µØÁö´ø ¹®Á¦°¡ ÀÖ¾ú´Ù. (¹°·Ð ¿¹Àü ¹öÀüÀº Àßµ¹¾Æ°¡°í..) // ÇØ°á(»ðÁú)À» ÇÏ´øÁß ´«¿¡ ¶ç´Â Â÷ÀÌÁ¡ÀÌ »ý¼ºµÈ DLL Å©±â°¡ ¸¹ÀÌ ´Þ¶ú´Âµ¥ // Sunk.Debug¿¡ ¾Æ¹« »ý°¢¾øÀÌ Ãß°¡ÇÑ Sunk.Smart, Sunk.Path ¶§¹®¿¡ // Å©±â°¡ ´Ã¾î³ª±âµµ Çß°í, Àü¿ª ÈÄÄ¿·Î½á »ç¿ëÇÏ¸é ¾ÈµÇ´Â API°¡ Æ÷ÇÔ µÇ¾î ÀÖ¾ú³ª º¸´Ù // Sunk.Debug¿¡¼­ Sunk.Smart, Sunk.Path À̰ŠµÎ°³ »©´Ï±ñ ¿ë·®µµ È®ÁÙ°í ¿¹Àüó·³ ÀßµÊ.. /////////////////////////////////////////////////////////////////////////////////////// const WM_WNDHOOK_RELOAD = WM_USER + 9630; WM_WNDHOOK_NOTIFY = WM_USER + 9633; WM_MESSAGEHOOK_NOTIFY = WM_USER + 9636; WND_STATE_ATTACH_HOOK = 1; WND_STATE_DETACH_HOOK = 2; WND_STATE_ACTIVATE = 3; WND_STATE_WINDOW_MIN = 4; WND_STATE_WINDOW_MAX = 5; WND_STATE_WINDOW_MOVESIZE = 6; WND_STATE_REDRAW_TITLE = 7; WND_STATE_CREATE_MAIN = 8; WND_STATE_DESTROY_MAIN = 9; WND_STATE_WINDOW_NORMAL = 10; WND_STATE_ACTIVATE2 = 11; // for CBT 2014-04-08 MSG_WM_COPY = 21; MSG_WM_CUT = 22; MSG_WM_PASTE = 23; MSG_WM_RENDERFORMAT = 24; MSG_WM_RENDERALLFORMATS = 25; MSG_WM_CLOSE = 26; MSG_WM_QUIT = 27; MSG_WM_DESTROY = 28; MSG_WM_SETTEXT = 29; type THookState = (hsFree, hsHooking, hsReload, hsFinish); PSharedData = ^TSharedData; TSharedData = packed record hRcvWnd: ULONGLONG; dwLastInput: DWORD; // HookState: THookState; end; // PWndActiveStruct = ^TWndActiveStruct; // TWndActiveStruct = packed record // nCode: Integer; // hWindow: HWND; // end; // PHWND = ^HWND; TWindowCatchWndMsg = class(TKuDllEntry) private SharedData_: TTgFileMapping; hCbtHook_, hShellHook_, hMessageHook_, hCallWndHook_, hMouseHook_, hKeyboardHook_: HHook; dtCreate_: TDateTime; dwLastInputTickCount_: DWORD; Trace_: TTgTrace; function InstallWindowActiveHook: Integer; function UnInstallWindowActiveHook: Integer; public Constructor Create; Destructor Destroy; override; procedure UpdateLastInput; function SendWndHookMsg(wState: WORD; hWindow: HWND = 0): Boolean; function SendMsgHookSimple(dwMsg: DWORD; hWindow: HWND): Boolean; property CBTHook: HHook read hCbtHook_; property ShellHook: HHook read hShellHook_; property MessageHook: HHook read hMessageHook_; property CallWndHook: HHook read hCallWndHook_; property MouseHook: HHook read hMouseHook_; property KeyboardHook: HHook read hKeyboardHook_; property CreateDateTime: TDateTime read dtCreate_; property SharedData: TTgFileMapping read SharedData_; end; function process_WH_CBT(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; function process_WH_SHELL(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; function process_WH_GETMESSAGE(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; function process_WH_CALLWNDPROC(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; function process_WH_MOUSE(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; function process_WH_KEYBOARD(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; function InstallWindowActiveHook: Integer; export; stdcall; // µ¿½Ã ½ÇÇà ½Ã ÈÄÅ· °øÀ¯¸ÊÆÄÀÏÀÌ Áߺ¹µÇ±â ¶§¹®¿¡ ÀÌ·¸°Ô º¯°æ ÇÔ 16_0106 09:48:04 sunk function UnInstallWindowActiveHook: Integer; export; stdcall; procedure OutLog(const sLog: String); overload; procedure OutLog(const Format: string; const Args: array of const); overload; implementation uses Tocsg.KERNEL32, DefineWndMon; //uses // Tocsg.Path; // À̰ŠÀý´ë Æ÷ÇÔ ½ÃÄѼ± ¾ÈµÈ´Ù 16_0106 10:36:34 sunk var _WindowActiveHook: TWindowCatchWndMsg = nil; procedure OutLog(const sLog: String); begin {$IFDEF DEBUG} OutputDebugString(PChar(sLog)); {$ENDIF} end; procedure OutLog(const Format: string; const Args: array of const); var str: String; begin {$IFDEF DEBUG} FmtStr(str, Format, Args); OutLog(str); {$ENDIF} end; function GetTitle(h: HWND): String; var str: array [0..255] of Char; begin GetWindowText(h, str, 256); Result := str; end; function process_WH_CBT(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; var pCreateWnd: PCBTCreateWnd; // pActivateWnd: PCBTActivateStruct; pMouse: PMouseHookStruct; begin if Assigned(_WindowActiveHook) then begin try try if nCode >= HC_ACTION then case nCode of HCBT_CREATEWND : // À©µµ¿ì°¡ »ý¼ºµÈ °æ¿ì´Ù, WM_CREATE, WM_NCCREATE ÇÁ·Î½ÃÀú°¡ ¾ÆÁ÷ ¼öÇàµÇÁö ¾ÊÀº ´Ü°è begin // À©µµ¿ì »ý¼º·Î±×´Â ¸ÞÀθ¸ ³²±âµµ·Ï ÇÔ. 2012-05-16 sunk // if gWindowActiveHook.OwnerWindow <> wParam then // begin // pCreateWnd := PCBTCreateWnd(lParam); // if pCreateWnd.lpcs.lpszName <> '' then // OutLog('[%s] process_WH_CBT >> HCBT_CREATEWND >> Name = %s', [gWindowActiveHook.ModuleName, pCreateWnd.lpcs.lpszName]); // end; end; HCBT_DESTROYWND : ; // À©µµ¿ì°¡ ÆÄ±«µÈ °æ¿ì´Ù HCBT_ACTIVATE : // À©µµ¿ì°¡ Ȱ¼ºÈ­ µÈ °æ¿ì´Ù begin _WindowActiveHook.SendWndHookMsg(WND_STATE_ACTIVATE2, wParam); // ¸·À½ 16_0811 09:54:17 sunk { gWindowActiveHook.hMain_ := wParam; gWindowActiveHook.SendMsg(WM_WAH_ACTIVATE, wParam); // pActivateWnd := PCBTActivateStruct(lParam); // OutLog('[%s] process_WH_CBT >> HCBT_ACTIVATE >> Mouse = %d >> Title = %s', [gWindowActiveHook.ModuleName, Integer(pActivateWnd.fMouse), GetTitle(wParam)]); OutLog('[%s] process_WH_CBT >> HCBT_ACTIVATE >> Title = %s', [gWindowActiveHook.ModuleName, GetTitle(wParam)]); } end; HCBT_CLICKSKIPPED : // ¸¶¿ì½º ¸Þ½ÃÁö°¡ ½Ã½ºÅÛ ¸Þ½ÃÁö¿¡¼­ Á¦°ÅµÈ °æ¿ì´Ù begin // pMouse := PMouseHookStruct(lParam); // OutLog('[%s] process_WH_CBT >> HCBT_CLICKSKIPPED >> HitTestCode = %d >> Title = %s', [gWindowActiveHook.ModuleName, pMouse.wHitTestCode, GetTitle(pMouse.hwnd)]); end; HCBT_KEYSKIPPED : // Űº¸µå ¸Þ½ÃÁö°¡ ½Ã½ºÅÛ ¸Þ½ÃÁö Å¥¿¡¼­ Á¦°ÅµÈ °æ¿ì´Ù begin // OutLog('[%s] process_WH_CBT >> HCBT_KEYSKIPPED >> Title = %s', [gWindowActiveHook.ModuleName, GetTitle(wParam)]); end; HCBT_MINMAX : // À©µµ¿ì°¡ ÃÖ¼ÒÈ­/ÃÖ´ëÈ­°¡ µÈ °æ¿ì´Ù begin case lParam of SW_RESTORE : _WindowActiveHook.SendWndHookMsg(WND_STATE_WINDOW_NORMAL, wParam); SW_MINIMIZE : _WindowActiveHook.SendWndHookMsg(WND_STATE_WINDOW_MIN, wParam); SW_MAXIMIZE : _WindowActiveHook.SendWndHookMsg(WND_STATE_WINDOW_MAX, wParam); end; OutLog('[%s] process_WH_CBT >> HCBT_MINMAX >> Title = %s', [_WindowActiveHook.ModuleName, GetTitle(wParam)]); end; HCBT_MOVESIZE : // À©µµ¿ì°¡ ¿Å°ÜÁö°Å³ª Å©±â°¡ º¯°æµÈ °æ¿ì´Ù begin _WindowActiveHook.SendWndHookMsg(WND_STATE_WINDOW_MOVESIZE, wParam); OutLog('[%s] process_WH_CBT >> HCBT_MOVESIZE >> Title = %s', [_WindowActiveHook.ModuleName, GetTitle(wParam)]); end; HCBT_QS : ; // ½Ã½ºÅÛ ¸Þ½ÃÁö Å¥·ÎºÎÅÍ WM_QUEUESYNC ¸Þ½ÃÁö¸¦ Àü´Þ¹ÞÀº °æ¿ì´Ù HCBT_SETFOCUS : // À©µµ¿ì°¡ Űº¸µå Æ÷Ä¿½º¸¦ °¡Áö°Ô µÈ °æ¿ì´Ù begin // OutLog('[%s] process_WH_CBT >> HCBT_SETFOCUS >> Title = %s, Pre = %s', [gWindowActiveHook.ModuleName, GetTitle(wParam), GetTitle(lParam)]); end; HCBT_SYSCOMMAND : ; // ½Ã½ºÅÛ ¸í·É(WM_SYSCOMMAND)ÀÌ ¼öÇàµÇ´Â °æ¿ì´Ù end; except exit; end; finally Result := CallNextHookEx(_WindowActiveHook.CBTHook, nCode, wParam, lParam); end; end else Result := 0;//CallNextHookEx(0, nCode, wParam, lParam); end; function process_WH_SHELL(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin if Assigned(_WindowActiveHook) then begin try try if nCode >= HC_ACTION then case nCode of HSHELL_ACCESSIBILITYSTATE : ; // Windows 2000/XP: accessibility »óŰ¡ º¯°æµÇ¾úÀ½ HSHELL_APPCOMMAND : ; // Windows 2000/XP: »ç¿ëÀÚÀÇ ÀÔ·Â À̺¥Æ®¿¡ ÀÇÇØ¼­ WM_APPCOMMAND °¡ ¹ß»ýÇÑ °æ¿ì´Ù HSHELL_ACTIVATESHELLWINDOW : ; // ½© ¸ÞÀÎ À©µµ¿ì°¡ Ȱ¼ºÈ­ µÇ¾î¾ß ÇÏ´Â °æ¿ì´Ù HSHELL_GETMINRECT : // À©µµ¿ì°¡ ÃÖ¼ÒÈ­/ÃÖ´ëÈ­µÈ °æ¿ì´Ù begin OutLog('[%s] process_WH_SHELL >> HSHELL_GETMINRECT', [_WindowActiveHook.ModuleName]); end; HSHELL_LANGUAGE : ; // Űº¸µå ¾ð¾î°¡ º¯°æµÇ°Å³ª »õ·Î¿î Űº¸µå ·¹À̾ƿôÀÌ ·ÎµåµÈ °æ¿ì´Ù HSHELL_REDRAW : // ŽºÅ©¹Ù¿¡ ÀÖ´Â À©µµ¿ì ŸÀÌÆ²ÀÌ »õ·Î ±×·ÁÁö´Â °æ¿ì´Ù begin _WindowActiveHook.SendWndHookMsg(WND_STATE_REDRAW_TITLE, wParam); OutLog('[%s] process_WH_SHELL >> HSHELL_REDRAW >> Title = %s', [_WindowActiveHook.ModuleName, GetTitle(wParam)]); end; HSHELL_TASKMAN : // »ç¿ëÀÚ°¡ ŽºÅ© ¸®½ºÆ®¸¦ ¼±ÅÃÇÑ °æ¿ì´Ù. Å×½ºÆ®ÇØ º» °á°ú Ctrl + Esc ۸¦ ´©¸¥ °æ¿ì ÈÅ ÇÁ·Î½ÃÀú°¡ È£ÃâµÇ¾ú´Ù. ½ÃÀÛ ¹öưÀ» ´­·¶À» ¶§¿£ È£ÃâµÇÁö ¾Ê´Â´Ù begin OutLog('[%s] process_WH_SHELL >> HSHELL_TASKMAN', [_WindowActiveHook.ModuleName]); end; HSHELL_WINDOWACTIVATED : // ž ·¹º§ À©µµ¿ìÀÇ È°¼ºÈ­ »óŰ¡ º¯°æµÈ °æ¿ì´Ù begin OutLog('[%s] process_WH_CBT >> HCBT_ACTIVATE >> Title = %s', [_WindowActiveHook.ModuleName, GetTitle(wParam)]); _WindowActiveHook.SendWndHookMsg(WND_STATE_ACTIVATE, wParam); end; HSHELL_WINDOWCREATED : // ž ·¹º§ À©µµ¿ì°¡ »ý¼ºµÈ °æ¿ì´Ù. ÀÌ ÈÅÀÌ È£ÃâµÇ´Â ½ÃÁ¡¿¡ À©µµ¿ì´Â »ý¼ºµÈ »óÅ´٠begin _WindowActiveHook.SendWndHookMsg(WND_STATE_CREATE_MAIN, wParam); OutLog('[%s] process_WH_SHELL >> HSHELL_WINDOWCREATED >> Start = %s', [_WindowActiveHook.ModuleName, DateTimeToStr(_WindowActiveHook.CreateDateTime)]); end; HSHELL_WINDOWDESTROYED : // ž ·¹º§ À©µµ¿ì°¡ ÆÄ±«µÈ °æ¿ì´Ù. ÀÌ ÈÅÀÌ È£ÃâµÇ´Â ½ÃÁ¡¿¡ À©µµ¿ì´Â Á¸ÀçÇÑ´Ù begin _WindowActiveHook.SendWndHookMsg(WND_STATE_DESTROY_MAIN, wParam); OutLog('[%s] process_WH_SHELL >> HSHELL_WINDOWDESTROYED >> Start = %s, End = %s', [_WindowActiveHook.ModuleName, DateTimeToStr(_WindowActiveHook.CreateDateTime), DateTimeToStr(now)]); end; HSHELL_WINDOWREPLACED : ; // Windows XP: ž ·¹º§ À©µµ¿ì°¡ ´ëü(replaced)µÈ °æ¿ì´Ù end; except exit; end; finally Result := CallNextHookEx(_WindowActiveHook.ShellHook, nCode, wParam, lParam); end; end else Result := 0;//CallNextHookEx(0, nCode, wParam, lParam); end; function process_WH_GETMESSAGE(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; begin if Assigned(_WindowActiveHook) then begin try // try // if nCode >= 0 then // begin // case PMSG(lParam).message of // WM_COPY : _WindowActiveHook.SendMsgHookSimple(MSG_WM_COPY); // WM_CUT : _WindowActiveHook.SendMsgHookSimple(MSG_WM_CUT); // WM_PASTE : _WindowActiveHook.SendMsgHookSimple(MSG_WM_PASTE); // WM_RENDERFORMAT : _WindowActiveHook.SendMsgHookSimple(MSG_WM_RENDERFORMAT); // WM_RENDERALLFORMATS : _WindowActiveHook.SendMsgHookSimple(MSG_WM_RENDERALLFORMATS); // end; // end; // except // exit; // end; finally Result := CallNextHookEx(_WindowActiveHook.MessageHook, nCode, wParam, lParam); end; end else Result := 0;//CallNextHookEx(0, nCode, wParam, lParam); end; function process_WH_CALLWNDPROC(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; begin if Assigned(_WindowActiveHook) then begin try try if nCode >= 0 then case PCWPSTRUCT(lParam).message of WM_COPY : _WindowActiveHook.SendMsgHookSimple(MSG_WM_COPY, PCWPSTRUCT(lParam).hwnd); WM_CUT : _WindowActiveHook.SendMsgHookSimple(MSG_WM_CUT, PCWPSTRUCT(lParam).hwnd); WM_PASTE : _WindowActiveHook.SendMsgHookSimple(MSG_WM_PASTE, PCWPSTRUCT(lParam).hwnd); WM_RENDERFORMAT : _WindowActiveHook.SendMsgHookSimple(MSG_WM_RENDERFORMAT, PCWPSTRUCT(lParam).hwnd); WM_RENDERALLFORMATS : _WindowActiveHook.SendMsgHookSimple(MSG_WM_RENDERALLFORMATS, PCWPSTRUCT(lParam).hwnd); // WM_CLOSE : _WindowActiveHook.SendMsgHookSimple(MSG_WM_CLOSE, PCWPSTRUCT(lParam).hwnd); // WM_QUIT : _WindowActiveHook.SendMsgHookSimple(MSG_WM_QUIT, PCWPSTRUCT(lParam).hwnd); WM_DESTROY : _WindowActiveHook.SendMsgHookSimple(MSG_WM_DESTROY, PCWPSTRUCT(lParam).hwnd); // À©µµ¿ì, Å©·Ò ¼­ºê Æû Á¾·áµÉ¶© ÀÌ°É »ç¿ëÇϴ±º 16_0203 15:19:17 sunk WM_SETTEXT : _WindowActiveHook.SendMsgHookSimple(MSG_WM_SETTEXT, PCWPSTRUCT(lParam).hwnd); end; except exit; end; finally Result := CallNextHookEx(_WindowActiveHook.MessageHook, nCode, wParam, lParam); end; end else Result := 0;//CallNextHookEx(0, nCode, wParam, lParam); end; function process_WH_MOUSE(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; begin if Assigned(_WindowActiveHook) then begin try try if nCode >= HC_ACTION then case wParam of WM_LBUTTONDOWN, WM_RBUTTONDOWN, WM_LBUTTONDBLCLK, WM_RBUTTONDBLCLK, WM_MBUTTONDOWN, WM_MBUTTONDBLCLK, WM_NCLBUTTONDOWN, WM_NCRBUTTONDOWN, WM_NCMBUTTONDOWN, // WM_MOUSEHOVER, // WM_MOUSELEAVE, WM_MOUSEWHEEL : _WindowActiveHook.UpdateLastInput; end; except exit; end; finally Result := CallNextHookEx(_WindowActiveHook.MouseHook, nCode, wParam, lParam); end; end else Result := 0;//CallNextHookEx(0, nCode, wParam, lParam); end; function process_WH_KEYBOARD(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; var bPreDown, bKeyDown: Boolean; begin if Assigned(_WindowActiveHook) then begin try try if nCode >= HC_ACTION then begin bPreDown := (lParam and $40000000) <> 0; // ۸¦ °è¼Ó ´©¸£°í ÀÖ´Â »óÅÂÀΰ¡ ¾Æ´Ñ°¡ bKeyDown := (lParam and $80000000) = 0; // Ű ´Ù¿îÀΰ¡ ¾Æ´Ñ°¡ if not bPreDown and bKeyDown then _WindowActiveHook.UpdateLastInput; end; except exit; end; finally Result := CallNextHookEx(_WindowActiveHook.KeyboardHook, nCode, wParam, lParam); end; end else Result := 0;//CallNextHookEx(0, nCode, wParam, lParam); end; function InstallWindowActiveHook: Integer; begin Result := -1; if Assigned(_WindowActiveHook) then Result := _WindowActiveHook.InstallWindowActiveHook; end; function UnInstallWindowActiveHook: Integer; begin Result := -1; if Assigned(_WindowActiveHook) then begin // if _WindowActiveHook.SharedData.IsAvailable then // _WindowActiveHook.SharedData.Data.HookState := hsFinish; Result := _WindowActiveHook.UnInstallWindowActiveHook; end; end; { TWindowCatchWndMsg } Constructor TWindowCatchWndMsg.Create; procedure GetStartTime; var ftCreate, ftExit, ftKernel, ftUser: TFileTime; nDosTime: Integer; begin dtCreate_ := 0; GetProcessTimes(GetCurrentProcess, ftCreate, ftExit, ftKernel, ftUser); if FileTimeToLocalFileTime(ftCreate, ftCreate) then if FileTimeToDosDateTime(ftCreate, LongRec(nDosTime).Hi, LongRec(nDosTime).Lo) then dtCreate_ := FileDateToDateTime(nDosTime); end; var sAddMapName: String; begin Inherited Create; Trace_ := nil; {$IFDEF DEBUG} var sPath: String := ParamStr(0); Trace_ := TTgTrace.Create(ExtractFilePath(sPath), ExtractFileName(sPath) + '.log', false); {$ELSE} Trace_ := TTgTrace.Create; {$ENDIF} ASSERT(_WindowActiveHook = nil); _WindowActiveHook := self; hCbtHook_ := 0; hShellHook_ := 0; hMessageHook_ := 0; hCallWndHook_ := 0; hMouseHook_ := 0; hKeyboardHook_ := 0; dwLastInputTickCount_ := 0; GetStartTime; sAddMapName := DllName; if sAddMapName <> '' then sAddMapName := StringReplace(sAddMapName, '64', '', [rfReplaceAll]); SharedData_ := TTgFileMapping.Create(MAP_FILENAME_WM + sAddMapName, SizeOf(TSharedData)); SharedData_.DoFreeData := false; // Ãß°¡ 15_0911 10:39:41 sunk if SharedData_.LastError = ERROR_SUCCESS then SendWndHookMsg(WND_STATE_ATTACH_HOOK); end; Destructor TWindowCatchWndMsg.Destroy; begin SendWndHookMsg(WND_STATE_DETACH_HOOK); UnInstallWindowActiveHook; _WindowActiveHook := nil; Inherited; FreeAndNil(SharedData_); if Assigned(Trace_) then FreeAndNil(Trace_); end; procedure TWindowCatchWndMsg.UpdateLastInput; begin if SharedData_.IsAvailable then SharedData_.Data.dwLastInput := GetTickCount; end; function TWindowCatchWndMsg.SendWndHookMsg(wState: WORD; hWindow: HWND): Boolean; begin Result := false; if SharedData_.IsAvailable then begin try if wState = WND_STATE_ATTACH_HOOK then PostMessage(SharedData_.Data.hRcvWnd, WM_WNDHOOK_NOTIFY, MakeWParam(wState, PID), PID) else PostMessage(SharedData_.Data.hRcvWnd, WM_WNDHOOK_NOTIFY, MakeWParam(wState, PID), hWindow); Result := true; // OutLog('[%s] TWindowCatchWndMsg >> SendMsg() >> H = %d, M = %d', [ModuleName, SharedData_.Data.hRcvWnd, wState]); except // end; end; end; function TWindowCatchWndMsg.SendMsgHookSimple(dwMsg: DWORD; hWindow: HWND): Boolean; begin Result := false; if SharedData_.IsAvailable then begin try PostMessage(SharedData_.Data.hRcvWnd, WM_MESSAGEHOOK_NOTIFY, dwMsg, hWindow); Result := true; // OutLog('[%s] TWindowCatchWndMsg >> SendMsg() >> H = %d, M = %d', [ModuleName, SharedData_.Data.hRcvWnd, wState]); except // end; end; end; function TWindowCatchWndMsg.InstallWindowActiveHook: Integer; begin TTgTrace.t('[%s] TWindowCatchWndMsg >> InstallWindowActiveHook()', [ModuleName]); // UnInstallWindowActiveHook; Result := 0; // Active Çѹø ´õ ÀÚ¼¼È÷ ÀâÀ¸·Á°í Ãß°¡ sunk // À̰ŠȰ¼ºÈ­ Çϰí UnInstallWindowActiveHook()¸¦ ¼öÇàÇϸé 64ºñÆ® ȯ°æ¿¡¼­ explorer.exe°¡ Á״´Ù.. ´Ù¸¥°Íµµ Á×°ÚÁö.. hCbtHook_ := SetWindowsHookEx(WH_CBT, process_WH_CBT, HInstance, 0); if hCbtHook_ = 0 then begin TTgTrace.t('[%s] TWindowCatchWndMsg >> SetWindowsHookEx(WH_CBT) fail!!', [ModuleName]); Result := 1; exit; end; hShellHook_ := SetWindowsHookEx(WH_SHELL, process_WH_SHELL, HInstance, 0); if hShellHook_ = 0 then begin TTgTrace.t('[%s] TWindowCatchWndMsg >> SetWindowsHookEx(WH_SHELL) fail!!', [ModuleName]); Result := 2; exit; end; // ÇÊ¿ä ¾øÀ¸¸é Á¦¿Ü 16_0106 10:43:50 sunk // hMessageHook_ := SetWindowsHookEx(WH_GETMESSAGE, process_WH_GETMESSAGE, HInstance, 0); // if hMessageHook_ = 0 then // begin // TTgTrace.t('[%s] TWindowCatchWndMsg >> SetWindowsHookEx(WH_GETMESSAGE) fail!!', [ModuleName]); // Result := 5; // exit; // end; // hCallWndHook_ := SetWindowsHookEx(WH_CALLWNDPROC, process_WH_CALLWNDPROC, HInstance, 0); // if hCallWndHook_ = 0 then // begin // TTgTrace.t('[%s] TWindowCatchWndMsg >> SetWindowsHookEx(WH_CALLWNDPROC) fail!!', [ModuleName]); // Result := 5; // exit; // end; // ÇÊ¿äÇÏÁö ¾ÊÀ¸¸é Á¦¿Ü½ÃŲ´Ù. 14_1030 13:25:41 sunk // hMouseHook_, hKeyboardHook_ ÄùÀÌÅÍ, ½ÃÅ¥Àο¡¼­ »ç¿ëÇÔ // hMouseHook_ := SetWindowsHookEx(WH_MOUSE, process_WH_MOUSE, HInstance, 0); // if hMouseHook_ = 0 then // begin // TTgTrace.t('[%s] TWindowCatchWndMsg >> SetWindowsHookEx(WH_MOUSE) fail!!', [ModuleName]); // Result := 3; // exit; // end; // ÄùÀÌÅÍ¿¡¼­ »ç¿ëÇÏÁö ¾ÊÀ½ 16_0111 09:15:35 sunk // hKeyboardHook_ := SetWindowsHookEx(WH_KEYBOARD, process_WH_KEYBOARD, HInstance, 0); // if hKeyboardHook_ = 0 then // begin // TTgTrace.t('[%s] TWindowCatchWndMsg >> SetWindowsHookEx(WH_KEYBOARD) fail!!', [ModuleName]); // Result := 4; // exit; // end; end; function TWindowCatchWndMsg.UnInstallWindowActiveHook: Integer; begin TTgTrace.t('[%s] TWindowCatchWndMsg >> UnInstallWindowActiveHook()', [ModuleName]); Result := 0; try if hKeyboardHook_ <> 0 then begin TTgTrace.t('[%s] TWindowCatchWndMsg >> UnhookWindowsHookEx(hKeybordHook_)', [ModuleName]); UnhookWindowsHookEx(hKeyboardHook_); hKeyboardHook_ := 0; end; except // ¿ÖÀÎÁö.. OS ¸¶´Ù´Ù¸¥°ÇÁö ¸ð¸£°ÚÁö¸¸, ¿À·ù¸¦ ¹ß»ýÇØ¼­ °ü·Ã ÇÁ·Î±×·¥ÀÌ Á״´Ù. 14_1023 17:57:08 sunk hKeyboardHook_ := 0; end; try if hMouseHook_ <> 0 then begin TTgTrace.t('[%s] TWindowCatchWndMsg >> UnhookWindowsHookEx(hMouseHook_)', [ModuleName]); UnhookWindowsHookEx(hMouseHook_); hMouseHook_ := 0; end; except // ¿ÖÀÎÁö.. OS ¸¶´Ù´Ù¸¥°ÇÁö ¸ð¸£°ÚÁö¸¸, ¿À·ù¸¦ ¹ß»ýÇØ¼­ °ü·Ã ÇÁ·Î±×·¥ÀÌ Á״´Ù. 14_1023 17:57:08 sunk hMouseHook_ := 0; end; try if hCallWndHook_ <> 0 then begin TTgTrace.t('[%s] TWindowCatchWndMsg >> UnhookWindowsHookEx(CallWndHook)', [ModuleName]); UnhookWindowsHookEx(hCallWndHook_); hCallWndHook_ := 0; end; except // ¿ÖÀÎÁö.. OS ¸¶´Ù´Ù¸¥°ÇÁö ¸ð¸£°ÚÁö¸¸, ¿À·ù¸¦ ¹ß»ýÇØ¼­ °ü·Ã ÇÁ·Î±×·¥ÀÌ Á״´Ù. 14_1023 17:57:08 sunk hCallWndHook_ := 0; end; try if hMessageHook_ <> 0 then begin TTgTrace.t('[%s] TWindowCatchWndMsg >> UnhookWindowsHookEx(GetMessageHook)', [ModuleName]); UnhookWindowsHookEx(hMessageHook_); hMessageHook_ := 0; end; except // ¿ÖÀÎÁö.. OS ¸¶´Ù´Ù¸¥°ÇÁö ¸ð¸£°ÚÁö¸¸, ¿À·ù¸¦ ¹ß»ýÇØ¼­ °ü·Ã ÇÁ·Î±×·¥ÀÌ Á״´Ù. 14_1023 17:57:08 sunk hMessageHook_ := 0; end; try if hShellHook_ <> 0 then begin TTgTrace.t('[%s] TWindowCatchWndMsg >> UnhookWindowsHookEx(ShellHook)', [ModuleName]); UnhookWindowsHookEx(hShellHook_); hShellHook_ := 0; end; except // ¿ÖÀÎÁö.. OS ¸¶´Ù´Ù¸¥°ÇÁö ¸ð¸£°ÚÁö¸¸, ¿À·ù¸¦ ¹ß»ýÇØ¼­ °ü·Ã ÇÁ·Î±×·¥ÀÌ Á״´Ù. 14_1023 17:57:08 sunk hShellHook_ := 0; end; try if hCbtHook_ <> 0 then begin TTgTrace.t('[%s] TWindowCatchWndMsg >> UnhookWindowsHookEx(CbtHook)', [ModuleName]); UnhookWindowsHookEx(hCbtHook_); hCbtHook_ := 0; end; except // ¿ÖÀÎÁö.. OS ¸¶´Ù´Ù¸¥°ÇÁö ¸ð¸£°ÚÁö¸¸, ¿À·ù¸¦ ¹ß»ýÇØ¼­ °ü·Ã ÇÁ·Î±×·¥ÀÌ Á״´Ù. 14_1023 17:57:08 sunk hCbtHook_ := 0; end; end; exports InstallWindowActiveHook, UnInstallWindowActiveHook; end.