Unify all log recording in the program
This commit is contained in:
@@ -336,7 +336,7 @@ extern "C" __declspec(dllexport) void TestRun(char* szServerIP,int uPort)
|
|||||||
extern "C" __declspec(dllexport) void StopRun() { g_MyApp.g_bExit = S_CLIENT_EXIT; }
|
extern "C" __declspec(dllexport) void StopRun() { g_MyApp.g_bExit = S_CLIENT_EXIT; }
|
||||||
|
|
||||||
// <20>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>ֹͣ
|
// <20>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>ֹͣ
|
||||||
extern "C" __declspec(dllexport) bool IsStoped() { return g_MyApp.g_bThreadExit; }
|
extern "C" __declspec(dllexport) bool IsStoped() { return g_MyApp.g_bThreadExit && ClientApp::GetCount() == 0; }
|
||||||
|
|
||||||
// <20>Ƿ<EFBFBD><C7B7>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB><EFBFBD>
|
// <20>Ƿ<EFBFBD><C7B7>˳<EFBFBD><CBB3>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||||
extern "C" __declspec(dllexport) BOOL IsExit() { return g_MyApp.g_bExit; }
|
extern "C" __declspec(dllexport) BOOL IsExit() { return g_MyApp.g_bExit; }
|
||||||
|
|||||||
@@ -58,31 +58,31 @@ BOOL SetKeepAliveOptions(int socket, int nKeepAliveSec = 180) {
|
|||||||
// <20><><EFBFBD><EFBFBD> TCP <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
// <20><><EFBFBD><EFBFBD> TCP <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
|
||||||
int enable = 1;
|
int enable = 1;
|
||||||
if (setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)) < 0) {
|
if (setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &enable, sizeof(enable)) < 0) {
|
||||||
std::cerr << "Failed to enable TCP keep-alive" << std::endl;
|
Mprintf("Failed to enable TCP keep-alive\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD> TCP_KEEPIDLE (3<><33><EFBFBD>ӿ<EFBFBD><D3BF>к<EFBFBD><D0BA><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> keep-alive <20><>)
|
// <20><><EFBFBD><EFBFBD> TCP_KEEPIDLE (3<><33><EFBFBD>ӿ<EFBFBD><D3BF>к<EFBFBD><D0BA><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> keep-alive <20><>)
|
||||||
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &nKeepAliveSec, sizeof(nKeepAliveSec)) < 0) {
|
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &nKeepAliveSec, sizeof(nKeepAliveSec)) < 0) {
|
||||||
std::cerr << "Failed to set TCP_KEEPIDLE" << std::endl;
|
Mprintf("Failed to set TCP_KEEPIDLE\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD> TCP_KEEPINTVL (5<><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>)
|
// <20><><EFBFBD><EFBFBD> TCP_KEEPINTVL (5<><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>)
|
||||||
int keepAliveInterval = 5; // 5<><35>
|
int keepAliveInterval = 5; // 5<><35>
|
||||||
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPINTVL, &keepAliveInterval, sizeof(keepAliveInterval)) < 0) {
|
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPINTVL, &keepAliveInterval, sizeof(keepAliveInterval)) < 0) {
|
||||||
std::cerr << "Failed to set TCP_KEEPINTVL" << std::endl;
|
Mprintf("Failed to set TCP_KEEPINTVL\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD> TCP_KEEPCNT (<28><><EFBFBD><EFBFBD>5<EFBFBD><35>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ӶϿ<D3B6>)
|
// <20><><EFBFBD><EFBFBD> TCP_KEEPCNT (<28><><EFBFBD><EFBFBD>5<EFBFBD><35>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>ӶϿ<D3B6>)
|
||||||
int keepAliveProbes = 5;
|
int keepAliveProbes = 5;
|
||||||
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPCNT, &keepAliveProbes, sizeof(keepAliveProbes)) < 0) {
|
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPCNT, &keepAliveProbes, sizeof(keepAliveProbes)) < 0) {
|
||||||
std::cerr << "Failed to set TCP_KEEPCNT" << std::endl;
|
Mprintf("Failed to set TCP_KEEPCNT\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "TCP keep-alive settings applied successfully" << std::endl;
|
Mprintf("TCP keep-alive settings applied successfully\n");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -172,7 +172,7 @@ inline std::string GetIPAddress(const char *hostName)
|
|||||||
|
|
||||||
int status = getaddrinfo(hostName, nullptr, &hints, &res);
|
int status = getaddrinfo(hostName, nullptr, &hints, &res);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
std::cerr << "getaddrinfo failed: " << gai_strerror(status) << std::endl;
|
Mprintf("getaddrinfo failed: %s\n", gai_strerror(status));
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ inline std::string GetIPAddress(const char *hostName)
|
|||||||
char ip[INET_ADDRSTRLEN];
|
char ip[INET_ADDRSTRLEN];
|
||||||
inet_ntop(AF_INET, &(addr->sin_addr), ip, sizeof(ip));
|
inet_ntop(AF_INET, &(addr->sin_addr), ip, sizeof(ip));
|
||||||
|
|
||||||
std::cout << "IP Address: " << ip << std::endl;
|
Mprintf("IP Address: %s \n", ip);
|
||||||
|
|
||||||
freeaddrinfo(res); // <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ͷŵ<CDB7>ַ<EFBFBD><D6B7>Ϣ
|
freeaddrinfo(res); // <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>ͷŵ<CDB7>ַ<EFBFBD><D6B7>Ϣ
|
||||||
return ip;
|
return ip;
|
||||||
@@ -225,20 +225,20 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
|||||||
// <20><>szServerIP<49><50><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IPת<50><D7AA>
|
// <20><>szServerIP<49><50><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IPת<50><D7AA>
|
||||||
// ʹ<><CAB9> inet_pton <20><><EFBFBD><EFBFBD> inet_addr (inet_pton <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7> IPv4 <20><> IPv6)
|
// ʹ<><CAB9> inet_pton <20><><EFBFBD><EFBFBD> inet_addr (inet_pton <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7> IPv4 <20><> IPv6)
|
||||||
if (inet_pton(AF_INET, server.c_str(), &ServerAddr.sin_addr) <= 0) {
|
if (inet_pton(AF_INET, server.c_str(), &ServerAddr.sin_addr) <= 0) {
|
||||||
std::cerr << "Invalid address or address not supported" << std::endl;
|
Mprintf("Invalid address or address not supported\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
||||||
m_sClientSocket = socket(AF_INET, SOCK_STREAM, 0);
|
m_sClientSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (m_sClientSocket == -1) {
|
if (m_sClientSocket == -1) {
|
||||||
std::cerr << "Failed to create socket" << std::endl;
|
Mprintf("Failed to create socket\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
// <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
if (connect(m_sClientSocket, (struct sockaddr*)&ServerAddr, sizeof(ServerAddr)) == -1) {
|
if (connect(m_sClientSocket, (struct sockaddr*)&ServerAddr, sizeof(ServerAddr)) == -1) {
|
||||||
std::cerr << "Connection failed" << std::endl;
|
Mprintf("Connection failed\n");
|
||||||
close(m_sClientSocket);
|
close(m_sClientSocket);
|
||||||
m_sClientSocket = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD>Ч
|
m_sClientSocket = -1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD><EFBFBD><EFBFBD>Ч
|
||||||
return false;
|
return false;
|
||||||
@@ -327,6 +327,8 @@ DWORD WINAPI IOCPClient::WorkThreadProc(LPVOID lParam)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CloseHandle(This->m_hWorkThread);
|
||||||
|
This->m_hWorkThread = NULL;
|
||||||
This->m_bWorkThread = S_STOP;
|
This->m_bWorkThread = S_STOP;
|
||||||
This->m_bIsRunning = FALSE;
|
This->m_bIsRunning = FALSE;
|
||||||
delete[] szBuffer;
|
delete[] szBuffer;
|
||||||
@@ -352,62 +354,51 @@ VOID IOCPClient::OnServerReceiving(char* szBuffer, ULONG ulLength)
|
|||||||
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>ͷ
|
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||||
if (memcmp(m_szPacketFlag, szPacketFlag, FLAG_LENGTH) != 0)
|
if (memcmp(m_szPacketFlag, szPacketFlag, FLAG_LENGTH) != 0)
|
||||||
{
|
{
|
||||||
throw "Bad Buffer";
|
Mprintf("[ERROR] OnServerReceiving memcmp fail: unknown header '%s'\n", szPacketFlag);
|
||||||
|
m_CompressedBuffer.ClearBuffer();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG ulPackTotalLength = 0;
|
ULONG ulPackTotalLength = 0;
|
||||||
CopyMemory(&ulPackTotalLength, m_CompressedBuffer.GetBuffer(FLAG_LENGTH),
|
CopyMemory(&ulPackTotalLength, m_CompressedBuffer.GetBuffer(FLAG_LENGTH), sizeof(ULONG));
|
||||||
sizeof(ULONG));
|
|
||||||
|
|
||||||
//--- <20><><EFBFBD>ݵĴ<DDB5>С<EFBFBD><D0A1>ȷ<EFBFBD>ж<EFBFBD>
|
//--- <20><><EFBFBD>ݵĴ<DDB5>С<EFBFBD><D0A1>ȷ<EFBFBD>ж<EFBFBD>
|
||||||
ULONG len = m_CompressedBuffer.GetBufferLength();
|
ULONG len = m_CompressedBuffer.GetBufferLength();
|
||||||
if (ulPackTotalLength && len >= ulPackTotalLength)
|
if (ulPackTotalLength && len >= ulPackTotalLength)
|
||||||
{
|
{
|
||||||
m_CompressedBuffer.ReadBuffer((PBYTE)szPacketFlag, FLAG_LENGTH);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7> shine
|
|
||||||
|
|
||||||
m_CompressedBuffer.ReadBuffer((PBYTE) &ulPackTotalLength, sizeof(ULONG));
|
|
||||||
|
|
||||||
ULONG ulOriginalLength = 0;
|
ULONG ulOriginalLength = 0;
|
||||||
|
|
||||||
|
m_CompressedBuffer.ReadBuffer((PBYTE)szPacketFlag, FLAG_LENGTH);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7> shine
|
||||||
|
m_CompressedBuffer.ReadBuffer((PBYTE) &ulPackTotalLength, sizeof(ULONG));
|
||||||
m_CompressedBuffer.ReadBuffer((PBYTE) &ulOriginalLength, sizeof(ULONG));
|
m_CompressedBuffer.ReadBuffer((PBYTE) &ulOriginalLength, sizeof(ULONG));
|
||||||
|
|
||||||
//50
|
|
||||||
ULONG ulCompressedLength = ulPackTotalLength - HDR_LENGTH;
|
ULONG ulCompressedLength = ulPackTotalLength - HDR_LENGTH;
|
||||||
PBYTE CompressedBuffer = new BYTE[ulCompressedLength];
|
const int bufSize = 512;
|
||||||
PBYTE DeCompressedBuffer = new BYTE[ulOriginalLength];
|
BYTE buf1[bufSize], buf2[bufSize];
|
||||||
|
PBYTE CompressedBuffer = ulCompressedLength > bufSize ? new BYTE[ulCompressedLength] : buf1;
|
||||||
|
PBYTE DeCompressedBuffer = ulCompressedLength > bufSize ? new BYTE[ulOriginalLength] : buf2;
|
||||||
|
|
||||||
m_CompressedBuffer.ReadBuffer(CompressedBuffer, ulCompressedLength);
|
m_CompressedBuffer.ReadBuffer(CompressedBuffer, ulCompressedLength);
|
||||||
|
|
||||||
size_t iRet = uncompress(DeCompressedBuffer,
|
size_t iRet = uncompress(DeCompressedBuffer, &ulOriginalLength, CompressedBuffer, ulCompressedLength);
|
||||||
&ulOriginalLength, CompressedBuffer, ulCompressedLength);
|
|
||||||
|
|
||||||
if (Z_SUCCESS(iRet))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD>ɹ<EFBFBD>
|
if (Z_SUCCESS(iRet))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD>ɹ<EFBFBD>
|
||||||
{
|
{
|
||||||
CBuffer m_DeCompressedBuffer;
|
|
||||||
m_DeCompressedBuffer.WriteBuffer(DeCompressedBuffer,
|
|
||||||
ulOriginalLength);
|
|
||||||
|
|
||||||
//<2F><>ѹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݺͳ<DDBA><CDB3>ȴ<EFBFBD><C8B4>ݸ<EFBFBD><DDB8><EFBFBD><EFBFBD><EFBFBD>Manager<65><72><EFBFBD>д<EFBFBD><D0B4><EFBFBD> ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>̬
|
//<2F><>ѹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ݺͳ<DDBA><CDB3>ȴ<EFBFBD><C8B4>ݸ<EFBFBD><DDB8><EFBFBD><EFBFBD><EFBFBD>Manager<65><72><EFBFBD>д<EFBFBD><D0B4><EFBFBD> ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>̬
|
||||||
//<2F><><EFBFBD><EFBFBD>m_pManager<65>е<EFBFBD><D0B5><EFBFBD><EFBFBD>һ<E0B2BB><D2BB><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5>õ<EFBFBD>OnReceive<76><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
//<2F><><EFBFBD><EFBFBD>m_pManager<65>е<EFBFBD><D0B5><EFBFBD><EFBFBD>һ<E0B2BB><D2BB><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5>õ<EFBFBD>OnReceive<76><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||||
if (m_DataProcess)
|
if (m_DataProcess)
|
||||||
m_DataProcess(m_Manager, (PBYTE)m_DeCompressedBuffer.GetBuffer(0),
|
m_DataProcess(m_Manager, (PBYTE)DeCompressedBuffer, ulOriginalLength);
|
||||||
m_DeCompressedBuffer.GetBufferLength());
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Mprintf("[ERROR] uncompress fail: dstLen %d, srcLen %d\n", ulOriginalLength, ulCompressedLength);
|
Mprintf("[ERROR] uncompress fail: dstLen %d, srcLen %d\n", ulOriginalLength, ulCompressedLength);
|
||||||
delete [] CompressedBuffer;
|
m_CompressedBuffer.ClearBuffer();
|
||||||
delete [] DeCompressedBuffer;
|
|
||||||
throw "Bad Buffer";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] CompressedBuffer;
|
if (CompressedBuffer != buf1)delete [] CompressedBuffer;
|
||||||
delete [] DeCompressedBuffer;
|
if (DeCompressedBuffer != buf2)delete [] DeCompressedBuffer;
|
||||||
#if _DEBUG
|
|
||||||
// Mprintf("[INFO] uncompress succeed data len: %d expect: %d\n", len, ulPackTotalLength);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Mprintf("[WARNING] OnServerReceiving incomplete data: %d expect: %d\n", len, ulPackTotalLength);
|
break; // received data is incomplete
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(...) {
|
}catch(...) {
|
||||||
@@ -436,13 +427,14 @@ BOOL IOCPClient::OnServerSending(const char* szBuffer, ULONG ulOriginalLength)
|
|||||||
#else
|
#else
|
||||||
unsigned long ulCompressedLength = ZSTD_compressBound(ulOriginalLength);
|
unsigned long ulCompressedLength = ZSTD_compressBound(ulOriginalLength);
|
||||||
#endif
|
#endif
|
||||||
LPBYTE CompressedBuffer = new BYTE[ulCompressedLength];
|
BYTE buf[1024];
|
||||||
|
LPBYTE CompressedBuffer = ulCompressedLength>1024 ? new BYTE[ulCompressedLength] : buf;
|
||||||
|
|
||||||
int iRet = compress(CompressedBuffer, &ulCompressedLength, (PBYTE)szBuffer, ulOriginalLength);
|
int iRet = compress(CompressedBuffer, &ulCompressedLength, (PBYTE)szBuffer, ulOriginalLength);
|
||||||
if (Z_FAILED(iRet))
|
if (Z_FAILED(iRet))
|
||||||
{
|
{
|
||||||
Mprintf("[ERROR] compress failed \n");
|
Mprintf("[ERROR] compress failed: srcLen %d, dstLen %d \n", ulOriginalLength, ulCompressedLength);
|
||||||
delete [] CompressedBuffer;
|
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#if !USING_ZLIB
|
#if !USING_ZLIB
|
||||||
@@ -454,20 +446,15 @@ BOOL IOCPClient::OnServerSending(const char* szBuffer, ULONG ulOriginalLength)
|
|||||||
m_WriteBuffer.WriteBuffer((PBYTE)m_szPacketFlag, FLAG_LENGTH);
|
m_WriteBuffer.WriteBuffer((PBYTE)m_szPacketFlag, FLAG_LENGTH);
|
||||||
|
|
||||||
m_WriteBuffer.WriteBuffer((PBYTE) &ulPackTotalLength,sizeof(ULONG));
|
m_WriteBuffer.WriteBuffer((PBYTE) &ulPackTotalLength,sizeof(ULONG));
|
||||||
// 5 4
|
|
||||||
//[Shine][ 30 ]
|
|
||||||
m_WriteBuffer.WriteBuffer((PBYTE)&ulOriginalLength, sizeof(ULONG));
|
m_WriteBuffer.WriteBuffer((PBYTE)&ulOriginalLength, sizeof(ULONG));
|
||||||
// 5 4 4
|
|
||||||
//[Shine][ 30 ][5]
|
|
||||||
m_WriteBuffer.WriteBuffer(CompressedBuffer,ulCompressedLength);
|
m_WriteBuffer.WriteBuffer(CompressedBuffer,ulCompressedLength);
|
||||||
|
|
||||||
delete [] CompressedBuffer;
|
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||||
CompressedBuffer = NULL;
|
|
||||||
|
|
||||||
// <20>ֿ鷢<D6BF><E9B7A2>
|
// <20>ֿ鷢<D6BF><E9B7A2>
|
||||||
//shine[0035][0010][HelloWorld+12]
|
return SendWithSplit((char*)m_WriteBuffer.GetBuffer(), m_WriteBuffer.GetBufferLength(), MAX_SEND_BUFFER);
|
||||||
return SendWithSplit((char*)m_WriteBuffer.GetBuffer(), m_WriteBuffer.GetBufferLength(),
|
|
||||||
MAX_SEND_BUFFER);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,8 +525,8 @@ VOID IOCPClient::Disconnect()
|
|||||||
|
|
||||||
VOID IOCPClient::RunEventLoop(const BOOL &bCondition)
|
VOID IOCPClient::RunEventLoop(const BOOL &bCondition)
|
||||||
{
|
{
|
||||||
OutputDebugStringA("======> RunEventLoop begin\n");
|
Mprintf("======> RunEventLoop begin\n");
|
||||||
while (m_bIsRunning && bCondition)
|
while (m_bIsRunning && bCondition)
|
||||||
Sleep(200);
|
Sleep(200);
|
||||||
OutputDebugStringA("======> RunEventLoop end\n");
|
Mprintf("======> RunEventLoop end\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
BYTE bToken = COMMAND_BYE;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
BYTE bToken = COMMAND_BYE;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||||
g_bExit = S_CLIENT_EXIT;
|
g_bExit = S_CLIENT_EXIT;
|
||||||
OutputDebugStringA("======> Client exit \n");
|
Mprintf("======> Client exit \n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
|||||||
BYTE bToken = SERVER_EXIT;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
BYTE bToken = SERVER_EXIT;// <20><><EFBFBD>ض<EFBFBD><D8B6>˳<EFBFBD>
|
||||||
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
m_ClientObject->OnServerSending((char*)&bToken, 1);
|
||||||
g_bExit = S_SERVER_EXIT;
|
g_bExit = S_SERVER_EXIT;
|
||||||
OutputDebugStringA("======> Server exit \n");
|
Mprintf("======> Server exit \n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ PerformBaseRelocation(PMEMORYMODULE module, ptrdiff_t delta)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
//printf("Unknown relocation: %d\n", type);
|
// Mprintf("Unknown relocation: %d\n", type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1180,7 +1180,7 @@ BOOL MemoryModuleTestsuite() {
|
|||||||
const uintptr_t* tests = AlignValueDownTests[idx];
|
const uintptr_t* tests = AlignValueDownTests[idx];
|
||||||
uintptr_t value = AlignValueDown(tests[0], tests[1]);
|
uintptr_t value = AlignValueDown(tests[0], tests[1]);
|
||||||
if (value != tests[2]) {
|
if (value != tests[2]) {
|
||||||
printf("AlignValueDown failed for 0x%" PRIxPTR "/0x%" PRIxPTR ": expected 0x%" PRIxPTR ", got 0x%" PRIxPTR "\n",
|
Mprintf("AlignValueDown failed for 0x%" PRIxPTR "/0x%" PRIxPTR ": expected 0x%" PRIxPTR ", got 0x%" PRIxPTR "\n",
|
||||||
tests[0], tests[1], tests[2], value);
|
tests[0], tests[1], tests[2], value);
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
}
|
}
|
||||||
@@ -1189,13 +1189,13 @@ BOOL MemoryModuleTestsuite() {
|
|||||||
const uintptr_t* tests = AlignValueUpTests[idx];
|
const uintptr_t* tests = AlignValueUpTests[idx];
|
||||||
uintptr_t value = AlignValueUp(tests[0], tests[1]);
|
uintptr_t value = AlignValueUp(tests[0], tests[1]);
|
||||||
if (value != tests[2]) {
|
if (value != tests[2]) {
|
||||||
printf("AlignValueUp failed for 0x%" PRIxPTR "/0x%" PRIxPTR ": expected 0x%" PRIxPTR ", got 0x%" PRIxPTR "\n",
|
Mprintf("AlignValueUp failed for 0x%" PRIxPTR "/0x%" PRIxPTR ": expected 0x%" PRIxPTR ", got 0x%" PRIxPTR "\n",
|
||||||
tests[0], tests[1], tests[2], value);
|
tests[0], tests[1], tests[2], value);
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
printf("OK\n");
|
Mprintf("OK\n");
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ private:
|
|||||||
PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,
|
PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,
|
||||||
FALSE, pid);
|
FALSE, pid);
|
||||||
if (!hProcess) {
|
if (!hProcess) {
|
||||||
std::cout << "OpenProcess failed. PID: " << pid << std::endl;
|
Mprintf("OpenProcess failed. PID: %d\n", pid);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,14 +97,14 @@ private:
|
|||||||
BOOL targetIs64Bit = FALSE;
|
BOOL targetIs64Bit = FALSE;
|
||||||
BOOL success = IsProcess64Bit(hProcess, targetIs64Bit);
|
BOOL success = IsProcess64Bit(hProcess, targetIs64Bit);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
std::cout << "Get architecture failed " << std::endl;
|
Mprintf("Get architecture failed \n");
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
const BOOL selfIs64Bit = sizeof(void*) == 8;
|
const BOOL selfIs64Bit = sizeof(void*) == 8;
|
||||||
if (selfIs64Bit != targetIs64Bit) {
|
if (selfIs64Bit != targetIs64Bit) {
|
||||||
std::cout << "[Unable inject] Injector is " << (selfIs64Bit ? "64bit" : "32bit")
|
Mprintf("[Unable inject] Injector is %s, Target process is %s\n",
|
||||||
<< ", Target process is " << (targetIs64Bit ? "64bit" : "32bit") << std::endl;
|
(selfIs64Bit ? "64bit" : "32bit"), (targetIs64Bit ? "64bit" : "32bit"));
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -139,20 +139,20 @@ private:
|
|||||||
LPBYTE shellcode = NULL;
|
LPBYTE shellcode = NULL;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
if (!MakeShellcode(shellcode, len, (LPBYTE)pDllBuffer, dllSize)) {
|
if (!MakeShellcode(shellcode, len, (LPBYTE)pDllBuffer, dllSize)) {
|
||||||
std::cout << "MakeShellcode failed " << std::endl;
|
Mprintf("MakeShellcode failed \n");
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LPVOID remoteBuffer = VirtualAllocEx(hProcess, nullptr, len, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
LPVOID remoteBuffer = VirtualAllocEx(hProcess, nullptr, len, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||||
if (!remoteBuffer) {
|
if (!remoteBuffer) {
|
||||||
std::cout << "VirtualAllocEx failed " << std::endl;
|
Mprintf("VirtualAllocEx failed \n");
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!WriteProcessMemory(hProcess, remoteBuffer, shellcode, len, nullptr)) {
|
if (!WriteProcessMemory(hProcess, remoteBuffer, shellcode, len, nullptr)) {
|
||||||
std::cout << "WriteProcessMemory failed " << std::endl;
|
Mprintf("WriteProcessMemory failed \n");
|
||||||
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
delete[] shellcode;
|
delete[] shellcode;
|
||||||
@@ -165,7 +165,7 @@ private:
|
|||||||
|
|
||||||
HANDLE hThread = CreateRemoteThread(hProcess, nullptr, 0, entry, remoteBuffer, 0, nullptr);
|
HANDLE hThread = CreateRemoteThread(hProcess, nullptr, 0, entry, remoteBuffer, 0, nullptr);
|
||||||
if (!hThread) {
|
if (!hThread) {
|
||||||
std::cout << "CreateRemoteThread failed " << std::endl;
|
Mprintf("CreateRemoteThread failed \n");
|
||||||
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
return false;
|
return false;
|
||||||
@@ -173,7 +173,7 @@ private:
|
|||||||
|
|
||||||
WaitForSingleObject(hThread, INFINITE);
|
WaitForSingleObject(hThread, INFINITE);
|
||||||
|
|
||||||
std::cout << "Finish injecting to PID: " << pid << std::endl;
|
Mprintf("Finish injecting to PID: %d\n", pid);
|
||||||
|
|
||||||
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
VirtualFreeEx(hProcess, remoteBuffer, 0, MEM_RELEASE);
|
||||||
CloseHandle(hThread);
|
CloseHandle(hThread);
|
||||||
|
|||||||
@@ -29,7 +29,11 @@ IsExit bExit = NULL;
|
|||||||
|
|
||||||
BOOL status = 0;
|
BOOL status = 0;
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "6543", CLIENT_TYPE_DLL };
|
||||||
|
#else
|
||||||
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "6543", CLIENT_TYPE_MEMDLL };
|
CONNECT_ADDRESS g_ConnectAddress = { FLAG_FINDEN, "127.0.0.1", "6543", CLIENT_TYPE_MEMDLL };
|
||||||
|
#endif
|
||||||
|
|
||||||
//<2F><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
|
//<2F><><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||||
void DebugPrivilege()
|
void DebugPrivilege()
|
||||||
@@ -266,7 +270,7 @@ int main(int argc, const char *argv[])
|
|||||||
{
|
{
|
||||||
if(!SetSelfStart(argv[0], REG_NAME))
|
if(!SetSelfStart(argv[0], REG_NAME))
|
||||||
{
|
{
|
||||||
std::cout<<"<EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD>ԱȨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n";
|
Mprintf("<EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD>ԱȨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n");
|
||||||
}
|
}
|
||||||
status = 0;
|
status = 0;
|
||||||
SetConsoleCtrlHandler(&callback, TRUE);
|
SetConsoleCtrlHandler(&callback, TRUE);
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ VOID CMy2015RemoteDlg::AddList(CString strIP, CString strAddr, CString strPCName
|
|||||||
EnterCriticalSection(&m_cs);
|
EnterCriticalSection(&m_cs);
|
||||||
if (IsExitItem(m_CList_Online, (ULONG_PTR)ContextObject)) {
|
if (IsExitItem(m_CList_Online, (ULONG_PTR)ContextObject)) {
|
||||||
LeaveCriticalSection(&m_cs);
|
LeaveCriticalSection(&m_cs);
|
||||||
OutputDebugStringA(CString("===> '") + strIP + CString("' already exist!!\n"));
|
Mprintf(CString("===> '") + strIP + CString("' already exist!!\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Ĭ<><C4AC>Ϊ0<CEAA><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//Ĭ<><C4AC>Ϊ0<CEAA><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
@@ -641,11 +641,11 @@ void CMy2015RemoteDlg::OnClose()
|
|||||||
{
|
{
|
||||||
// <20><><EFBFBD>ش<EFBFBD><D8B4>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>ǹر<C7B9>
|
// <20><><EFBFBD>ش<EFBFBD><D8B4>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>ǹر<C7B9>
|
||||||
ShowWindow(SW_HIDE);
|
ShowWindow(SW_HIDE);
|
||||||
OutputDebugStringA("======> Hide\n");
|
Mprintf("======> Hide\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMy2015RemoteDlg::Release(){
|
void CMy2015RemoteDlg::Release(){
|
||||||
OutputDebugStringA("======> Release\n");
|
Mprintf("======> Release\n");
|
||||||
isClosed = TRUE;
|
isClosed = TRUE;
|
||||||
ShowWindow(SW_HIDE);
|
ShowWindow(SW_HIDE);
|
||||||
|
|
||||||
@@ -1101,7 +1101,7 @@ BOOL CMy2015RemoteDlg::Activate(int nPort,int nMaxConnection)
|
|||||||
UINT ret = 0;
|
UINT ret = 0;
|
||||||
if ( (ret=m_iocpServer->StartServer(NotifyProc, OfflineProc, nPort)) !=0 )
|
if ( (ret=m_iocpServer->StartServer(NotifyProc, OfflineProc, nPort)) !=0 )
|
||||||
{
|
{
|
||||||
OutputDebugStringA("======> StartServer Failed \n");
|
Mprintf("======> StartServer Failed \n");
|
||||||
char code[32];
|
char code[32];
|
||||||
sprintf_s(code, "%d", ret);
|
sprintf_s(code, "%d", ret);
|
||||||
MessageBox("<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD>StartServerʧ<EFBFBD><EFBFBD>! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"+CString(code));
|
MessageBox("<EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><EFBFBD><EFBFBD>StartServerʧ<EFBFBD><EFBFBD>! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"+CString(code));
|
||||||
@@ -1339,7 +1339,7 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
|||||||
{
|
{
|
||||||
char buf[100];
|
char buf[100];
|
||||||
sprintf_s(buf, "*** Received [%s] invalid login data! ***\n", inet_ntoa(ClientAddr.sin_addr));
|
sprintf_s(buf, "*** Received [%s] invalid login data! ***\n", inet_ntoa(ClientAddr.sin_addr));
|
||||||
OutputDebugStringA(buf);
|
Mprintf(buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1368,7 +1368,7 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
|||||||
delete LoginInfor;
|
delete LoginInfor;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}catch(...){
|
}catch(...){
|
||||||
OutputDebugStringA("[ERROR] OnUserToOnlineList catch an error \n");
|
Mprintf("[ERROR] OnUserToOnlineList catch an error \n");
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -1376,7 +1376,7 @@ LRESULT CMy2015RemoteDlg::OnUserToOnlineList(WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
LRESULT CMy2015RemoteDlg::OnUserOfflineMsg(WPARAM wParam, LPARAM lParam)
|
LRESULT CMy2015RemoteDlg::OnUserOfflineMsg(WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
OutputDebugStringA("======> OnUserOfflineMsg\n");
|
Mprintf("======> OnUserOfflineMsg\n");
|
||||||
CString ip, port;
|
CString ip, port;
|
||||||
port.Format("%d", lParam);
|
port.Format("%d", lParam);
|
||||||
EnterCriticalSection(&m_cs);
|
EnterCriticalSection(&m_cs);
|
||||||
|
|||||||
@@ -947,18 +947,18 @@ void CFileManagerDlg::OnReceiveComplete()
|
|||||||
}
|
}
|
||||||
catch (CMemoryException* e)
|
catch (CMemoryException* e)
|
||||||
{
|
{
|
||||||
OutputDebugStringA("[ERROR] CMemoryException\n");
|
Mprintf("[ERROR] CMemoryException\n");
|
||||||
}
|
}
|
||||||
catch (CFileException* e)
|
catch (CFileException* e)
|
||||||
{
|
{
|
||||||
OutputDebugStringA("[ERROR] CFileException\n");
|
Mprintf("[ERROR] CFileException\n");
|
||||||
}
|
}
|
||||||
catch (CException* e)
|
catch (CException* e)
|
||||||
{
|
{
|
||||||
OutputDebugStringA("[ERROR] CException\n");
|
Mprintf("[ERROR] CException\n");
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
OutputDebugStringA("[ERROR] Other exception\n");
|
Mprintf("[ERROR] Other exception\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TOKEN_FILE_SIZE: // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD>ĵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
case TOKEN_FILE_SIZE: // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD>ĵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ BOOL IOCPServer::InitializeIOCP(VOID)
|
|||||||
|
|
||||||
DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
||||||
{
|
{
|
||||||
OutputDebugStringA("======> IOCPServer WorkThreadProc begin \n");
|
Mprintf("======> IOCPServer WorkThreadProc begin \n");
|
||||||
|
|
||||||
IOCPServer* This = (IOCPServer*)(lParam);
|
IOCPServer* This = (IOCPServer*)(lParam);
|
||||||
|
|
||||||
@@ -362,7 +362,7 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
|||||||
if (ContextObject && This->m_bTimeToKill == FALSE &&dwTrans==0)
|
if (ContextObject && This->m_bTimeToKill == FALSE &&dwTrans==0)
|
||||||
{
|
{
|
||||||
ContextObject->olps = NULL;
|
ContextObject->olps = NULL;
|
||||||
OutputDebugStringA("!!! RemoveStaleContext \n");
|
Mprintf("!!! RemoveStaleContext \n");
|
||||||
This->RemoveStaleContext(ContextObject);
|
This->RemoveStaleContext(ContextObject);
|
||||||
}
|
}
|
||||||
SAFE_DELETE(OverlappedPlus);
|
SAFE_DELETE(OverlappedPlus);
|
||||||
@@ -416,7 +416,7 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
|||||||
ContextObject = NULL;
|
ContextObject = NULL;
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
OutputDebugStringA("This->HandleIO catched an error!!!");
|
Mprintf("This->HandleIO catched an error!!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,7 +432,7 @@ DWORD IOCPServer::WorkThreadProc(LPVOID lParam)
|
|||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
Mprintf("======> IOCPServer All WorkThreadProc done\n");
|
Mprintf("======> IOCPServer All WorkThreadProc done\n");
|
||||||
}
|
}
|
||||||
OutputDebugStringA("======> IOCPServer WorkThreadProc end \n");
|
Mprintf("======> IOCPServer WorkThreadProc end \n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -454,7 +454,7 @@ BOOL IOCPServer::HandleIO(IOType PacketFlags,PCONTEXT_OBJECT ContextObject, DWOR
|
|||||||
bRet = OnClientPostSending(ContextObject,dwTrans);
|
bRet = OnClientPostSending(ContextObject,dwTrans);
|
||||||
break;
|
break;
|
||||||
case IOIdle:
|
case IOIdle:
|
||||||
OutputDebugStringA("=> HandleIO PacketFlags= IOIdle\n");
|
Mprintf("=> HandleIO PacketFlags= IOIdle\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -512,7 +512,7 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
|
|||||||
ContextObject->Decode(CompressedBuffer, ulOriginalLength);
|
ContextObject->Decode(CompressedBuffer, ulOriginalLength);
|
||||||
m_NotifyProc(ContextObject);
|
m_NotifyProc(ContextObject);
|
||||||
SAFE_DELETE_ARRAY(CompressedBuffer);
|
SAFE_DELETE_ARRAY(CompressedBuffer);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
bool usingZstd = ContextObject->CompressMethod == COMPRESS_ZSTD, zlibFailed = false;
|
bool usingZstd = ContextObject->CompressMethod == COMPRESS_ZSTD, zlibFailed = false;
|
||||||
PBYTE DeCompressedBuffer = new BYTE[ulOriginalLength]; //<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
PBYTE DeCompressedBuffer = new BYTE[ulOriginalLength]; //<2F><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
|
||||||
@@ -522,7 +522,6 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
|
|||||||
if (usingZstd ? C_SUCCESS(iRet) : (S_OK==iRet))
|
if (usingZstd ? C_SUCCESS(iRet) : (S_OK==iRet))
|
||||||
{
|
{
|
||||||
ContextObject->InDeCompressedBuffer.ClearBuffer();
|
ContextObject->InDeCompressedBuffer.ClearBuffer();
|
||||||
//ContextObject->InCompressedBuffer.ClearBuffer();
|
|
||||||
ContextObject->InDeCompressedBuffer.WriteBuffer(DeCompressedBuffer, ulOriginalLength);
|
ContextObject->InDeCompressedBuffer.WriteBuffer(DeCompressedBuffer, ulOriginalLength);
|
||||||
ContextObject->Decode(DeCompressedBuffer, ulOriginalLength);
|
ContextObject->Decode(DeCompressedBuffer, ulOriginalLength);
|
||||||
m_NotifyProc(ContextObject); //֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD>
|
m_NotifyProc(ContextObject); //֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD>
|
||||||
@@ -544,7 +543,7 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
|
|||||||
delete [] CompressedBuffer;
|
delete [] CompressedBuffer;
|
||||||
delete [] DeCompressedBuffer;
|
delete [] DeCompressedBuffer;
|
||||||
if (zlibFailed) {
|
if (zlibFailed) {
|
||||||
OutputDebugStringA("[ERROR] ZLIB uncompress failed \n");
|
Mprintf("[ERROR] ZLIB uncompress failed \n");
|
||||||
throw "Bad Buffer";
|
throw "Bad Buffer";
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@@ -553,7 +552,7 @@ BOOL IOCPServer::OnClientReceiving(PCONTEXT_OBJECT ContextObject, DWORD dwTrans
|
|||||||
}
|
}
|
||||||
}catch(...)
|
}catch(...)
|
||||||
{
|
{
|
||||||
OutputDebugStringA("[ERROR] OnClientReceiving catch an error \n");
|
Mprintf("[ERROR] OnClientReceiving catch an error \n");
|
||||||
ContextObject->InCompressedBuffer.ClearBuffer();
|
ContextObject->InCompressedBuffer.ClearBuffer();
|
||||||
ContextObject->InDeCompressedBuffer.ClearBuffer();
|
ContextObject->InDeCompressedBuffer.ClearBuffer();
|
||||||
}
|
}
|
||||||
@@ -574,7 +573,7 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
|||||||
else {
|
else {
|
||||||
memcpy(buf, szBuffer, ulOriginalLength);
|
memcpy(buf, szBuffer, ulOriginalLength);
|
||||||
}
|
}
|
||||||
OutputDebugStringA("[COMMAND] Send: " + CString(buf) + "\r\n");
|
Mprintf("[COMMAND] Send: " + CString(buf) + "\r\n");
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -582,7 +581,7 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
|||||||
{
|
{
|
||||||
if (ulOriginalLength <= 0) return;
|
if (ulOriginalLength <= 0) return;
|
||||||
if (ContextObject->CompressMethod == COMPRESS_UNKNOWN) {
|
if (ContextObject->CompressMethod == COMPRESS_UNKNOWN) {
|
||||||
OutputDebugStringA("[ERROR] UNKNOWN compress method \n");
|
Mprintf("[ERROR] UNKNOWN compress method \n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (ContextObject->CompressMethod == COMPRESS_NONE) {
|
else if (ContextObject->CompressMethod == COMPRESS_NONE) {
|
||||||
@@ -596,7 +595,8 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
|||||||
unsigned long ulCompressedLength = usingZstd ?
|
unsigned long ulCompressedLength = usingZstd ?
|
||||||
ZSTD_compressBound(ulOriginalLength) : (double)ulOriginalLength * 1.001 + 12;
|
ZSTD_compressBound(ulOriginalLength) : (double)ulOriginalLength * 1.001 + 12;
|
||||||
#endif
|
#endif
|
||||||
LPBYTE CompressedBuffer = new BYTE[ulCompressedLength];
|
BYTE buf[1024];
|
||||||
|
LPBYTE CompressedBuffer = ulCompressedLength>1024 ? new BYTE[ulCompressedLength]:buf;
|
||||||
Buffer tmp(szBuffer, ulOriginalLength); szBuffer = tmp.Buf();
|
Buffer tmp(szBuffer, ulOriginalLength); szBuffer = tmp.Buf();
|
||||||
ContextObject->Encode(szBuffer, ulOriginalLength);
|
ContextObject->Encode(szBuffer, ulOriginalLength);
|
||||||
size_t iRet = usingZstd ?
|
size_t iRet = usingZstd ?
|
||||||
@@ -605,15 +605,15 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
|||||||
|
|
||||||
if (usingZstd ? C_FAILED(iRet) : (S_OK != iRet))
|
if (usingZstd ? C_FAILED(iRet) : (S_OK != iRet))
|
||||||
{
|
{
|
||||||
OutputDebugStringA("[ERROR] compress failed \n");
|
Mprintf("[ERROR] compress failed \n");
|
||||||
delete [] CompressedBuffer;
|
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulCompressedLength = usingZstd ? iRet : ulCompressedLength;
|
ulCompressedLength = usingZstd ? iRet : ulCompressedLength;
|
||||||
|
|
||||||
ContextObject->WriteBuffer(CompressedBuffer, ulCompressedLength, ulOriginalLength);
|
ContextObject->WriteBuffer(CompressedBuffer, ulCompressedLength, ulOriginalLength);
|
||||||
delete [] CompressedBuffer;
|
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||||
}while (false);
|
}while (false);
|
||||||
|
|
||||||
OVERLAPPEDPLUS* OverlappedPlus = new OVERLAPPEDPLUS(IOWrite);
|
OVERLAPPEDPLUS* OverlappedPlus = new OVERLAPPEDPLUS(IOWrite);
|
||||||
@@ -621,12 +621,12 @@ VOID IOCPServer::OnClientPreSending(CONTEXT_OBJECT* ContextObject, PBYTE szBuffe
|
|||||||
if ( (!bOk && GetLastError() != ERROR_IO_PENDING) ) //<2F><><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ʧ<EFBFBD><CAA7>
|
if ( (!bOk && GetLastError() != ERROR_IO_PENDING) ) //<2F><><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ʧ<EFBFBD><CAA7>
|
||||||
{
|
{
|
||||||
int a = GetLastError();
|
int a = GetLastError();
|
||||||
OutputDebugStringA("!!! OnClientPreSending Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
Mprintf("!!! OnClientPreSending Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||||
RemoveStaleContext(ContextObject);
|
RemoveStaleContext(ContextObject);
|
||||||
SAFE_DELETE(OverlappedPlus);
|
SAFE_DELETE(OverlappedPlus);
|
||||||
}
|
}
|
||||||
}catch(...){
|
}catch(...){
|
||||||
OutputDebugStringA("[ERROR] OnClientPreSending catch an error \n");
|
Mprintf("[ERROR] OnClientPreSending catch an error \n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,13 +653,13 @@ BOOL IOCPServer::OnClientPostSending(CONTEXT_OBJECT* ContextObject,ULONG ulCompl
|
|||||||
if ( iOk == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING )
|
if ( iOk == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING )
|
||||||
{
|
{
|
||||||
int a = GetLastError();
|
int a = GetLastError();
|
||||||
OutputDebugStringA("!!! OnClientPostSending Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
Mprintf("!!! OnClientPostSending Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||||
RemoveStaleContext(ContextObject);
|
RemoveStaleContext(ContextObject);
|
||||||
SAFE_DELETE(OverlappedPlus);
|
SAFE_DELETE(OverlappedPlus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(...){
|
}catch(...){
|
||||||
OutputDebugStringA("[ERROR] OnClientPostSending catch an error \n");
|
Mprintf("[ERROR] OnClientPostSending catch an error \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -775,7 +775,7 @@ void IOCPServer::OnAccept()
|
|||||||
if ( (!bOk && GetLastError() != ERROR_IO_PENDING)) //<2F><><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ʧ<EFBFBD><CAA7>
|
if ( (!bOk && GetLastError() != ERROR_IO_PENDING)) //<2F><><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ʧ<EFBFBD><CAA7>
|
||||||
{
|
{
|
||||||
int a = GetLastError();
|
int a = GetLastError();
|
||||||
OutputDebugStringA("!!! OnAccept Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
Mprintf("!!! OnAccept Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||||
RemoveStaleContext(ContextObject);
|
RemoveStaleContext(ContextObject);
|
||||||
SAFE_DELETE(OverlappedPlus);
|
SAFE_DELETE(OverlappedPlus);
|
||||||
return;
|
return;
|
||||||
@@ -800,7 +800,7 @@ VOID IOCPServer::PostRecv(CONTEXT_OBJECT* ContextObject)
|
|||||||
if (iOk == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING)
|
if (iOk == SOCKET_ERROR && WSAGetLastError() != WSA_IO_PENDING)
|
||||||
{
|
{
|
||||||
int a = GetLastError();
|
int a = GetLastError();
|
||||||
OutputDebugStringA("!!! PostRecv Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
Mprintf("!!! PostRecv Ͷ<><CDB6><EFBFBD><EFBFBD>Ϣʧ<CFA2><CAA7>\n");
|
||||||
RemoveStaleContext(ContextObject);
|
RemoveStaleContext(ContextObject);
|
||||||
SAFE_DELETE(OverlappedPlus);
|
SAFE_DELETE(OverlappedPlus);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ public:
|
|||||||
#if TRACK_OVERLAPPEDPLUS
|
#if TRACK_OVERLAPPEDPLUS
|
||||||
char szLog[100];
|
char szLog[100];
|
||||||
sprintf_s(szLog, "=> [new] OVERLAPPEDPLUS %p by thread [%d].\n", this, GetCurrentThreadId());
|
sprintf_s(szLog, "=> [new] OVERLAPPEDPLUS %p by thread [%d].\n", this, GetCurrentThreadId());
|
||||||
OutputDebugStringA(szLog);
|
Mprintf(szLog);
|
||||||
#endif
|
#endif
|
||||||
ZeroMemory(this, sizeof(OVERLAPPEDPLUS));
|
ZeroMemory(this, sizeof(OVERLAPPEDPLUS));
|
||||||
m_ioType = ioType;
|
m_ioType = ioType;
|
||||||
@@ -381,7 +381,7 @@ public:
|
|||||||
#if TRACK_OVERLAPPEDPLUS
|
#if TRACK_OVERLAPPEDPLUS
|
||||||
char szLog[100];
|
char szLog[100];
|
||||||
sprintf_s(szLog, "=> [delete] OVERLAPPEDPLUS %p by thread [%d].\n", this, GetCurrentThreadId());
|
sprintf_s(szLog, "=> [delete] OVERLAPPEDPLUS %p by thread [%d].\n", this, GetCurrentThreadId());
|
||||||
OutputDebugStringA(szLog);
|
Mprintf(szLog);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// CSystemDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
// CSystemDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
|
||||||
|
|
||||||
typedef struct
|
typedef struct ItemData
|
||||||
{
|
{
|
||||||
DWORD ID;
|
DWORD ID;
|
||||||
CString Data[3];
|
CString Data[3];
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ void CVideoDlg::InitCodec(DWORD fccHandler)
|
|||||||
m_pVideoCodec = new CVideoCodec;
|
m_pVideoCodec = new CVideoCodec;
|
||||||
if (!m_pVideoCodec->InitCompressor(m_BitmapInfor_Full, fccHandler))
|
if (!m_pVideoCodec->InitCompressor(m_BitmapInfor_Full, fccHandler))
|
||||||
{
|
{
|
||||||
OutputDebugStringA("======> InitCompressor failed \n");
|
Mprintf("======> InitCompressor failed \n");
|
||||||
delete m_pVideoCodec;
|
delete m_pVideoCodec;
|
||||||
// <20><>NULL, <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ΪNULL<4C><4C><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ѹ<EFBFBD><D1B9>
|
// <20><>NULL, <20><><EFBFBD><EFBFBD>ʱ<EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ΪNULL<4C><4C><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ѹ<EFBFBD><D1B9>
|
||||||
m_pVideoCodec = NULL;
|
m_pVideoCodec = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user