Initial MSVC 2008 projects workspace

This commit is contained in:
alexey.min
2012-02-01 05:25:08 +00:00
commit 03de3bdc95
1446 changed files with 476853 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
#include "stdafx.h"
#include "L2Login_RequestAuthLogin.h"
L2Login_RequestAuthLogin::L2Login_RequestAuthLogin()
{
_initNull();
}
L2Login_RequestAuthLogin::L2Login_RequestAuthLogin( const unsigned char *bytes, unsigned int length )
{
_initNull();
setBytes( bytes, length );
}
// RSA_pubKeyMod must point to 128-bytes length buffer
bool L2Login_RequestAuthLogin::create( const char *szL2Login, const char *szL2Password,
unsigned int ggAuthResponse, const unsigned char *RSA_pubKeyMod )
{
// assert
if( !szL2Login || !szL2Password ) return false;
// vars
size_t l2l_len = strlen( szL2Login );
size_t l2p_len = strlen( szL2Password );
char l2login[L2_LOGIN_MAXLEN];
char l2password[L2_PASSWORD_MAXLEN];
unsigned char block128[128];
int i = 0;
const int l2l_offset = 94;
const int l2p_offset = 108;
// memsets
memset( l2login, 0, sizeof(l2login) );
memset( l2password, 0, sizeof(l2password) );
memset( block128, 0, sizeof(block128) );
// check strings length
if( (l2l_len<1) || (l2l_len>L2_LOGIN_MAXLEN) )
{
printf( "L2Login_RequestAuthLogin::create(): L2 Login length must be [1..%d] chars\n",
L2_LOGIN_MAXLEN );
return false;
}
if( (l2p_len<1) || (l2p_len>L2_PASSWORD_MAXLEN) )
{
printf( "L2Login_RequestAuthLogin::create(): L2 Password length must be [1..%d] chars\n",
L2_PASSWORD_MAXLEN );
return false;
}
// copy strings
for( i=0; i<(int)l2l_len; i++ ) l2login[i] = szL2Login[i];
for( i=0; i<(int)l2p_len; i++ ) l2password[i] = szL2Password[i];
// copy login/pass to 128-byte block
memcpy( (void *)(block128 + l2l_offset), l2login, L2_LOGIN_MAXLEN );
memcpy( (void *)(block128 + l2p_offset), l2password, L2_PASSWORD_MAXLEN );
// RSA encode block...
if( !this->block_encode_RSA( block128, sizeof(block128), RSA_pubKeyMod ) ) return false;
// construct packet
this->writeReset();
this->setPacketType( 0x00 ); // RequestAuthLogin code
this->writeBytes( block128, sizeof(block128) ); // block with login/password
this->writeUInt( ggAuthResponse ); // from GGAuthResponse
for( i=0; i<16; i++ ) this->writeUChar( 0x00 ); // 16 NULLs
this->writeUChar( 0x08 );
for( i=0; i<10; i++ ) this->writeUChar( 0x00 ); // some 11 bytes
// now packet must be padded to 8-byte border
// next caller must add checksum, and so on...
return true;
}
// for internal use only
// encode block with login/password
// RSA_pubKeyMod must point to 128-bytes length buffer
bool L2Login_RequestAuthLogin::block_encode_RSA( unsigned char *block , unsigned int blockSize,
const unsigned char *RSA_pubKeyMod )
{
if( !block || (blockSize<1) || !RSA_pubKeyMod ) return false;
bool retVal = true;
unsigned char blockE[128];
memset( blockE, 0, sizeof(blockE) );
// allocate & initialize RSA struct
RSA *rsa = RSA_new();
// set exponent and n
rsa->e = BN_new();
BN_dec2bn( &(rsa->e), "65537" ); // exponent is constant, 65537
rsa->n = BN_bin2bn( RSA_pubKeyMod, 128, NULL ); // n is taken from unscrambled RSA public key modulus from Init packet
//printf( "RSA_size: %d\n", RSA_size( rsa ) );
int res = RSA_public_encrypt( 128, block, blockE, rsa, RSA_NO_PADDING );
if( res == -1 )
{
retVal = false;
fprintf( stderr, "RSA_public_encrypt res: %d\n", res );
ERR_print_errors_fp( stderr );
}
// store result...
memcpy( block, blockE, 128 );
// free RSA struct
RSA_free( rsa );
rsa = NULL;
return retVal;
}
bool L2Login_RequestAuthLogin::block_decode_RSA( unsigned char *block , unsigned int blockSize,
const unsigned char *RSA_pubKeyMod )
{
if( !block || (blockSize<1) || !RSA_pubKeyMod ) return false;
bool retVal = true;
unsigned char blockE[128];
memset( blockE, 0, sizeof(blockE) );
// allocate & initialize RSA struct
RSA *rsa = RSA_new();
// set exponent and n
rsa->e = BN_new();
BN_dec2bn( &(rsa->e), "65537" ); // exponent is constant, 65537
rsa->n = BN_bin2bn( RSA_pubKeyMod, 128, NULL ); // n is taken from unscrambled RSA public key modulus from Init packet
int res = RSA_private_decrypt( 128, block, blockE, rsa, RSA_NO_PADDING );
if( res == -1 )
{
retVal = false;
fprintf( stderr, "RSA_private_decrypt res: %d\n", res );
ERR_print_errors_fp( stderr );
}
// store result...
memcpy( block, blockE, 128 );
// free RSA struct
RSA_free( rsa );
rsa = NULL;
return retVal;
}
bool L2Login_RequestAuthLogin::parse( L2_VERSION ver /*= L2_VERSION_T1*/ )
{
UNREFERENCED_PARAMETER(ver);
fprintf( stderr, "L2Login_RequestAuthLogin::parse() not implemented!\n" );
return false;
}

