diff options
| author | boris <wzn@moneybot.cc> | 2018-11-28 16:00:02 +1300 |
|---|---|---|
| committer | boris <wzn@moneybot.cc> | 2018-11-28 16:00:02 +1300 |
| commit | 3d412a4b30a9f7c7f51ea6562e694315948bd3da (patch) | |
| tree | 26d67dfd1f3e5fd12903ad13e85d0cb8bcf8f21c /client/connect.hpp | |
| parent | e4729e4393d90271a3814c7a79950a660c48325a (diff) | |
cleaned up
in short, the cheat and loader are now separate solutions. unused stuff was moved into the legacy solution in case anyone wants to compile it or whatever.
i can change this back if you want to. also, i configured the loader to compile in x64, and have separate build types for linux and win64
Diffstat (limited to 'client/connect.hpp')
| -rw-r--r-- | client/connect.hpp | 282 |
1 files changed, 0 insertions, 282 deletions
diff --git a/client/connect.hpp b/client/connect.hpp deleted file mode 100644 index 96bb9c8..0000000 --- a/client/connect.hpp +++ /dev/null @@ -1,282 +0,0 @@ -#pragma once - -#include <Windows.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fstream> - -#pragma comment( lib, "ws2_32.lib" ) - -#include <vector> - -/* TEST */ -#include <Psapi.h> -#include <TlHelp32.h> -/* TEST */ - -#include "err.hpp" -#include "util.hpp" - -/* -protocol rules: -every msg must be xored -first byte is the xorkey - -*/ - -namespace client -{ - constexpr auto PORT_NUM = 6969; - constexpr auto BUFFER_SIZE = 255; - - class c_connect { - public: - c_connect( const char* ip ) : - m_ip( inet_addr( ip ) ) { } - - ~c_connect( ) { - if( m_socket ) - closesocket( m_socket ); - - WSACleanup( ); - } - - bool setup( ) { - int code{ }; - - if( WSAStartup( MAKEWORD( 2, 2 ), &m_wsdata ) ) - code = err::ERR_WSA; - else { - m_socket = socket( AF_INET, SOCK_STREAM, 0 ); - if( m_socket == INVALID_SOCKET ) - code = err::ERR_WSA; - } - - if( code != err::ERR_NONE ) { - MessageBoxA( nullptr, err::translate_err( code ), "", MB_OK ); - return false; - } - - return true; - } - - bool connect( ) { - sockaddr_in server_address{ }; - int code{ }; - - server_address.sin_addr.s_addr = m_ip; - server_address.sin_port = htons( PORT_NUM ); - server_address.sin_family = AF_INET; - - code = ::connect( m_socket, ( sockaddr* )( &server_address ), - sizeof( server_address ) ); - - if( code == -1 ) { - MessageBoxA( nullptr, err::translate_err( err::ERR_CONNECT ), "", MB_OK ); - return false; - } - - return true; - } - - void decode_buffer( uint8_t* buf, size_t length ) { - auto key = buf[ 0 ]; - for( size_t i{ 1 }; i < length; ++i ) - buf[ i ] ^= key; - } - - std::string get_string( ) { - std::string ret{ }; - char buffer[ BUFFER_SIZE ]; - - - while ( true ) { - int received = recv( m_socket, buffer, BUFFER_SIZE, 0 ); - if ( received < 0 ) - break; - - for ( int i{ }; i < received; ++i ) - ret.push_back( buffer[ i ] ); - - if ( received < BUFFER_SIZE ) - break; - } - - if ( ret.size( ) ) { - decode_buffer( ( uint8_t* )ret.data( ), ret.size( ) ); - ret.erase( ret.begin( ) ); - } - - return ret; - } - - std::vector< uint8_t > get_msg( ) { - std::vector< uint8_t > ret; - char buffer[ BUFFER_SIZE ]; - int received = 0; - - while( true ) { - received = recv( m_socket, buffer, BUFFER_SIZE, 0 ); - if( received < 0 ) - break; - - for( int i{ }; i < received; ++i ) - ret.push_back( buffer[ i ] ); - - if( received < BUFFER_SIZE ) - break; - } - - if( ret.size( ) ) { - decode_buffer( ret.data( ), ret.size( ) ); - ret.erase( ret.begin( ) ); - } - return ret; - } - - void send_msg( const uint8_t* msg, size_t length ) { - auto buffer = std::make_unique< uint8_t[ ] >( length + 1 ); - auto key = util::random_number( 0, 255 ) & 0xff; - - buffer[ 0 ] = key; - memcpy( buffer.get( ) + 1, - msg, - length ); - - for( size_t i = 1; i <= length; ++i ) { - buffer[ i ] ^= key; - } - - int ret = send( m_socket, ( char* )buffer.get( ), length + 1, 0 ); - if ( ret == SOCKET_ERROR ) { - printf( xors( "error sending message error code: %d" ), WSAGetLastError( ) ); - } - } - - void send_msg( const char* msg ) { - auto length = strlen( msg ); - auto buffer = std::make_unique< uint8_t[ ] >( length + 1 ); - auto key = util::random_number( 0, 255 ) & 0xff; - - buffer[ 0 ] = key; - memcpy( buffer.get( ) + 1, - msg, - length ); - - for ( size_t i = 1; i <= length; ++i ) { - buffer[ i ] ^= key; - } - - int ret = send( m_socket, ( char* )buffer.get( ), length + 1, 0 ); - if ( ret == SOCKET_ERROR ) { - printf( xors( "error sending message error code: %d" ), WSAGetLastError( ) ); - } - } - - - void send_msg( const char msg ) { - auto buffer = std::make_unique< uint8_t[ ] >( 2 ); - auto key = util::random_number( 0, 255 ) & 0xff; - - buffer[ 0 ] = key; - buffer[ 1 ] = msg; - buffer[ 1 ] ^= buffer[ 0 ]; - - int ret = send( m_socket, ( char* )buffer.get( ), 2, 0 ); - if ( ret == SOCKET_ERROR ) { - printf( xors( "error sending message error code: %d" ), WSAGetLastError( ) ); - } - } - - void handle( ) { -
- auto msg = get_string( );
- if ( msg != xors( "hello" ) ) {
- std::cout << "connection failed." << std::endl;
- //return 0;
- }
-
- send_msg( "hello" );
-
- std::string username{ }, password{ };
- std::cout << "Enter your username" << std::endl << "> ";
- std::cin >> username;
-
- send_msg( username.c_str( ) );
- msg = get_string( );
- std::cout <<msg <<std::endl;
- if ( msg != xors( "correct username" ) ) {
- std::cout << "incorrect username" << std::endl;
- //return 0; // remember to close connection on server when bad values were sent.
- }
-
- std::cout << "Enter your password" << std::endl << "> ";
- std::cin >> password;
-
- send_msg( password.c_str( ) );
- if ( get_string( ) != xors( "correct password" ) ) {
- std::cout << "incorrect password";
- //return 0; // remember to close connection on server when bad values were sent.
- }
-
- // Receive list of games,
- msg = get_string( );
- std::cout << msg << std::endl;
-
-
- std::cout << "For what game do you want to inject on?" << std::endl << "> ";
-
- char game_id{ };
- std::cin >> game_id;
-
- send_msg( game_id );
-
- // get process name.
- msg = get_string( );
-
- std::cout << msg << std::endl;
-
- int process_identifier{ };
-
- HANDLE snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
- if ( snapshot != INVALID_HANDLE_VALUE ) {
- PROCESSENTRY32 entry{ sizeof( PROCESSENTRY32 ) };
-
- if ( Process32First( snapshot, &entry ) ) {
- do {
- if ( msg == entry.szExeFile ) {
- process_identifier = entry.th32ProcessID;
- break;
- }
- } while ( Process32Next( snapshot, &entry ) );
- }
- }
-
- if ( !process_identifier ) {
- std::cout << "Could not find process." << std::endl;
- return;
- }
-
- std::cout << "found" << std::endl;
- send_msg( "found" );
-
- auto file = get_msg( ); - auto file_data = file.data( ); - auto file_size = file.size( ); - - auto save_file = std::ofstream( "gmod.txt", std::ofstream::binary ); - if ( save_file.is_open( ) ) { - save_file.write( ( const char* )file_data, file_size ); - save_file.close( ); - } - - - } - - private: - SOCKET m_socket; - WSADATA m_wsdata; - int m_ip; - }; -}
\ No newline at end of file |
