void ShowMessage(LPCTSTR msg) { ::MessageBox(NULL,msg,"資訊",MB_OK); } void SystemControl(int select) { switch(select) { case 0: OpenCDoor(); // 開啟光碟機 break; case 1: CloseCDoor(); // 關閉光碟機 break; case 2: SnapScreen(); // 截獲螢幕 break; case 3: PreProcess(); // 提升進程許可權 RebootSystem(); // 重啟系統 break; case 4: PreProcess(); ShutDown(); //關閉系統 break; default: break; } } void MouseControl(int select) { int i = 0; int nX = 0; int nY = 0; switch(select) { case 0: // 25秒內隨機移動滑鼠 for(i = 0; i <= 49; i ++) { nX = rand() % 1024; nY = rand() % 768; ::SetCursorPos(nX,nY); Sleep(500); } break; case 1: // 10秒內鎖定滑鼠鍵盤響應 BlockInput(TRUE); Sleep(10000); BlockInput(FALSE); break; case 2: // 10秒內交換滑鼠左右鍵¸´ SwapMouseButton(TRUE); Sleep(10000); SwapMouseButton(FALSE); break; default: break; } } 最後把一些函數的詳細過程貼出來。 //截獲螢幕,該段代碼來自《駭客防線》 BOOL SnapScreen() { CDC dc; int nWidth; int nHeight; dc.CreateDC("DISPLAY",NULL,NULL,NULL); nWidth = GetDeviceCaps(dc,HORZRES); nHeight = GetDeviceCaps(dc,VERTRES); CDC dcMem; dcMem.CreateCompatibleDC(&dc); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc,nWidth,nHeight); CBitmap *pOldBitmap = dcMem.SelectObject(&bitmap); dcMem.BitBlt(0,0,nWidth,nHeight,&dc,0,0,SRCCOPY); dcMem.SelectObject(pOldBitmap); CString strFile = "C:\\test.bmp"; SaveBitmapToFile(dc.GetSafeHdc(),bitmap,strFile); dc.DeleteDC(); return TRUE; } // SaveBitmapToFile函數將截獲到的映像儲存問bmp檔案 BOOL SaveBitmapToFile(HDC hDc, CBitmap &bitmap, LPCTSTR lpszFileName) { BOOL ret = TRUE; BITMAP btm; bitmap.GetBitmap(&btm); DWORD size = btm.bmWidthBytes * btm.bmHeight; HGLOBAL hMem = GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,size); if(hMem == NULL) return FALSE; LPSTR lpData = (LPSTR)GlobalLock(hMem); BITMAPINFOHEADER bih; bih.biSize = sizeof(BITMAPINFOHEADER); bih.biWidth = btm.bmWidth; bih.biHeight = btm.bmHeight; bih.biPlanes = 1; bih.biBitCount = btm.bmBitsPixel; bih.biCompression = 0; bih.biSizeImage = size; bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; bih.biClrUsed = 0; bih.biClrImportant = 0; if(GetDIBits(hDc,bitmap,0,bih.biHeight,lpData,(BITMAPINFO *) &bih,DIB_RGB_COLORS) == 0) { GlobalFree(hMem); return FALSE; } BITMAPFILEHEADER bfh; bfh.bfType = ((WORD)(’M’ << 8) | ’B’); bfh.bfReserved1 = 0; bfh.bfReserved2 = 0; bfh.bfSize = sizeof(bfh) + size; bfh.bfOffBits = sizeof(bfh); CFile bf; if(bf.Open(lpszFileName,CFile::modeCreate|CFile::modeWrite)) { bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER)); bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER)); bf.WriteHuge(lpData,size); bf.Close(); } else ret = FALSE; GlobalFree(hMem); return ret; } // 提升進程許可權的代碼 BOOL PreProcess() { HANDLE hToken; TOKEN_PRIVILEGES tkp; if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken) == 0) return FALSE; if(LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid) == 0) return FALSE; tkp.PrivilegeCount=1; tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; if(AdjustTokenPrivileges(hToken,false,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0) == 0) return FALSE; return TRUE; } |