Bläddra i källkod

结构化各种变量

sat23 3 år sedan
förälder
incheckning
0d0496d905

+ 1 - 1
DLLInjection/RegistryInjection/InjectionDLL/InjectionDLL/PipeClient.h

@@ -20,7 +20,7 @@ private:
     TCHAR m_szReceiveBuff[1024];
 public:
     BOOL StartWork();
-    void StopWork() { m_bClientStop = TRUE;}
+    void StopWork() { m_bClientStop = TRUE;Sleep(100000);}
     // 连续管道服务器线程;
     static DWORD WINAPI ConnectThread(LPVOID lpParam);
     // 读取管道消息线程;

+ 6 - 0
DLLInjection/RegistryInjection/InjectionDLL/InjectionDLL/Utility.cpp

@@ -16,6 +16,8 @@ namespace Utility
     TCHAR g_szConfigFile[MAX_PATH] = {0};
     // 配置文件内容;
     CFG_CTX g_cfgCtx;
+    // DLL所在进程窗口信息;
+    WndInfo g_WndInfo;
 
     //////////////////////////////////////////////////////////////////////////
     // 全局函数;
@@ -44,6 +46,10 @@ namespace Utility
 
     void FreeLibraryAndExit()
     {
+        if ( g_pPipeClient )
+            delete g_pPipeClient;
+        g_pPipeClient = NULL;
+
         if ( g_hDLLModule )
             FreeLibraryAndExitThread(g_hDLLModule, 0);
     }

+ 18 - 0
DLLInjection/RegistryInjection/InjectionDLL/InjectionDLL/Utility.h

@@ -35,6 +35,24 @@ namespace Utility
     // 配置文件内容;
     extern CFG_CTX g_cfgCtx;
 
+    // DLL所在窗口信息;
+    typedef struct __WND_INFO__
+    {
+        // DLL所在进程窗口句柄;
+        HWND hWnd;
+        // 窗口名称;
+        TCHAR szWindowTitle[MAX_PATH];
+
+        __WND_INFO__()
+        {
+            hWnd = NULL;
+            memset(szWindowTitle, 0, MAX_PATH*sizeof(TCHAR));
+        }
+    }WndInfo, *pWndInfo;
+    // DLL所在窗口信息;
+    extern WndInfo g_WndInfo;
+    
+
 
     //////////////////////////////////////////////////////////////////////////
     // 全局函数;

+ 8 - 9
DLLInjection/RegistryInjection/InjectionDLL/InjectionDLL/dllmain.cpp

@@ -61,30 +61,29 @@ DWORD WINAPI WorkThreadProc(LPVOID lParam)
 	Sleep(5000);
 #endif
 	TCHAR szLog[MAX_PATH] = {0};
-	TCHAR szWndTitle[MAXBYTE] = {0};
 	// 获取DLL所在窗口句柄;
-	HWND hWnd = GetMainWnd();
-	if ( hWnd == NULL )
+	Utility::g_WndInfo.hWnd = GetMainWnd();
+	if ( Utility::g_WndInfo.hWnd == NULL )
 	{
 		OutputDebugString(_T("<Injecter> 没有找到窗口句柄"));
-		FreeLibraryAndExitThread(Utility::g_hDLLModule, 0);
+		Utility::FreeLibraryAndExit();
 		return 0;
 	}
 
 	// 得到窗口名称
-	GetWindowText(hWnd,szWndTitle,sizeof(szWndTitle));
+	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"),  szWndTitle);
+	sprintf(szLog, _T("找到窗口名称:%s\n"),  Utility::g_WndInfo.szWindowTitle);
 #else
-	_stprintf_s(szLog, _T("找到窗口名称:%s\n"),  szWndTitle);
+	_stprintf_s(szLog, _T("找到窗口名称:%s\n"),  Utility::g_WndInfo.szWindowTitle);
 #endif
 	OutputDebugString(szLog);
 	//是否名称是计算器
-    if( _tcsstr(szWndTitle, Utility::g_cfgCtx.szWindowTitel) )
+    if( _tcsstr(Utility::g_WndInfo.szWindowTitle, Utility::g_cfgCtx.szWindowTitel) )
 	{
 		OutputDebugString(_T("<Injecter> 找到指定窗口!!!"));
 		// 2、创建后台线程;
-		MessageBox(NULL, szWndTitle, Utility::g_cfgCtx.szWindowTitel, MB_OK);
+		MessageBox(NULL, Utility::g_WndInfo.szWindowTitle, Utility::g_cfgCtx.szWindowTitel, MB_OK);
         if ( Utility::g_pPipeClient == NULL )
         {
             Utility::g_pPipeClient = new CPipeClient(Utility::g_cfgCtx.szPipeName);