mircode.cpp
资源名称:盛大传奇外挂原代码.rar [点击查看]
上传用户:marco7834
上传日期:2010-02-24
资源大小:82k
文件大小:3k
源码类别:
游戏引擎
开发平台:
Visual C++
- // mircode.cpp: implementation of the mircode class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "mircode.h"
- #include "bindef.h"
- #include <stdio.h>
- char ucase( char c )
- {
- // char cres = ' ';
- if( c >= 'a' && c <= 'z' )
- {
- c+= 'A' - 'a';
- return c;
- }
- return c;
- }
- int hex2int( char c )
- {
- if( c >= 'A' && c <= 'F' )
- {
- return (int)(c - 'A' + 10 );
- }
- else if( c >= '0' && c <= '9' )
- {
- return (int)( c - '0' );
- }
- return 0;
- }
- char hextable[] = "0123456789ABCDEF";
- char int2hex( int v )
- {
- v &= 0xf;
- return hextable[v];
- }
- int UnNameCode( char * in, char * out )
- {
- int i = 0;
- //int size = strlen( in );
- while( in[i] != ' ' )
- {
- out[i] = (in[i] & 0x3f ) << 2;
- out[i] |= (in[i + 1] & 0xc0 ) >> 6;
- i ++;
- }
- out[i] = ' ';
- return 1;
- }
- int CodeGateCode( char * in, char * out )
- {
- int lcnt = strlen( in ) ;
- int i = 0;
- int icode = 0;
- int tcode = 0;
- int hbyte = 0;
- int lbyte = 0;
- int _edi = 0xf667;
- for( i = 0;i < lcnt;i ++ )
- {
- icode = ((int)in[i]) & 0xff;
- //tcode = icode;
- //icode = ((int)out[i]) & 0xff;
- tcode = icode;
- tcode ^= ((_edi & 0xffff)>>8);
- hbyte = (tcode & 0xf0 )>>4;
- lbyte = (tcode & 0xf );
- out[i * 2] = int2hex( hbyte );
- out[i * 2 + 1] = int2hex( lbyte );
- _edi = (((_edi + tcode ) * 0xce6d ) & 0xffff ) + 0x58bf;
- }
- out[i * 2] = ' ';
- return 1;
- }
- int UnGateCode( char * in, char * out )
- {
- if( in == NULL )
- return 0;
- int lcnt = strlen( in ) >> 1;
- if( lcnt == 0 )
- return 0;
- if( in[0] == (char)0)//' ' )
- return 0;
- int i = 0;
- int icode = 0;
- int _edi = 0xf667;
- for( i = 0;i < lcnt;i ++ )
- {
- out[i] = ((hex2int( ucase( in[i * 2])) & 0xf )<<4);
- out[i] += hex2int( ucase( in[i * 2 + 1])) & 0xf;
- icode = ((int)out[i]) & 0xff;
- out[i] ^= ((_edi & 0xffff)>>8);
- _edi = (((_edi + icode ) * 0xce6d ) & 0xffff ) + 0x58bf;
- }
- out[lcnt] = (char)0;//' ';
- return 1;
- }
- int UnGameCode( char * p, BYTE * out )
- {
- int i = 0;
- int ilen = 0, olen = 0;
- int iptr = 0, optr = 0;
- BYTE * pb = (BYTE*)p;
- BYTE b1,b2,b3,b4;
- if( p == NULL || out == NULL)
- return 0;
- ilen = strlen( p );
- if( ilen <= 0 )
- return 0;
- *((DWORD*)&p[ilen]) = 0x3c3c3c;
- olen = (ilen * 6) / 8;
- for( i =0;i < ((ilen + 3)/4);i ++ )
- {
- b1 = (pb[iptr++] - 0x3c) & 0x3f;
- b2 = (pb[iptr++] - 0x3c) & 0x3f;
- b3 = (pb[iptr++] - 0x3c) & 0x3f;
- b4 = (pb[iptr++] - 0x3c) & 0x3f;
- out[optr++] =(( b1 & b00111111) << 2 )| ((b2 & b00110000) >> 4);
- out[optr++] =(( b2 & b00001111) << 4 )| ((b3 & b00111100) >> 2);
- out[optr++] =(( b3 & b00000011) << 6 )| b4;
- }
- out[olen] = ' ';
- return olen;
- }
- int CodeGameCode( BYTE * in, int size, BYTE * out )
- {
- int i = 0,ilen = 0;
- int idxout = 0;
- int idxin = 0;
- // int icode = 0;
- int reallen = 0;
- ilen = size;
- ilen = (size + 2)/3;
- BYTE b1,b2,b3;
- reallen = (size * 8 + 5) / 6;
- (*(DWORD*)&in[size])=0;
- // ileft = size % 3;
- for( i = 0;i < ilen;i ++ )
- {
- b1 = in[idxin++];
- b2 = in[idxin++];
- b3 = in[idxin++];
- out[idxout++] = ((b1 & b11111100) >> 2)+'<';
- out[idxout++] = (((b1 & b00000011) << 4)|((b2 & b11110000) >> 4))+'<';
- out[idxout++] = (((b2 & b00001111) << 2)|((b3 & b11000000) >> 6))+'<';
- out[idxout++] = (b3 & b00111111)+'<';
- }
- out[reallen]= ' ';
- return 1;
- }