View File

@@ -0,0 +1,36 @@
#ifndef L2LOGIN_REQUESTAUTHLOGIN_H_
#define L2LOGIN_REQUESTAUTHLOGIN_H_
#include "../L2LoginPacket.h"
#define L2_LOGIN_MAXLEN 14
#define L2_PASSWORD_MAXLEN 16
class L2Login_RequestAuthLogin: public L2LoginPacket
{
public:
L2Login_RequestAuthLogin();
L2Login_RequestAuthLogin( const unsigned char *bytes, unsigned int length );
public:
// RSA_pubKeyMod must point to 128-bytes length buffer
bool create( const char *szL2Login, const char *szL2Password,
unsigned int ggAuthResponse, const unsigned char *RSA_pubKeyMod );
//virtual bool create( L2_VERSION ver = L2_VERSION_T1 );
virtual bool parse( L2_VERSION ver = L2_VERSION_T1 );
public:
char strLogin[32];
char strPassword[32];
unsigned int uGGAuthResponse;
protected:
// for internal use only
// encode block with login/password
// RSA_pubKeyMod must point to 128-bytes length buffer
bool block_encode_RSA( unsigned char *block , unsigned int blockSize,
const unsigned char *RSA_pubKeyMod );
bool block_decode_RSA( unsigned char *block , unsigned int blockSize,
const unsigned char *RSA_pubKeyMod );
};
#endif /*L2LOGIN_REQUESTAUTHLOGIN_H_*/

View File

@@ -0,0 +1,43 @@
#include "stdafx.h"
#include "L2Login_RequestGGAuth.h"
L2Login_RequestGGAuth::L2Login_RequestGGAuth()
{
this->_initNull();
sessionId[0] = sessionId[1] = sessionId[2] = sessionId[3] = 0;
}
L2Login_RequestGGAuth::L2Login_RequestGGAuth( const unsigned char *bytes, unsigned int length )
{
this->_initNull();
this->setBytes( bytes, length );
sessionId[0] = sessionId[1] = sessionId[2] = sessionId[3] = 0;
}
// sesionID - 4 bytes array
bool L2Login_RequestGGAuth::create( L2_VERSION ver )
{
UNREFERENCED_PARAMETER(ver);
// set packet type
this->setPacketType( 0x07 );
// write sessionID
this->writeUChar( sessionId[0] );
this->writeUChar( sessionId[1] );
this->writeUChar( sessionId[2] );
this->writeUChar( sessionId[3] );
// write 16 0x00
int i;
for( i=0; i<16; i++ ) this->writeUChar( 0x00 );
return true;
}
bool L2Login_RequestGGAuth::parse( L2_VERSION ver )
{
UNREFERENCED_PARAMETER(ver);
if( getPacketType() != 0x07 ) return false;
sessionId[0] = readUChar();
sessionId[1] = readUChar();
sessionId[2] = readUChar();
sessionId[3] = readUChar();
return true;
}

View File

@@ -0,0 +1,19 @@
#ifndef LOGIN_REQUESTGGAUTH_H_
#define LOGIN_REQUESTGGAUTH_H_
#include "../L2LoginPacket.h"
class L2Login_RequestGGAuth: public L2LoginPacket
{
public:
L2Login_RequestGGAuth();
L2Login_RequestGGAuth( const unsigned char *bytes, unsigned int length );
public:
virtual bool create( L2_VERSION ver = L2_VERSION_T1 );
virtual bool parse( L2_VERSION ver = L2_VERSION_T1 );
public:
unsigned char sessionId[4];
};
#endif /*LOGIN_REQUESTGGAUTH_H_*/

View File

