diff options
| author | boris <wzn@moneybot.cc> | 2018-12-30 15:00:51 +1300 |
|---|---|---|
| committer | boris <wzn@moneybot.cc> | 2018-12-30 15:00:51 +1300 |
| commit | d786e65a9a262638e74f6ebcf1b296917897ae49 (patch) | |
| tree | 17199ab95db8a59abf4d3bf40543296d76e8659e /csgo-loader/csgo-server | |
| parent | 0340821cc614fda2a94a96c255d16105dd2f6f9a (diff) | |
unban marcus or suffer my wrath
grr
Diffstat (limited to 'csgo-loader/csgo-server')
| -rw-r--r-- | csgo-loader/csgo-server/Networking/TCPServer.cpp | 32 | ||||
| -rw-r--r-- | csgo-loader/csgo-server/Networking/TCPServer.hpp | 7 | ||||
| -rw-r--r-- | csgo-loader/csgo-server/Networking/WebSocket.cpp | 17 | ||||
| -rw-r--r-- | csgo-loader/csgo-server/Security/Encryption.cpp | 40 | ||||
| -rw-r--r-- | csgo-loader/csgo-server/Server.cpp | 10 | ||||
| -rw-r--r-- | csgo-loader/csgo-server/csgo-server.vcxproj | 65 |
6 files changed, 111 insertions, 60 deletions
diff --git a/csgo-loader/csgo-server/Networking/TCPServer.cpp b/csgo-loader/csgo-server/Networking/TCPServer.cpp index c381c85..d93a710 100644 --- a/csgo-loader/csgo-server/Networking/TCPServer.cpp +++ b/csgo-loader/csgo-server/Networking/TCPServer.cpp @@ -4,7 +4,7 @@ namespace Networking {
void TCPConnection::Close()
{
- printf("[ <= ] disconnected\n");
+ printf("[ <= ] %s disconnected!\n", m_IpAddress);
if(m_Socket)
closesocket(m_Socket);
@@ -18,12 +18,10 @@ namespace Networking // Send data.
int32_t Result = send(m_Socket, (char *)Bytes.data(), (int)Bytes.size(), 0);
- if(m_IpAddress)
-
- printf("[ => ] %zd bytes\n", Bytes.size());
+ printf("[ => ] Sending %zd bytes to %s.\n", Bytes.size(), m_IpAddress);
if(Result == -1)
- printf("[ => ] %zd bytes failed (%d)\n", Bytes.size(), WSAGetLastError());
+ printf("[ E! ] Failed to send %zd bytes to %s. (Socket %04Ix)\n", Bytes.size(), m_IpAddress, m_Socket);
}
ByteArray TCPConnection::ReceiveRawBytes()
@@ -43,7 +41,7 @@ namespace Networking // Emplace all received bytes.
for(int n = 0; n < Received; ++n)
{
- ReceivedBytes.emplace_back(RecvBuffer[n]);
+ ReceivedBytes.push_back(RecvBuffer[n]);
}
// No more bytes left to receive.
@@ -51,7 +49,7 @@ namespace Networking break;
}
- printf("[ <= ] %zd bytes\n", ReceivedBytes.size());
+ printf("[ <= ] Received %zd bytes from %s.\n", ReceivedBytes.size(), m_IpAddress);
return ReceivedBytes;
}
@@ -90,8 +88,8 @@ namespace Networking // Set up server context.
m_Context.sin_addr.s_addr = INADDR_ANY;
- m_Context.sin_family = AF_INET;
- m_Context.sin_port = htons(ServerPort);
+ m_Context.sin_family = AF_INET;
+ m_Context.sin_port = htons(ServerPort);
int32_t Bind = bind(m_Socket, (sockaddr *)&m_Context, sizeof sockaddr_in);
@@ -99,7 +97,7 @@ namespace Networking return false;
// Start listening.
- printf("[INFO] Server listening on port %d.\n", ServerPort);
+ printf("[ i! ] Server listening on port %d.\n", ServerPort);
listen(m_Socket, 1);
return true;
@@ -121,23 +119,17 @@ namespace Networking Encryption.Start();
// Attempt handshake with client.
- TCPConnection Connection(IncomingSocket, inet_ntoa(IncomingConnection.sin_addr), Encryption);
+ const char *IpAddress = inet_ntoa(IncomingConnection.sin_addr);
+ TCPConnection Connection(IncomingSocket, IpAddress, Encryption);
ByteArray EncryptionKey = Connection.GetEncryptionKey();
Connection.SendRawBytes(EncryptionKey);
- // Print out handshake header
- printf("[ => ] Handshake: ");
-
- for(auto &It : EncryptionKey)
- printf("%02x ", It);
-
- printf("\n");
-
// Detach a thread to handle the connection.
std::thread thread([&]
{
- // smol fix :^)
+ // Fix for crashing when there is no connection handler
+ // (literally happened to me once)
if(m_ConnectionHandler)
m_ConnectionHandler(Connection);
diff --git a/csgo-loader/csgo-server/Networking/TCPServer.hpp b/csgo-loader/csgo-server/Networking/TCPServer.hpp index 31beec8..a29a796 100644 --- a/csgo-loader/csgo-server/Networking/TCPServer.hpp +++ b/csgo-loader/csgo-server/Networking/TCPServer.hpp @@ -23,13 +23,14 @@ namespace Networking {
SOCKET m_Socket;
Wrapper::Encryption m_Encryption;
- const char *m_IpAddress;
+ char m_IpAddress[32];
public:
// Initialiser for TCPConnection class.
TCPConnection(SOCKET Connection, const char *IpAddress, Wrapper::Encryption &RSA) :
- m_Encryption(RSA), m_Socket(Connection), m_IpAddress(IpAddress)
+ m_Encryption(RSA), m_Socket(Connection)
{
- printf("[ => ] connected\n");
+ strcpy_s<32>(m_IpAddress, IpAddress);
+ printf("[ => ] %s connected!\n", m_IpAddress);
}
// Release the connection once it goes out of scope.
diff --git a/csgo-loader/csgo-server/Networking/WebSocket.cpp b/csgo-loader/csgo-server/Networking/WebSocket.cpp index 75b5731..2c42001 100644 --- a/csgo-loader/csgo-server/Networking/WebSocket.cpp +++ b/csgo-loader/csgo-server/Networking/WebSocket.cpp @@ -21,30 +21,27 @@ namespace Networking // Receives a response from a request.
ByteArray WebSocket::Request(const char *File, const char *Header, ByteArray &Data)
{
- DWORD ReceivedSize{};
ByteArray Response;
InternetHandle WebRequest = HttpOpenRequestA(m_Address, "POST", File, 0, 0, 0, INTERNET_FLAG_SECURE | INTERNET_FLAG_KEEP_CONNECTION, 0);
- if(!WebRequest)
- return Response;
-
// Make connection request.
bool Sent = HttpSendRequestA(WebRequest, Header, (DWORD)strlen(Header), Data.data(), (DWORD)Data.size());
if(Sent)
{
- // Allocate a buffer to read the response into.
- uint8_t *Block = (uint8_t *)malloc(0x1000);
+ DWORD ReceivedSize{};
+
+ uint8_t *Block = (uint8_t *)malloc(4096);
// Read response.
- while(InternetReadFile(WebRequest, Block, 0x1000, &ReceivedSize))
+ while(InternetReadFile(WebRequest, Block, 4096, &ReceivedSize))
{
- const size_t RequestRange = std::min< int >(0x1000, ReceivedSize);
- for(size_t n{}; n < RequestRange; ++n)
+ for(size_t n{}; n < std::min< int >(4096, ReceivedSize); ++n)
+ {
Response.push_back(Block[n]);
+ }
}
- // Free the buffer to avoid leaking memory.
free(Block);
}
diff --git a/csgo-loader/csgo-server/Security/Encryption.cpp b/csgo-loader/csgo-server/Security/Encryption.cpp index b79a1c3..f4681b8 100644 --- a/csgo-loader/csgo-server/Security/Encryption.cpp +++ b/csgo-loader/csgo-server/Security/Encryption.cpp @@ -259,7 +259,7 @@ namespace Wrapper ByteArray::size_type Aes256::decrypt_start(const ByteArray::size_type encrypted_length)
{
- register unsigned char j;
+ unsigned char j;
m_remainingLength = encrypted_length;
@@ -308,7 +308,7 @@ namespace Wrapper {
if(!m_decryptInitialized && m_buffer_pos == m_salt.size() + 1)
{
- register unsigned char j;
+ unsigned char j;
ByteArray::size_type padding;
// Get salt
@@ -370,7 +370,7 @@ namespace Wrapper void Aes256::expand_enc_key(unsigned char* rc)
{
- register unsigned char i;
+ unsigned char i;
m_rkey[0] = m_rkey[0] ^ sbox[m_rkey[29]] ^ (*rc);
m_rkey[1] = m_rkey[1] ^ sbox[m_rkey[30]];
@@ -433,7 +433,7 @@ namespace Wrapper void Aes256::sub_bytes(unsigned char* buffer)
{
- register unsigned char i = KEY_SIZE / 2;
+ unsigned char i = KEY_SIZE / 2;
while(i--)
buffer[i] = sbox[buffer[i]];
@@ -441,7 +441,7 @@ namespace Wrapper void Aes256::sub_bytes_inv(unsigned char* buffer)
{
- register unsigned char i = KEY_SIZE / 2;
+ unsigned char i = KEY_SIZE / 2;
while(i--)
buffer[i] = sboxinv[buffer[i]];
@@ -459,7 +459,7 @@ namespace Wrapper void Aes256::add_round_key(unsigned char* buffer, const unsigned char round)
{
- register unsigned char i = KEY_SIZE / 2;
+ unsigned char i = KEY_SIZE / 2;
while(i--)
buffer[i] ^= m_rkey[(round & 1) ? i + 16 : i];
@@ -467,7 +467,7 @@ namespace Wrapper void Aes256::shift_rows(unsigned char* buffer)
{
- register unsigned char i, j, k, l; /* to make it potentially parallelable :) */
+ unsigned char i, j, k, l; /* to make it potentially parallelable :) */
i = buffer[1];
buffer[1] = buffer[5];
@@ -492,7 +492,7 @@ namespace Wrapper void Aes256::shift_rows_inv(unsigned char* buffer)
{
- register unsigned char i, j, k, l; /* same as above :) */
+ unsigned char i, j, k, l; /* same as above :) */
i = buffer[1];
buffer[1] = buffer[13];
@@ -517,7 +517,7 @@ namespace Wrapper void Aes256::mix_columns(unsigned char* buffer)
{
- register unsigned char i, a, b, c, d, e;
+ unsigned char i, a, b, c, d, e;
for(i = 0; i < 16; i += 4)
{
@@ -537,7 +537,7 @@ namespace Wrapper void Aes256::mix_columns_inv(unsigned char* buffer)
{
- register unsigned char i, a, b, c, d, e, x, y, z;
+ unsigned char i, a, b, c, d, e, x, y, z;
for(i = 0; i < 16; i += 4)
{
@@ -581,7 +581,6 @@ namespace Wrapper // Generate random bytes to use as encryption key.
if(CryptGenRandom(m_CryptProvider, RandomBytesCount, RandomBytes))
{
- m_EncryptionKey.reserve(RandomBytesCount);
m_EncryptionKey.insert(
m_EncryptionKey.begin(),
RandomBytes,
@@ -598,15 +597,10 @@ namespace Wrapper {
// If an encryption key is provided, initialise the wrapper with
// the passed parameter.
- if(!EncryptionKey.empty())
- {
- m_EncryptionKey.reserve(EncryptionKey.size());
- std::copy(EncryptionKey.begin(), EncryptionKey.end(), m_EncryptionKey.begin());
- }
- else
- {
+ std::copy(EncryptionKey.begin(), EncryptionKey.end(), m_EncryptionKey.begin());
+
+ if(EncryptionKey.empty())
Start();
- }
}
ByteArray Encryption::Encrypt(ByteArray &Data)
@@ -614,7 +608,11 @@ namespace Wrapper // Encrypt outgoing data.
ByteArray Encrypted;
+ #ifdef DEBUG
+ Encrypted = Data;
+ #else
Aes256::encrypt(m_EncryptionKey, Data, Encrypted);
+ #endif
return Encrypted;
}
@@ -624,7 +622,11 @@ namespace Wrapper // Decrypt incoming data.
ByteArray Decrypted;
+ #ifdef DEBUG
+ Decrypted = Data;
+ #else
Aes256::decrypt(m_EncryptionKey, Data, Decrypted);
+ #endif
return Decrypted;
}
diff --git a/csgo-loader/csgo-server/Server.cpp b/csgo-loader/csgo-server/Server.cpp index c475542..2f3f913 100644 --- a/csgo-loader/csgo-server/Server.cpp +++ b/csgo-loader/csgo-server/Server.cpp @@ -1,14 +1,8 @@ #include <Server.hpp>
-void ConnectionHandler(Networking::TCPConnection &Connection)
+void ConnectionHandler(Networking::TCPConnection &)
{
- ByteArray Bytes = Connection.ReceiveBytes();
- for(auto &It : Bytes)
- printf("%02x ", It);
- printf("\n");
-
- Connection.SendBytes(Bytes);
}
int __stdcall WinMain(HINSTANCE, HINSTANCE, char*, int)
@@ -33,7 +27,7 @@ int __stdcall WinMain(HINSTANCE, HINSTANCE, char*, int) }
if(!Result)
- printf("[FAIL] Failed to initialise server. (%08lx)\n", WSAGetLastError());
+ printf("[ !! ] Failed to initialise server. (%08lx)\n", WSAGetLastError());
system("pause");
}
\ No newline at end of file diff --git a/csgo-loader/csgo-server/csgo-server.vcxproj b/csgo-loader/csgo-server/csgo-server.vcxproj index 268a409..3bd07ca 100644 --- a/csgo-loader/csgo-server/csgo-server.vcxproj +++ b/csgo-loader/csgo-server/csgo-server.vcxproj @@ -5,6 +5,14 @@ <Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
+ <ProjectConfiguration Include="FuckMSVC|Win32">
+ <Configuration>FuckMSVC</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="FuckMSVC|x64">
+ <Configuration>FuckMSVC</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
@@ -59,6 +67,13 @@ <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='FuckMSVC|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
@@ -72,6 +87,13 @@ <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='FuckMSVC|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
@@ -83,12 +105,18 @@ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='FuckMSVC|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='FuckMSVC|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
@@ -102,6 +130,12 @@ <ExecutablePath>$(ExecutablePath)</ExecutablePath>
<IncludePath>$(ProjectDir);$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='FuckMSVC|x64'">
+ <OutDir>$(SolutionDir)bin\$(Configuration)\</OutDir>
+ <IntDir>$(SolutionDir)build\$(Configuration)\Server\</IntDir>
+ <ExecutablePath>$(ExecutablePath)</ExecutablePath>
+ <IncludePath>$(ProjectDir);$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
+ </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
@@ -137,6 +171,20 @@ <OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='FuckMSVC|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
@@ -154,6 +202,23 @@ <SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='FuckMSVC|x64'">
+ <ClCompile>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ <ConformanceMode>true</ConformanceMode>
+ <PreprocessorDefinitions>DEBUG;_WINSOCK_DEPRECATED_NO_WARNINGS;WIN32_LEAN_AND_MEAN;NOMINMAX;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
+ <SubSystem>Windows</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
|
