This repository has been archived by the owner on Mar 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bncsutilinterface.cpp
executable file
·161 lines (128 loc) · 5.61 KB
/
bncsutilinterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Copyright [2008] [Trevor Hogan]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
CODE PORTED FROM THE ORIGINAL GHOST PROJECT: http://ghost.pwner.org/
*/
#include "ghost.h"
#include "util.h"
#include "bncsutilinterface.h"
#include <bncsutil/bncsutil.h>
//
// CBNCSUtilInterface
//
CBNCSUtilInterface :: CBNCSUtilInterface( std::string userName, std::string userPassword )
{
// m_nls = (void *)nls_init( userName.c_str( ), userPassword.c_str( ) );
m_NLS = new NLS( userName, userPassword );
}
CBNCSUtilInterface :: ~CBNCSUtilInterface( )
{
// nls_free( (nls_t *)m_nls );
delete (NLS *)m_NLS;
}
void CBNCSUtilInterface :: Reset( std::string userName, std::string userPassword )
{
// nls_free( (nls_t *)m_nls );
// m_nls = (void *)nls_init( userName.c_str( ), userPassword.c_str( ) );
delete (NLS *)m_NLS;
m_NLS = new NLS( userName, userPassword );
}
bool CBNCSUtilInterface :: HELP_SID_AUTH_CHECK( bool TFT, std::string war3Path, std::string keyROC, std::string keyTFT, std::string valueStringFormula, std::string mpqFileName, BYTEARRAY clientToken, BYTEARRAY serverToken )
{
// set m_EXEVersion, m_EXEVersionHash, m_EXEInfo, m_InfoROC, m_InfoTFT
std::string FileWar3EXE = war3Path + "war3.exe";
std::string FileStormDLL = war3Path + "Storm.dll";
if( !UTIL_FileExists( FileStormDLL ) )
FileStormDLL = war3Path + "storm.dll";
std::string FileGameDLL = war3Path + "game.dll";
bool ExistsWar3EXE = UTIL_FileExists( FileWar3EXE );
bool ExistsStormDLL = UTIL_FileExists( FileStormDLL );
bool ExistsGameDLL = UTIL_FileExists( FileGameDLL );
if( ExistsWar3EXE && ExistsStormDLL && ExistsGameDLL )
{
// todotodo: check getExeInfo return value to ensure 1024 bytes was enough
char buf[1024];
uint32_t EXEVersion;
getExeInfo( FileWar3EXE.c_str( ), (char *)&buf, 1024, (uint32_t *)&EXEVersion, BNCSUTIL_PLATFORM_X86 );
m_EXEInfo = buf;
m_EXEVersion = UTIL_CreateByteArray( EXEVersion, false );
unsigned long EXEVersionHash;
checkRevisionFlat( valueStringFormula.c_str( ), FileWar3EXE.c_str( ), FileStormDLL.c_str( ), FileGameDLL.c_str( ), extractMPQNumber( mpqFileName.c_str( ) ), (unsigned long *)&EXEVersionHash );
m_EXEVersionHash = UTIL_CreateByteArray( (uint32_t) EXEVersionHash, false );
m_KeyInfoROC = CreateKeyInfo( keyROC, UTIL_ByteArrayToUInt32( clientToken, false ), UTIL_ByteArrayToUInt32( serverToken, false ) );
if( TFT )
m_KeyInfoTFT = CreateKeyInfo( keyTFT, UTIL_ByteArrayToUInt32( clientToken, false ), UTIL_ByteArrayToUInt32( serverToken, false ) );
if( m_KeyInfoROC.size( ) == 36 && ( !TFT || m_KeyInfoTFT.size( ) == 36 ) )
return true;
else
{
if( m_KeyInfoROC.size( ) != 36 )
CONSOLE_Print( "[BNCSUI] unable to create ROC key info - invalid ROC key" );
if( TFT && m_KeyInfoTFT.size( ) != 36 )
CONSOLE_Print( "[BNCSUI] unable to create TFT key info - invalid TFT key" );
}
}
else
{
if( !ExistsWar3EXE )
CONSOLE_Print( "[BNCSUI] unable to open [" + FileWar3EXE + "]" );
if( !ExistsStormDLL )
CONSOLE_Print( "[BNCSUI] unable to open [" + FileStormDLL + "]" );
if( !ExistsGameDLL )
CONSOLE_Print( "[BNCSUI] unable to open [" + FileGameDLL + "]" );
}
return false;
}
bool CBNCSUtilInterface :: HELP_SID_AUTH_ACCOUNTLOGON( )
{
// set m_ClientKey
char buf[32];
// nls_get_A( (nls_t *)m_nls, buf );
( (NLS *)m_NLS )->getPublicKey( buf );
m_ClientKey = UTIL_CreateByteArray( (unsigned char *)buf, 32 );
return true;
}
bool CBNCSUtilInterface :: HELP_SID_AUTH_ACCOUNTLOGONPROOF( BYTEARRAY salt, BYTEARRAY serverKey )
{
// set m_M1
char buf[20];
// nls_get_M1( (nls_t *)m_nls, buf, std::string( serverKey.begin( ), serverKey.end( ) ).c_str( ), std::string( salt.begin( ), salt.end( ) ).c_str( ) );
( (NLS *)m_NLS )->getClientSessionKey( buf, std::string( salt.begin( ), salt.end( ) ).c_str( ), std::string( serverKey.begin( ), serverKey.end( ) ).c_str( ) );
m_M1 = UTIL_CreateByteArray( (unsigned char *)buf, 20 );
return true;
}
bool CBNCSUtilInterface :: HELP_PvPGNPasswordHash( std::string userPassword )
{
// set m_PvPGNPasswordHash
char buf[20];
hashPassword( userPassword.c_str( ), buf );
m_PvPGNPasswordHash = UTIL_CreateByteArray( (unsigned char *)buf, 20 );
return true;
}
BYTEARRAY CBNCSUtilInterface :: CreateKeyInfo( std::string key, uint32_t clientToken, uint32_t serverToken )
{
unsigned char Zeros[] = { 0, 0, 0, 0 };
BYTEARRAY KeyInfo;
CDKeyDecoder Decoder( key.c_str( ), key.size( ) );
if( Decoder.isKeyValid( ) )
{
UTIL_AppendByteArray( KeyInfo, UTIL_CreateByteArray( (uint32_t)key.size( ), false ) );
UTIL_AppendByteArray( KeyInfo, UTIL_CreateByteArray( Decoder.getProduct( ), false ) );
UTIL_AppendByteArray( KeyInfo, UTIL_CreateByteArray( Decoder.getVal1( ), false ) );
UTIL_AppendByteArray( KeyInfo, UTIL_CreateByteArray( Zeros, 4 ) );
size_t Length = Decoder.calculateHash( clientToken, serverToken );
char *buf = new char[Length];
Length = Decoder.getHash( buf );
UTIL_AppendByteArray( KeyInfo, UTIL_CreateByteArray( (unsigned char *)buf, Length ) );
delete [] buf;
}
return KeyInfo;
}