@@ -0,0 +1,34 @@
#include "stdafx.h"
#include "L2Login_RequestServerList.h"
/*
22 00 // packet size - 34 bytes
05 // packet type - RequestServerList
e0 43 ef 46 8e dc 83 f2 // sessionKey #1
04 00 00 00 00 00 00 // some 7 bytes
b1 6a 9f 6c 00 00 00 00 // checksum and 4 0x00 bytes of checksum padding
00 00 00 00 00 00 00 00 // 8 0x00 bytes padding
*/
L2Login_RequestServerList::L2Login_RequestServerList()
{
this->_initNull();
}
L2Login_RequestServerList::L2Login_RequestServerList( const unsigned char *bytes, unsigned int length )
{
this->_initNull();
this->setBytes( bytes, length );
}
bool L2Login_RequestServerList::create( const unsigned char *sessionKey1 )
{
if( !sessionKey1 ) return false;
this->writeReset();
this->setPacketType( 0x05 );
this->writeBytes( sessionKey1, 8 );
unsigned char somebytes[7] = { 4,0,0,0, 0,0,0 };
this->writeBytes( somebytes, sizeof(somebytes) );
// now packet is padded at 8-byte border. all left to is add checksum
return true;
}

View File

@@ -0,0 +1,25 @@
#ifndef L2LOGIN_REQUESTSERVERLIST_H_
#define L2LOGIN_REQUESTSERVERLIST_H_
#include "../L2LoginPacket.h"
/*
22 00 // packet size - 34 bytes
05 // packet type - RequestServerList
e0 43 ef 46 8e dc 83 f2 // sessionKey #1
04 00 00 00 00 00 00 // some 7 bytes
b1 6a 9f 6c 00 00 00 00 // checksum and 4 0x00 bytes of checksum padding
00 00 00 00 00 00 00 00 // 8 0x00 bytes padding
*/
class L2Login_RequestServerList : public L2LoginPacket
{
public:
L2Login_RequestServerList();
L2Login_RequestServerList( const unsigned char *bytes, unsigned int length );
public:
// sessionKey1 - 8-byte array (from LoginOK packet)
bool create( const unsigned char *sessionKey1 );
};
#endif /*L2LOGIN_REQUESTSERVERLIST_H_*/

View File

@@ -0,0 +1,70 @@
#include "stdafx.h"
#include "L2Login_RequestServerLogin.h"
/**
* Format is ddc
* d: first part of session id
* d: second part of session id
* c: server ID
*/
L2Login_RequestServerLogin::L2Login_RequestServerLogin()
{
this->_initNull();
}
L2Login_RequestServerLogin::L2Login_RequestServerLogin( const unsigned char *bytes, unsigned int length )
{
this->_initNull();
this->setBytes( bytes, length );
}
// sessionKey1 must point to 8-byte array
// this is Session Key #1 from LoginOK packet
bool L2Login_RequestServerLogin::create( const unsigned char *sessionKey1,
unsigned char GameServerID )
{
if( !sessionKey1 || (GameServerID == 0x00) ) return false;
// construct packet
this->writeReset();
this->setPacketType( 0x02 ); // RequestServerLogin
this->writeBytes( sessionKey1, 8 );
this->writeUChar( GameServerID );
// pad to 8-byte border
int i;
for( i=0; i<6; i++ ) this->writeUChar( 0x00 );
return true;
}
bool L2Login_RequestServerLogin::read_sessionKey1( unsigned char *bytes )
{
if( !this->canReadBytes(8) ) return false;
return this->readBytes( bytes, 8 );
}
unsigned char L2Login_RequestServerLogin::read_GameServerID()
{
return this->readUChar();
}
bool L2Login_RequestServerLogin::parse( L2_VERSION ver /*= L2_VERSION_T1*/ )
{
UNREFERENCED_PARAMETER(ver);
if( getPacketType() != 0x02 ) return false;
if( !canReadBytes( 9 ) ) return false;
readBytes( p_sessionKey1, 8 );
p_gameServerId = readUChar();
return true;
}
bool L2Login_RequestServerLogin::create( L2_VERSION ver /*= L2_VERSION_T1*/ )
{
UNREFERENCED_PARAMETER(ver);
setPacketType( 0x02 ); // RequestServerLogin
writeBytes( p_sessionKey1, 8 );
writeUChar( p_gameServerId );
// pad to 8-byte border
int i;
for( i=0; i<6; i++ ) writeUChar( 0x00 );
return true;
}

View File

@@ -0,0 +1,26 @@
#ifndef L2LOGIN_REQUESTSERVERLOGIN_H_
#define L2LOGIN_REQUESTSERVERLOGIN_H_
#include "../L2LoginPacket.h"
class L2Login_RequestServerLogin : public L2LoginPacket
{
public:
L2Login_RequestServerLogin();
L2Login_RequestServerLogin( const unsigned char *bytes, unsigned int length );
public:
// sessionKey1 must point to 8-byte array
// this is Session Key #1 from LoginOK packet
bool create( const unsigned char *sessionKey1, unsigned char GameServerID );
public:
bool read_sessionKey1( unsigned char *bytes );
unsigned char read_GameServerID();
public:
bool parse( L2_VERSION ver = L2_VERSION_T1 );
bool create( L2_VERSION ver = L2_VERSION_T1 );
public:
unsigned char p_gameServerId;
unsigned char p_sessionKey1[8];
};
#endif /*L2LOGIN_REQUESTSERVERLOGIN_H_*/