/*
这是一个简单的传奇游戏tcp数据包解密程序,不够完整有点小问题
当登陆传奇时候 帐号和密码是通过封包模式发送,格式为:帐号/密码
例如:帐号为wuyu 密码位wuyu 则格式为wuyu/wuyu 加密后为 HguIEOKJpGTnk`paYsQuYNysYSaq
加密方法未知,现在帐号和密码一起长度为10位可以正常解密
传奇版本更新当帐号密码长度一起大于10位解密就出现乱码
看看问题出在哪里
*/
#include <windows.h>
#include <stdio.h>
static unsigned char Decode6BitMask[6] = { 0xfc, 0xf8, 0xf0, 0xe0, 0xc0 };
int WINAPI fnDecode6BitBuf(char *pszSrc, char *pszDest, int nDestLen)
{
int nLen = strlen((const char *)pszSrc);
int nDestPos = 0, nBitPos = 2;
int nMadeBit = 0;
unsigned char ch, chCode, tmp;
for (int i = 0; i < nLen; i++)
{
if ((pszSrc[i] - 0x3c) >= 0)
{
ch = pszSrc[i] - 0x3c;
}
else
{
nDestPos = 0;
break;
}
if (nDestPos >= nDestLen) break;
if ((nMadeBit + 6) >= 8)
{
chCode = (tmp | ((ch & 0x3f) >> (6 - nBitPos)));
pszDest[nDestPos++] = chCode;
nMadeBit = 0;
if (nBitPos <6)
nBitPos += 2;
else
{
nBitPos = 2;
continue;
}
}
tmp = ((ch << nBitPos) & Decode6BitMask[nBitPos - 2]);
nMadeBit += (8 - nBitPos);
}
// pszDest[nDestPos] = '\0';
return nDestPos;
}
void main()
{
typedef struct
{
union
{
DWORD dwFlag;
struct
{
WORD wa;
WORD wb;
};
};
WORD wCmd;
WORD w1;
WORD w2;
WORD w3;
char data[1024];
}MMSG;
MMSG *msg1;
char m_tmpBuffer2[100],TcpData[256];
strcpy(m_tmpBuffer2,"HguIEOKJpGTnk`paYsQuYNysYSaq");//wuyu/wuyu
msg1=(MMSG*)malloc(sizeof(MMSG));
memset(msg1,0,sizeof(MMSG));
memset(TcpData,0,sizeof(TcpData));
fnDecode6BitBuf(&m_tmpBuffer2[0],TcpData,strlen(m_tmpBuffer2));
msg1=(MMSG *)&TcpData[0];
printf("\n%s\n",msg1->data);
strcpy(m_tmpBuffer2,"<>o{s[Tfpyp>GK{Yv`^hHGdKdoomW@fkNgm[>{PyykOvIJ{p{`{ewK\\myzouIvOi");//wuyoua/wuyoua
//用户名+密码超过10个字就不能用fnDecode6BitBuf()函数解密了 (加密方法完全一样)
//strlen("wuyoua")+strlen("wuyoua")>10
//问题应该是出在fnDecode6BitBuf() 考虑的位数不够
msg1=(MMSG*)malloc(sizeof(MMSG));
memset(msg1,0,sizeof(MMSG));
memset(TcpData,0,sizeof(TcpData));
fnDecode6BitBuf(&m_tmpBuffer2[0],TcpData,strlen(m_tmpBuffer2));
msg1=(MMSG *)&TcpData[0];
printf("\n%s\n",msg1->data);
Sleep(5333);
}
//知道的请加我qq80885088 谢谢了