遊戲平臺登錄器

經常上hf平臺,擠不進去自己想進去的房間,花了一天多時間研究了一下,因此有了以下的文章.

 

  1. /*  
  2.     witten by       :       [email protected] (applebomb) 
  3.     history         :       2012/6/2 (ver 1) 
  4.     information :       一直在玩浩方DOTA IMBA, 總是進不了450人房間, 一氣之下花了時間研究 
  5.                                     怎麼搞自動擠房間. 因此有了下面的程序 
  6.                                     浩方版本: 5.8.1.516-20120528 
  7.  
  8.     how to use  :       打開電信 DOTA IMBA 房間, 運行程序進行自動擠房間  
  9.  
  10.     attention!! :       花時間自己寫的同學注意兩點, 在這兩點上浪費了一天時間.  
  11.                                     第一: WM_NOTIFY 的消息結構是發送給父窗口而非控件本身, 不過對於ListView控件 
  12.                                           來說, 似乎用WM_NOTIFY發送雙擊動作結構體 不起作用 
  13.                                                 { 如果有成功的同學請郵件告訴我方法, 謝謝! } 
  14.                                     第二: 運行程序時候需要以Administrator身份, 否則用 GetLastError() = Access Denied 
  15.      
  16.     how to do       :   step 1. 找出浩方窗口 
  17.                                     step 2. 找出登錄列表 
  18.                                     step 3. openProcess 浩方進程, 在裏面分配幾個獲取信息的變量 
  19.                                     step 4. 發送消息讓取得信息 
  20.                                     step 5. ReadProcessMemory 讀取 step4得到的信息 
  21.                                     step 6. 獲取房間在控件中的相對座標 
  22.                                     step 7. 發送信息點擊登陸房間 
  23.                                     step 8. 如果彈出 Type: "#32770", Name: "浩方電競平臺" 的窗口, 則登錄不成功 
  24.                                     step 9. 如果看不見登錄列表, 則登錄成功 
  25. */ 
  26.  
  27. #include <stdio.h> 
  28. #include <Windows.h> 
  29. #include <WinDef.h> 
  30. #include <CommCtrl.h> 
  31. #include <WinUser.h> 
  32.  
  33. /* funciton declare */ 
  34. BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam);  /* 枚舉浩方主進程 */ 
  35. BOOL CALLBACK EnumChildWindowsProc(HWND hwnd, LPARAM lparam); /* 枚舉窗口子進程 */ 
  36.  
  37. int main (int argc, const char *argv[]) 
  38.     ::EnumWindows((WNDENUMPROC)EnumWindowsProc, 0); // 查找浩方主進程 
  39.     getchar();  
  40.     return 0; 
  41.  
  42. /* 
  43.     查找浩方主進程 
  44. */ 
  45. BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam) 
  46.     char programName[256]; 
  47.     ::GetWindowTextA(hwnd, programName, 256-1); 
  48.     if (strstr(programName, "浩方電競平臺")!=NULL) 
  49.     { 
  50.         printf ("Found main program window. \n"); 
  51.         ::EnumChildWindows(hwnd, (WNDENUMPROC)EnumChildWindowsProc, 0); /* 找到主窗口, 枚舉找出ListView控件*/ 
  52.     } 
  53.     return true
  54.  
  55. /* 
  56.     查找ListView控件 
  57. */ 
  58. BOOL CALLBACK EnumChildWindowsProc(HWND hwnd, LPARAM lparam) 
  59.     char hwndName[256]; 
  60.     ::GetClassNameA(hwnd, hwndName, 256-1); //hwnd 正在枚舉的控件 
  61.       
  62.     if (strcmp(hwndName,"SysListView32") == 0) { 
  63.         int nID = ::GetDlgCtrlID(hwnd); 
  64.         printf("nID : %d\n",nID);  
  65.          
  66.         if (nID == 257)  /*這裏我是找出ListView的控件ID = 257 (還有id = 340, 513, 12001 這三個沒有用)*/ 
  67.         { 
  68.             int find = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0,0); 
  69.              
  70.             //打開浩方進程 
  71.             DWORD ProcessID; 
  72.             HANDLE handle; 
  73.             ::GetWindowThreadProcessId(hwnd, &ProcessID); 
  74.             handle = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, ProcessID); 
  75.              
  76.             LVITEM *_lvi, lvi; /* 指向一條ListView 記錄*/ 
  77.             WCHAR *_item, *_subitem; /* */ 
  78.             WCHAR item[512], subitem[512]; 
  79.             PPOINT ppoint; 
  80.             POINT pt; 
  81.              
  82.             /* 在浩方進程分配獲取信息空間 */ 
  83.             _lvi = (LVITEM*)VirtualAllocEx(handle, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE); 
  84.             _item = (WCHAR*)VirtualAllocEx(handle, NULL, 512, MEM_COMMIT, PAGE_READWRITE); 
  85.             _subitem = (WCHAR*)VirtualAllocEx(handle, NULL, 512, MEM_COMMIT, PAGE_READWRITE); 
  86.             ppoint = (PPOINT)VirtualAllocEx(handle, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE); 
  87.        
  88.             int roomindex = 0;  /* 從0開始枚舉房間 */ 
  89.             bool getinflag =false/* 登陸成功標誌 */ 
  90.             while (!getinflag) 
  91.             { 
  92.                 lvi.iSubItem=0; /* Listview中第一項房間名 */ 
  93.                 lvi.cchTextMax=512; /*Number of TCHARs in the buffer pointed to by pszText, including the terminating NULL.*/ 
  94.                 lvi.pszText=(LPWSTR)_item; /* 將浩方進程裏面將要存放房間名稱的地址傳遞給lvi */ 
  95.                  
  96.                 WriteProcessMemory(handle, _lvi, &lvi, sizeof(LVITEM), NULL); /* 將定義好的lvi結構寫到上面在浩方分配的內存裏 */ 
  97.                 SendMessage(hwnd, LVM_GETITEMTEXT, (WPARAM)roomindex, (LPARAM)_lvi); /* 發送消息將結果寫在 _item指定的內存裏*/ 
  98.  
  99.                 lvi.iSubItem=1; /*人數*/ 
  100.                 lvi.pszText=(LPWSTR)_subitem; 
  101.                 WriteProcessMemory(handle, _lvi, &lvi, sizeof(LVITEM), NULL); 
  102.                 SendMessage(hwnd, LVM_GETITEMTEXT, (WPARAM)roomindex, (LPARAM)_lvi); 
  103.  
  104.                 // 將浩方進程裏取得的結果讀回登陸器進程內存 
  105.                 ReadProcessMemory(handle, _item, item, 512, NULL); 
  106.                 ReadProcessMemory(handle, _subitem, subitem, 512, NULL); 
  107.     
  108.                 // 比較當前房間是否是需要進入的房間 
  109.                 wchar_t *pRoomName = wcsstr(item, L"IMBA"); /* 電信 IMBA */ 
  110.                 wchar_t *pRoomCont = wcsstr(subitem, L"/450");  /* 450人 */ 
  111.    
  112.                 if (pRoomName && pRoomCont){ 
  113.                     printf ("find the room."); //找到合適的房間, 嘗試登陸 
  114.  
  115.                     //選擇房間 
  116.                     lvi.state = LVIS_SELECTED; 
  117.                     lvi.stateMask = LVIS_SELECTED; 
  118.                     WriteProcessMemory(handle, _lvi, &lvi, sizeof(LVITEM), NULL); 
  119.                     ::SendMessage(hwnd, LVM_SETITEMSTATE, (WPARAM)roomindex, (LPARAM)_lvi ); 
  120.  
  121.                     /* 取得房間一欄在浩方里面的相對位置, LVM_GETITEMPOSITION 消息比較簡單,  
  122.                      不需要用到WriteProcessMemory 寫入控制信息 */ 
  123.                     ::SendMessage(hwnd, LVM_GETITEMPOSITION, roomindex, (LPARAM)ppoint); 
  124.                     ::ReadProcessMemory(handle, ppoint, &pt, sizeof(POINT), NULL); 
  125.  
  126.                     // 模擬雙擊房間, postmessage 直接返回, sendmessage 等待結果再返回 
  127.                     PostMessage(hwnd, WM_LBUTTONDBLCLK, MK_LBUTTON, MAKELPARAM(pt.x, pt.y)); 
  128.            
  129.                     // 檢查是彈出"人滿不能進入, 或者登陸上了房間" 
  130.                     int waittime = 0; /* 超時從新嘗試另一個房間 */ 
  131.                     while(1) 
  132.                     { 
  133.                         /* 不能進入房間, 這裏參考了  
  134.                             http://blog.csdn.net/courage3000/article/details/7526475 檢查代碼 
  135.                         */ 
  136.                         HWND hRenMan = FindWindowA("#32770""浩方電競平臺"); 
  137.                         if (hRenMan) {   
  138.                             printf("fail to login in. find next room.\n");         
  139.                             SendMessage(hRenMan, WM_CLOSE, 0, 0); 
  140.                             break;        
  141.                         }else
  142.                          if (!IsWindowVisible(hwnd)) 
  143.                          {           
  144.                              getinflag = true;   
  145.                              break
  146.                          } // !iswindowvisible 
  147.                         } // if hRenMan 
  148.                          
  149.                         waittime++; // 超時嘗試登陸另一個房間 
  150.                         if (waittime > 10) break
  151.                         Sleep(1000); 
  152.                        
  153.                     } // while(1) 
  154.                 } //if pRoomName && pRoomCont 
  155.                  
  156.                 if (roomindex++ >= find) /*不能登陸成功重新嘗試*/ 
  157.                     roomindex =0; 
  158.             } 
  159.              
  160.             VirtualFreeEx(handle, _lvi, 0, MEM_RELEASE); // 釋放內存  
  161.             VirtualFreeEx(handle, _item, 0, MEM_RELEASE);  
  162.             VirtualFreeEx(handle, _subitem, 0, MEM_RELEASE); 
  163.             VirtualFreeEx(handle, ppoint, 0, MEM_RELEASE); 
  164.         }        
  165.     } 
  166.     return true
  167.  
  168.  
  169. /* 
  170. * subprogram : 用鼠標找出鼠標位置的子窗口句柄 
  171. */ 
  172. void subprogram_findWNDbyMouse() 
  173. {/* 
  174.      
  175.     POINT pt; 
  176.     ::GetCursorPos(&pt);     
  177.     HWND wfp =  ::WindowFromPoint(pt); 
  178.     if (wfp != NULL && ::GetParent(wfp) == hwnd) 
  179.     { 
  180.         printf ("mouse point at: %d, %d",pt.x,pt.y); 
  181.      
  182.         printf ("mouse point: find window : "); 
  183.          
  184.         char lpsubWinName[256], plsubWinText[256]; 
  185.         ::GetClassNameA(wfp, lpsubWinName, 256 - 1); 
  186.         ::GetWindowTextA(wfp, plsubWinText, 256-1); 
  187.         printf (" %s    %s\n", lpsubWinName, plsubWinText); 
  188.     } 
  189. */ 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章