4 #include "HookLoader.h"
5 #include "../DCHook64/DCHook64.h"
8 #define HOOK64_SUBDIR 0 // x64
\8aÖ
\98A
\83t
\83@
\83C
\83\8b\82Ísub directory x64
\82Ö
12 THookLoader::THookLoader(const char *dllname)
20 DCHWaitForCaptureResult = NULL;
29 THookLoader::~THookLoader()
33 bool THookLoader::Load(HWND hwnd)
38 hDll = LoadLibrary( DllName );
43 DBW("Cannot load DLL:%s",DllName);
45 // DKPPHK.DLL
\82ª
\82È
\82¯
\82ê
\82Î DCHOOK.DLL
\82ðload
46 DllName = "DCHOOK.DLL";
48 hDll = LoadLibrary( DllName );
50 DBW("Cannot load DLL:%s",DllName);
55 DCHInit = (FNDCHInit)GetProcAddress( hDll, "Init" );
56 DCHUninit = (FNDCHUninit)GetProcAddress( hDll, "Uninit" );
57 DCHConfig = (FNDCHConfig)GetProcAddress( hDll, "Config" );
58 DCHConfig2 = (FNDCHConfig2)GetProcAddress( hDll, "Config2" );
59 DCHCapture = (FNDCHCapture)GetProcAddress( hDll, "Capture" );
60 DCHWaitForCaptureResult = (FNDCHWaitForCaptureResult)GetProcAddress( hDll, "WaitForCaptureResult" );
62 DCDebug = (FNDebug)GetProcAddress( hDll, "Debug" );
65 if (!DCHInit || !DCHUninit || !DCHConfig || !DCHConfig2 || !DCHCapture || !DCHWaitForCaptureResult){
73 const char *pVxdPath = NULL;
78 VxdPath = ExtractFilePath( Application->ExeName );
80 GetShortPathName( VxdPath.c_str(), path, sizeof(path) );
82 VxdPath += "HK95D.VXD";
84 const char *pVxdPath = VxdPath.data();
87 if ( !DCHInit( hwnd, DllName, WindowsNT, pVxdPath ) ){
90 DBW("Cannot initialized DLL");
98 void THookLoader::Unload()
108 bool THookLoader::Init(HWND hwnd)
111 return DCHInit(hwnd, NULL, NULL, NULL);
113 void THookLoader::Uninit()
115 if (DCHUninit) DCHUninit();
118 int THookLoader::Capture()
122 return DCHCapture(NULL, NULL, true, false);
124 int THookLoader::CaptureAsync()
128 int ret = DCHCapture(NULL, NULL, true, true);
129 int result = DCHWaitForCaptureResult(false, 0);
130 DBW("result:%d", result);
137 int THookLoader::CaptureAsyncWait()
142 void THookLoader::OpenThread()
144 DBW("OpenThread: %08X", hThread);
148 hThread = CreateThread(NULL, 0, cbWaitCaptureThread, this, CREATE_SUSPENDED, &dwThreadId);
149 ResumeThread(hThread);
152 DWORD WINAPI THookLoader::cbWaitCaptureThread(LPVOID This)
154 ((THookLoader*)This)->WaitCaptureThread();
158 void THookLoader::WaitCaptureThread()
160 DCHWaitForCaptureResult(true, 3000);
164 static const char *MyWinTitle = "<Processing...in dchook>";
165 inline HANDLE __WinExec( const char *cmd, int show, const char *dir=NULL )
167 return WinExecEx(cmd, show, dir, MyWinTitle);
172 const char *StrDCHK64EXE = "..\\dchk64\\x64\\Debug\\dchk64.exe"; // for debug
175 const char *StrDCHK64EXE = "x64\\DKPUHK64.exe";
177 const char *StrDCHK64EXE = "DKPUHK64.exe";
181 THookLoader64::THookLoader64(HWND hwnd_recv)
188 THookLoader64::~THookLoader64()
194 bool THookLoader64::Load(HWND hwnd)
196 #if 1 // Find already launched hook executer.
197 HWND hwndFound = FindWindow("dchk64", "DCHK64");
198 // HWND hwndFound = FindApp("dchk64", "DCHK64", "");
200 DBW("x64:Found %08X already launched exe", hwndFound);
201 hwndTarget = hwndFound;
208 wsprintf(param, "%s %08X", StrDCHK64EXE, hwndRecv);
209 hProc = __WinExec(param, SW_HIDE, 0); // Launch dchk64.exe
211 DBW("Launch failed: %s", param);
215 //WaitForInputIdle(hProc, 3000);
219 void THookLoader64::Unload()
224 TerminateProcess(hProc, 0);
229 bool THookLoader64::Init(HWND hwnd)
231 DBW("x64:Init hwndTarget=%08X", hwndTarget);
237 HDCInitParam p = {hwnd};
238 return Send(HDC_Init, &p, sizeof(p)) ? true : false;
240 void THookLoader64::Uninit( )
247 int THookLoader64::Config( int clickonly, int keyaction, int keyflag )
251 HDCConfigParam p = {clickonly, keyaction, keyflag };
252 return Send(HDC_Config, &p, sizeof(p));
254 int THookLoader64::Config2( struct TDCHConfig *cfg )
258 return Send(HDC_Config2, cfg, sizeof(*cfg));
260 int THookLoader64::Capture()
264 return Send(HDC_Capture, 0);
266 int THookLoader64::CaptureAsync()
270 return Send(HDC_CaptureAsync, 0);
272 int THookLoader64::CaptureAsyncWait()
276 return Send(HDC_CaptureAsyncWait, 0);
278 int THookLoader64::Debug()
282 return Send(HDC_Debug, 0);
285 int THookLoader64::Send(int msg, void *data, int len)
288 memset(&cds, 0, sizeof(cds));
292 return (int)SendMessage(hwndTarget, WM_COPYDATA, 0, (LPARAM)&cds);