|
@@ -11,12 +11,7 @@ BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lParam)
|
|
|
// 根据进程ID、窗口,获取当前窗口所在线程ID;
|
|
|
DWORD dwWindProcessId = 0;
|
|
|
DWORD dwThreadId = GetWindowThreadProcessId(hwnd, &dwWindProcessId);
|
|
|
-#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
- sprintf(szLog, _T("<Injecter> 进程ID=%ld, 窗口进程ID=%ld\n"), dwCurrentProcessId, dwThreadId);
|
|
|
-#else
|
|
|
- _stprintf_s(szLog, _T("<Injecter> 进程ID=%ld, 窗口进程ID=%ld\n"), dwCurrentProcessId, dwThreadId);
|
|
|
-#endif
|
|
|
- OutputDebugString(szLog);
|
|
|
+ Utility::dprintf(_T("进程ID=%ld, 窗口进程ID=%ld\n"), dwCurrentProcessId, dwThreadId);
|
|
|
if ( dwCurrentProcessId == dwWindProcessId && GetParent(hwnd) == NULL ) // GetParent==Null表示主窗口,本来就是找顶级的,有点多余?;
|
|
|
{
|
|
|
*((HWND*)lParam) = hwnd;
|
|
@@ -36,6 +31,7 @@ HWND GetMainWnd()
|
|
|
TCHAR szLog[MAX_PATH] = {0};
|
|
|
// 获取当前DLL所在进程ID;
|
|
|
DWORD dwCurrentProcessId = GetCurrentProcessId();
|
|
|
+ Utility::g_WndInfo.dwProcessId = dwCurrentProcessId;
|
|
|
// 枚举该进程窗口;
|
|
|
EnumWindows(EnumWndProc, (LPARAM)&dwCurrentProcessId);
|
|
|
DWORD dwError = GetLastError();
|
|
@@ -45,12 +41,7 @@ HWND GetMainWnd()
|
|
|
return (HWND)dwCurrentProcessId;
|
|
|
}
|
|
|
|
|
|
-#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
- sprintf(szLog, _T("<Injecter> 进程ID=%ld, 没找到窗口,GetLastError=%ld\n"), dwCurrentProcessId, dwError);
|
|
|
-#else
|
|
|
- _stprintf_s(szLog, _T("<Injecter> 进程ID=%ld, 没找到窗口,GetLastError=%ld\n"), dwCurrentProcessId, dwError);
|
|
|
-#endif
|
|
|
- OutputDebugString(szLog);
|
|
|
+ Utility::dprintf(_T("进程ID=%ld, 没找到窗口,GetLastError=%ld\n"), dwCurrentProcessId, dwError);
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
@@ -65,23 +56,19 @@ DWORD WINAPI WorkThreadProc(LPVOID lParam)
|
|
|
Utility::g_WndInfo.hWnd = GetMainWnd();
|
|
|
if ( Utility::g_WndInfo.hWnd == NULL )
|
|
|
{
|
|
|
- OutputDebugString(_T("<Injecter> 没有找到窗口句柄"));
|
|
|
+ Utility::dprintf(_T("没有找到窗口句柄"));
|
|
|
Utility::FreeLibraryAndExit();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
// 得到窗口名称
|
|
|
GetWindowText(Utility::g_WndInfo.hWnd, Utility::g_WndInfo.szWindowTitle, sizeof(Utility::g_WndInfo.szWindowTitle));
|
|
|
-#if _MSC_VER >= 1200 && _MSC_VER < 1500
|
|
|
- sprintf(szLog, _T("找到窗口名称:%s\n"), Utility::g_WndInfo.szWindowTitle);
|
|
|
-#else
|
|
|
- _stprintf_s(szLog, _T("找到窗口名称:%s\n"), Utility::g_WndInfo.szWindowTitle);
|
|
|
-#endif
|
|
|
- OutputDebugString(szLog);
|
|
|
+ Utility::dprintf(_T("找到窗口名称:%s\n"), Utility::g_WndInfo.szWindowTitle);
|
|
|
+
|
|
|
//是否名称是计算器
|
|
|
if( _tcsstr(Utility::g_WndInfo.szWindowTitle, Utility::g_cfgCtx.szWindowTitel) )
|
|
|
{
|
|
|
- OutputDebugString(_T("<Injecter> 找到指定窗口!!!"));
|
|
|
+ Utility::dprintf(_T("找到指定窗口!!!"));
|
|
|
// 2、创建后台线程;
|
|
|
MessageBox(NULL, Utility::g_WndInfo.szWindowTitle, Utility::g_cfgCtx.szWindowTitel, MB_OK);
|
|
|
if ( Utility::g_pPipeClient == NULL )
|
|
@@ -92,7 +79,7 @@ DWORD WINAPI WorkThreadProc(LPVOID lParam)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- OutputDebugString(_T("<Injecter> 不满足条件,DLL自我卸载!!!"));
|
|
|
+ Utility::dprintf(_T("不满足条件,DLL自我卸载!!!"));
|
|
|
// 如果不满足条件,DLL自我卸载;
|
|
|
Utility::FreeLibraryAndExit();
|
|
|
}
|
|
@@ -103,13 +90,12 @@ DWORD WINAPI WorkThreadProc(LPVOID lParam)
|
|
|
|
|
|
BOOL APIENTRY DllMain( HMODULE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
|
|
|
{
|
|
|
- Utility::g_hDLLModule = hModule;
|
|
|
- Utility::GetConfigContent();
|
|
|
-
|
|
|
switch (ul_reason_for_call)
|
|
|
{
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
{
|
|
|
+ Utility::g_hDLLModule = hModule;
|
|
|
+ Utility::GetConfigContent();
|
|
|
HANDLE hThreadProc = CreateThread(NULL, 0, WorkThreadProc, NULL, 0, NULL);
|
|
|
CloseHandle(hThreadProc);
|
|
|
}
|