贝贝游戏 网址www.game499.com 这个游戏和其他的网狐的客服端不同,界面不同其次主要的不同是他们数据加密方法不同,传统的数据加密方式如下,因为手上有网狐的源码所以直接上源码
//加密数据
WORD CTCPSocket::EncryptBuffer(BYTE pcbDataBuffer[], WORD wDataSize, WORD wBufferSize)
{
//效验参数
ASSERT(wDataSize>=sizeof(TCP_Head));
ASSERT(wBufferSize>=(wDataSize+2*sizeof(DWORD)));
ASSERT(wDataSize<=(sizeof(TCP_Head)+SOCKET_TCP_PACKET));
//调整长度
WORD wEncryptSize=wDataSize-sizeof(TCP_Command),wSnapCount=0;
if ((wEncryptSize%sizeof(DWORD))!=0)
{
wSnapCount=sizeof(DWORD)-wEncryptSize%sizeof(DWORD);
memset(pcbDataBuffer+sizeof(TCP_Info)+wEncryptSize,0,wSnapCount);
}
//效验码与字节映射
BYTE cbCheckCode=0;
for (WORD i=sizeof(TCP_Info);i<wDataSize;i++)
{
cbCheckCode+=pcbDataBuffer[i];
pcbDataBuffer[i]=MapSendByte(pcbDataBuffer[i]);
}
return wDataSize;
}
<pre name="code" class="cpp">//解密数据
WORD CTCPSocket::CrevasseBuffer(BYTE pcbDataBuffer[], WORD wDataSize)
{
//效验参数
ASSERT(m_dwSendPacketCount>0);
ASSERT(wDataSize>=sizeof(TCP_Head));
ASSERT(((TCP_Head *)pcbDataBuffer)->TCPInfo.wPacketSize==wDataSize);
//调整长度
WORD wSnapCount=0;
if ((wDataSize%sizeof(DWORD))!=0)
{
wSnapCount=sizeof(DWORD)-wDataSize%sizeof(DWORD);
memset(pcbDataBuffer+wDataSize,0,wSnapCount);
}
//解密数据
DWORD dwXorKey=m_dwRecvXorKey;
DWORD * pdwXor=(DWORD *)(pcbDataBuffer+sizeof(TCP_Info));
WORD * pwSeed=(WORD *)(pcbDataBuffer+sizeof(TCP_Info));
WORD wEncrypCount=(wDataSize+wSnapCount-sizeof(TCP_Info))/4;
for (WORD i=0;i<wEncrypCount;i++)
{
if ((i==(wEncrypCount-1))&&(wSnapCount>0))
{
BYTE * pcbKey=((BYTE *)&m_dwRecvXorKey)+sizeof(DWORD)-wSnapCount;
CopyMemory(pcbDataBuffer+wDataSize,pcbKey,wSnapCount);
}
dwXorKey=SeedRandMap(*pwSeed++);
dwXorKey|=((DWORD)SeedRandMap(*pwSeed++))<<16;
dwXorKey^=g_dwPacketKey;
*pdwXor++^=m_dwRecvXorKey;
m_dwRecvXorKey=dwXorKey;
}
//效验码与字节映射
TCP_Head * pHead=(TCP_Head *)pcbDataBuffer;
BYTE cbCheckCode=pHead->TCPInfo.cbCheckCode;
for (int i=sizeof(TCP_Info);i<wDataSize;i++)
{
pcbDataBuffer[i]=MapRecvByte(pcbDataBuffer[i]);
cbCheckCode+=pcbDataBuffer[i];
}
if (cbCheckCode!=0) throw TEXT("数据包效验码错误");