diff --git a/cozinha_loader/cozinha_loader.vcxproj b/cozinha_loader/cozinha_loader.vcxproj
index 2ef56b1..ffac316 100644
--- a/cozinha_loader/cozinha_loader.vcxproj
+++ b/cozinha_loader/cozinha_loader.vcxproj
@@ -73,6 +73,7 @@
MultiThreadedDebugDLL
true
CompileAsCpp
+ stdc17
Windows
@@ -97,6 +98,7 @@
None
false
CompileAsCpp
+ stdc17
Windows
@@ -117,7 +119,6 @@
-
diff --git a/cozinha_loader/cozinha_loader.vcxproj.filters b/cozinha_loader/cozinha_loader.vcxproj.filters
index 86b1932..093f462 100644
--- a/cozinha_loader/cozinha_loader.vcxproj.filters
+++ b/cozinha_loader/cozinha_loader.vcxproj.filters
@@ -7,24 +7,21 @@
{ebfadaa9-2c80-4c74-b27c-c01e8ed57886}
-
+
{ba7bf719-1929-4eed-a323-02c32e116f3f}
-
+
{8f4f41f8-3272-4c46-a64b-a5209764d0cf}
-
+
{10d10d53-65fa-4875-965f-f7ec0fa57614}
-
+
{5dfeec10-d957-4322-8a9a-3f33434a2c17}
-
+
{1771c7ca-3cf1-4f5a-8fb0-c784c17f5d96}
-
- {526d0e79-9eb5-4faa-8937-dab1afdc9273}
-
@@ -40,22 +37,19 @@
pch
- helpers\logging
+ ext\logging
- helpers\memory
+ ext\memory
- helpers\utils
+ ext\utils
loader
- helpers\vac3_bypass
-
-
- helpers\singleton
+ ext\vac3_bypass
\ No newline at end of file
diff --git a/cozinha_loader/injection.cpp b/cozinha_loader/injection.cpp
index c5b47f5..167a323 100644
--- a/cozinha_loader/injection.cpp
+++ b/cozinha_loader/injection.cpp
@@ -3,35 +3,38 @@
bool injector::map( std::string process, std::wstring module_name, std::vector binary_bytes )
{
- log_debug( "Waiting for [ %s ] to be opened...", process.c_str() );
+ // ~ wait for process to be opened
+ //
+ log_debug( "waiting for [ %s ] to be opened...", process.c_str() );
- // Wait for process to be opened
auto process_list = memory::get_process_list();
- while (true)
+ while ( true )
{
- std::this_thread::sleep_for( 500ms );
-
process_list = memory::get_process_list();
- if (memory::is_process_open( process_list, process ))
+ if ( memory::is_process_open( process_list, process ) )
break;
+
+ std::this_thread::sleep_for( 500ms );
}
- if (process.find( "csgo" ) != std::string::npos)
+ // ~ bypassing injection block by csgo (-allow_third_party_software) the easiest way
+ //
+ if ( process.find( "csgo" ) != std::string::npos )
{
- // Bypassing injection block by csgo (-allow_third_party_software) the easiest way.
const auto bypass_nt_open_file = []( DWORD pid )
{
const auto h_process = OpenProcess( PROCESS_ALL_ACCESS, false, pid );
LPVOID nt_open_file = GetProcAddress( LoadLibrary( "ntdll" ), "NtOpenFile" );
- if (nt_open_file)
- {
- char original_bytes[5];
- // Copy 5 bytes to NtOpenFile procedure address
- std::memcpy( original_bytes, nt_open_file, 5 );
- // Write it to memory.
- WriteProcessMemory( h_process, nt_open_file, original_bytes, 5, nullptr );
- }
+ char original_bytes[5];
+
+ // ~ copy 5 bytes to NtOpenFile procedure address
+ //
+ std::memcpy( original_bytes, nt_open_file, 5 );
+
+ // ~ write it to memory
+ //
+ WriteProcessMemory( h_process, nt_open_file, original_bytes, 5, nullptr );
CloseHandle( h_process );
};
@@ -39,134 +42,142 @@ bool injector::map( std::string process, std::wstring module_name, std::vector cheat {};
+ std::vector cheat{};
- // Reading file and writing it to a variable
- if (!utils::other::read_file_to_memory( std::filesystem::absolute( cheat_filename ).string(), &cheat ))
+ // ~ reading file and writing it to a variable
+ //
+ if ( !utils::other::read_file_to_memory( std::filesystem::absolute( utils::vars::cheat_filename ).string(), &cheat ) )
{
- log_err( "Failed to write dll to memory! [ read_file_to_memory ]" );
+ log_err( "failed to write dll to memory!" );
return false;
}
- // Inject vac bypass to steam
- if (!map( "steam.exe", L"tier0_s.dll", vac3_data ))
+ // ~ inject vac bypass to steam
+ //
+ if ( !map( "steam.exe", L"tier0_s.dll", vac3_data ) )
{
- log_err( "Steam memory mapping failure!" );
+ log_err( "steam memory mapping failure!" );
return false;
}
- // Then inject cheat to csgo
- if (!map( "csgo.exe", L"serverbrowser.dll", cheat ))
+ // ~ inject cheat to process
+ //
+ if ( !map( process_name, L"serverbrowser.dll", cheat ) )
{
- log_err( "Cheat memory mapping failure!" );
+ log_err( "cheat memory mapping failure!" );
return false;
}
- log_ok( "All done!" );
+ log_ok( "all done!" );
return true;
}
void injector::close_processes( std::vector processes )
{
auto process_list = memory::get_process_list();
- for (const auto &process : processes)
+ for ( const auto& process : processes )
{
- while (true)
+ while ( true )
{
- std::this_thread::sleep_for( 500ms );
-
memory::kill_process( process_list, process );
process_list = memory::get_process_list();
- if (!memory::is_process_open( process_list, process ))
+ if ( !memory::is_process_open( process_list, process ) )
break;
+
+ std::this_thread::sleep_for( 500ms );
}
}
}
\ No newline at end of file
diff --git a/cozinha_loader/injection.hpp b/cozinha_loader/injection.hpp
index be2746d..71b8130 100644
--- a/cozinha_loader/injection.hpp
+++ b/cozinha_loader/injection.hpp
@@ -1,18 +1,16 @@
#pragma once
-using namespace std::chrono_literals;
-
-class injector: public singleton
+class injector
{
private:
bool map( std::string process, std::wstring module_name, std::vector binary_bytes );
void close_processes( std::vector processes );
public:
- std::string cheat_filename = "cheat.dll";
-
injector() = default;
~injector() = default;
- bool call();
-};
\ No newline at end of file
+ bool call( std::string process_name );
+};
+
+inline auto g_injector = injector();
\ No newline at end of file
diff --git a/cozinha_loader/logger.hpp b/cozinha_loader/logger.hpp
index c4c9370..b64fa62 100644
--- a/cozinha_loader/logger.hpp
+++ b/cozinha_loader/logger.hpp
@@ -8,47 +8,44 @@ enum class msg_type_t: std::uint32_t
LSUCCESS = 10, /* green */
LDEBUG = 9, /* blue */
LWARN = 14, /* yellow */
- LERROR = 12, /* red */
- LINFO = 8 /* gray */
+ LERROR = 12 /* red */
};
-inline std::ostream &operator<< ( std::ostream &os, const msg_type_t type )
+inline std::ostream& operator<< ( std::ostream& os, const msg_type_t type )
{
- switch (type)
+ switch ( type )
{
- case msg_type_t::LSUCCESS:
- return os << ">>";
- case msg_type_t::LDEBUG:
- return os << "..";
- case msg_type_t::LWARN:
- return os << "**";
- case msg_type_t::LERROR:
- return os << "!!";
- case msg_type_t::LINFO:
- return os << "##";
- default: return os << "";
- };
+ case msg_type_t::LSUCCESS: return os << ">>";
+ case msg_type_t::LDEBUG: return os << "..";
+ case msg_type_t::LWARN: return os << "**";
+ case msg_type_t::LERROR: return os << "!!";
+ default: return os << "";
+ }
}
class logger
{
private:
- std::shared_timed_mutex m {};
+ std::shared_timed_mutex mutex{};
public:
- logger()
+ logger( std::string title_name )
{
- FILE *conin {}, *conout {};
-
AllocConsole();
AttachConsole( GetCurrentProcessId() );
- SetConsoleTitle( "cozinha loader" );
+ if ( !title_name.empty() )
+ {
+ SetConsoleTitle( title_name.c_str() );
+ }
+
+ FILE* conin{}, * conout{};
freopen_s( &conin, "conin$", "r", stdin );
freopen_s( &conout, "conout$", "w", stdout );
freopen_s( &conout, "conout$", "w", stderr );
}
+
~logger()
{
const auto handle = FindWindow( "ConsoleWindowClass", nullptr );
@@ -57,45 +54,45 @@ class logger
}
template< typename ... arg >
- void print( const msg_type_t type, const std::string &func, const std::string &format, arg ... a )
+ void print( const msg_type_t type, const std::string& func, const std::string& format, arg ... a )
{
- static auto *h_console = GetStdHandle( STD_OUTPUT_HANDLE );
- std::unique_lock lock( m );
+ static auto* h_console = GetStdHandle( STD_OUTPUT_HANDLE );
+ std::unique_lock lock( mutex );
- // parse and format the output
const size_t size = static_cast(1) + std::snprintf( nullptr, 0, format.c_str(), a ... );
const std::unique_ptr buf( new char[size] );
std::snprintf( buf.get(), size, format.c_str(), a ... );
const auto formated = std::string( buf.get(), buf.get() + size - 1 );
- // print msg
- if (type != msg_type_t::LNONE)
+ if ( type != msg_type_t::LNONE )
{
SetConsoleTextAttribute( h_console, static_cast(type) );
std::cout << "[";
std::cout << type;
std::cout << "] ";
+
SetConsoleTextAttribute( h_console, 15 /* white */ );
std::cout << "[ ";
+
SetConsoleTextAttribute( h_console, static_cast(type) );
std::cout << func;
+
SetConsoleTextAttribute( h_console, 15 /* white */ );
std::cout << " ] ";
}
- if (type == msg_type_t::LDEBUG)
+ if ( type == msg_type_t::LDEBUG )
SetConsoleTextAttribute( h_console, 8 /* gray */ );
else
SetConsoleTextAttribute( h_console, 15 /* white */ );
- std::cout << formated << std::endl;
+ std::cout << formated << "\n";
}
};
-inline auto g_logger = std::make_unique();
-#define log_raw(...) g_logger->print( msg_type_t::LNONE, __FUNCTION__, __VA_ARGS__ )
-#define log_debug(...) g_logger->print( msg_type_t::LDEBUG, __FUNCTION__, __VA_ARGS__ )
-#define log_ok(...) g_logger->print( msg_type_t::LSUCCESS, __FUNCTION__, __VA_ARGS__ )
-#define log_warn(...) g_logger->print( msg_type_t::LWARN, __FUNCTION__, __VA_ARGS__ )
-#define log_err(...) g_logger->print( msg_type_t::LERROR, __FUNCTION__, __VA_ARGS__ )
-#define log_info(...) g_logger->print(msg_type_t::LINFO, __FUNCTION__, __VA_ARGS__)
\ No newline at end of file
+inline auto g_logger = logger( "-> cozinha loader" );
+#define log_raw(...) g_logger.print( msg_type_t::LNONE, __FUNCTION__, __VA_ARGS__ )
+#define log_ok(...) g_logger.print( msg_type_t::LSUCCESS, __FUNCTION__, __VA_ARGS__ )
+#define log_debug(...) g_logger.print( msg_type_t::LDEBUG, __FUNCTION__, __VA_ARGS__ )
+#define log_warn(...) g_logger.print( msg_type_t::LWARN, __FUNCTION__, __VA_ARGS__ )
+#define log_err(...) g_logger.print( msg_type_t::LERROR, __FUNCTION__, __VA_ARGS__ )
\ No newline at end of file
diff --git a/cozinha_loader/main.cpp b/cozinha_loader/main.cpp
index 54d5ddd..9991ebf 100644
--- a/cozinha_loader/main.cpp
+++ b/cozinha_loader/main.cpp
@@ -1,21 +1,33 @@
#include "pch.hpp"
-int WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd )
+auto on_exit() -> void;
+
+int WINAPI WinMain( _In_ HINSTANCE hInstance,
+ _In_opt_ HINSTANCE hPrevInstance,
+ _In_ LPSTR lpCmdLine,
+ _In_ int nShowCmd )
{
- // Sleep for 5 seconds before exiting.
- std::atexit( [] { std::this_thread::sleep_for( std::chrono::seconds( 5 ) ); } );
+ std::atexit( on_exit );
+
+ // ~ get arguments
+ //
+ int argc; auto* argv = CommandLineToArgvW( GetCommandLineW(), &argc );
- // Get arguments
- int argc {}; LPWSTR *argv = CommandLineToArgvW( GetCommandLineW(), &argc );
+ // ~ if an argument is passed inject the target dll, so we can drag and drop the dll to the exe.
+ //
+ if ( argv[1] ) utils::vars::cheat_filename = utils::string::wstring_to_string( argv[1] );
- // If an argument is passed inject the target dll, so we can drag and drop the dll to the exe.
- if (argv[1]) injector::get().cheat_filename = utils::string::wstring_to_string( argv[1] );
+ std::string proc_name;
+ std::cout << "Target process name: ";
+ std::cin >> proc_name;
- if (!injector::get().call())
- {
- log_err( "Injection failed!" );
+ if ( !g_injector.call( proc_name ) )
return EXIT_FAILURE;
- }
return EXIT_SUCCESS;
+}
+
+auto on_exit() -> void
+{
+ std::this_thread::sleep_for( 10s );
}
\ No newline at end of file
diff --git a/cozinha_loader/memory.hpp b/cozinha_loader/memory.hpp
index f527ced..29c2335 100644
--- a/cozinha_loader/memory.hpp
+++ b/cozinha_loader/memory.hpp
@@ -2,7 +2,7 @@
namespace memory
{
- inline bool open_process( std::string path, std::vector arguments, PROCESS_INFORMATION &pi )
+ inline bool open_process( std::string path, std::vector arguments, PROCESS_INFORMATION& pi )
{
STARTUPINFO si;
{
@@ -12,40 +12,40 @@ namespace memory
ZeroMemory( &pi, sizeof( pi ) );
- std::string str_path {};
+ std::string str_path{};
str_path += path;
- for (const auto &arg : arguments)
+ for ( const auto& arg : arguments )
str_path += (" " + arg);
- return CreateProcess( nullptr, const_cast(str_path.c_str()), nullptr, nullptr, false, 0, nullptr, nullptr, &si, &pi );
+ return CreateProcess( nullptr, str_path.data(), nullptr, nullptr, false, 0, nullptr, nullptr, &si, &pi );
}
- inline bool is_process_open( const std::vector> &vec_processes, std::string_view str_proc )
+ inline bool is_process_open( const std::vector>& vec_processes, std::string_view str_proc )
{
- if (vec_processes.empty())
+ if ( vec_processes.empty() )
return {};
- if (str_proc.empty())
+ if ( str_proc.empty() )
return {};
auto target = utils::string::to_lower( str_proc.data() );
- for (const auto &ctx : vec_processes)
+ for ( const auto& ctx : vec_processes )
{
auto ep = utils::string::to_lower( ctx.second );
- if (target.find( ".exe" ) == std::string::npos)
+ if ( target.find( ".exe" ) == std::string::npos )
{
- if (ep.find( target ) == std::string::npos)
+ if ( ep.find( target ) == std::string::npos )
continue;
}
else
{
- if (ep != target)
+ if ( ep != target )
continue;
}
const auto h_process = OpenProcess( PROCESS_VM_READ, false, ctx.first );
- if (h_process != nullptr)
+ if ( h_process != nullptr )
{
CloseHandle( h_process );
return true;
@@ -55,32 +55,32 @@ namespace memory
return {};
}
- inline bool kill_process( const std::vector> &vec_processes, std::string_view str_proc )
+ inline bool kill_process( const std::vector>& vec_processes, std::string_view str_proc )
{
- if (vec_processes.empty())
+ if ( vec_processes.empty() )
return {};
- if (str_proc.empty())
+ if ( str_proc.empty() )
return {};
auto executed = false;
auto target = utils::string::to_lower( str_proc.data() );
- for (const auto &ctx : vec_processes)
+ for ( const auto& ctx : vec_processes )
{
auto ep = utils::string::to_lower( ctx.second );
- if (target.find( ".exe" ) == std::string::npos)
+ if ( target.find( ".exe" ) == std::string::npos )
{
- if (ep.find( target ) == std::string::npos)
+ if ( ep.find( target ) == std::string::npos )
continue;
}
else
{
- if (ep != target)
+ if ( ep != target )
continue;
}
const auto h_process = OpenProcess( PROCESS_TERMINATE, false, ctx.first );
- if (h_process != nullptr)
+ if ( h_process != nullptr )
{
TerminateProcess( h_process, 9 );
CloseHandle( h_process );
@@ -92,26 +92,26 @@ namespace memory
return executed;
}
- inline std::uint32_t get_process_id_by_name( const std::vector> &vec_processes, std::string_view str_proc )
+ inline std::uint32_t get_process_id_by_name( const std::vector>& vec_processes, std::string_view str_proc )
{
- if (vec_processes.empty())
+ if ( vec_processes.empty() )
return {};
- if (str_proc.empty())
+ if ( str_proc.empty() )
return {};
auto target = utils::string::to_lower( str_proc.data() );
- for (const auto &ctx : vec_processes)
+ for ( const auto& ctx : vec_processes )
{
auto ep = utils::string::to_lower( ctx.second );
- if (target.find( ".exe" ) == std::string::npos)
+ if ( target.find( ".exe" ) == std::string::npos )
{
- if (ep.find( target ) == std::string::npos)
+ if ( ep.find( target ) == std::string::npos )
continue;
}
else
{
- if (ep != target)
+ if ( ep != target )
continue;
}
@@ -123,17 +123,17 @@ namespace memory
inline std::vector> get_process_list()
{
- std::vector> vec_list {};
+ std::vector> vec_list{};
const auto h_handle = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, NULL );
- PROCESSENTRY32 m_entry {};
+ PROCESSENTRY32 m_entry{};
m_entry.dwSize = sizeof( m_entry );
- if (!Process32First( h_handle, &m_entry ))
+ if ( !Process32First( h_handle, &m_entry ) )
return {};
- while (Process32Next( h_handle, &m_entry ))
+ while ( Process32Next( h_handle, &m_entry ) )
vec_list.emplace_back( m_entry.th32ProcessID, m_entry.szExeFile );
CloseHandle( h_handle );
diff --git a/cozinha_loader/pch.hpp b/cozinha_loader/pch.hpp
index 0f88985..cce70cc 100644
--- a/cozinha_loader/pch.hpp
+++ b/cozinha_loader/pch.hpp
@@ -4,13 +4,15 @@
#include
#include
#include
-#include
-#include
+
+#include
+#include
#include
+using namespace std::chrono_literals;
+
// header files
-#include "singleton.hpp"
#include "logger.hpp"
#include "utils.hpp"
#include "memory.hpp"
diff --git a/cozinha_loader/singleton.hpp b/cozinha_loader/singleton.hpp
deleted file mode 100644
index 020d61b..0000000
--- a/cozinha_loader/singleton.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-template
-class singleton
-{
-protected:
- singleton() {}
- ~singleton() {}
-
- singleton( const singleton & ) = delete;
- singleton &operator=( const singleton & ) = delete;
-
- singleton( singleton && ) = delete;
- singleton &operator=( singleton && ) = delete;
-public:
- static T &get()
- {
- static T inst {};
- return inst;
- }
-};
\ No newline at end of file
diff --git a/cozinha_loader/utils.hpp b/cozinha_loader/utils.hpp
index 510f2c5..8ab1400 100644
--- a/cozinha_loader/utils.hpp
+++ b/cozinha_loader/utils.hpp
@@ -4,20 +4,39 @@ namespace utils
{
namespace string
{
- inline std::string to_lower( std::string string )
+ inline std::string to_lower( std::string str )
{
- std::transform( string.begin(), string.end(), string.begin(), static_cast(::tolower) );
- return string;
+ std::transform( str.begin(), str.end(), str.begin(), static_cast(::tolower) );
+ return str;
}
- inline std::string wstring_to_string( std::wstring wstring )
+ inline std::string to_upper( std::string str )
{
- if (wstring.empty())
- return {};
+ std::transform( str.begin(), str.end(), str.begin(), static_cast(::toupper) );
+ return str;
+ }
+
+ inline std::wstring string_to_wstring( std::string str )
+ {
+ if ( str.empty() )
+ return std::wstring();
+
+ const auto len = str.length() + 1;
+ auto ret = std::wstring( len, 0 );
+ const auto size = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, &str[0], str.size(), &ret[0], len );
+ ret.resize( size );
+
+ return ret;
+ }
+
+ inline std::string wstring_to_string( std::wstring wstr )
+ {
+ if ( wstr.empty() )
+ return std::string();
- const auto size = WideCharToMultiByte( CP_UTF8, WC_ERR_INVALID_CHARS, &wstring[0], wstring.size(), nullptr, 0, nullptr, nullptr );
+ const auto size = WideCharToMultiByte( CP_UTF8, WC_ERR_INVALID_CHARS, &wstr[0], wstr.size(), nullptr, 0, nullptr, nullptr );
auto ret = std::string( size, 0 );
- WideCharToMultiByte( CP_UTF8, WC_ERR_INVALID_CHARS, &wstring[0], wstring.size(), &ret[0], size, nullptr, nullptr );
+ WideCharToMultiByte( CP_UTF8, WC_ERR_INVALID_CHARS, &wstr[0], wstr.size(), &ret[0], size, nullptr, nullptr );
return ret;
}
@@ -25,10 +44,10 @@ namespace utils
namespace other
{
- inline bool read_file_to_memory( const std::string &path, std::vector *out_buffer )
+ inline bool read_file_to_memory( const std::string& path, std::vector* out_buffer )
{
std::ifstream file( path, std::ios::binary );
- if (!file)
+ if ( !file )
return {};
out_buffer->assign( (std::istreambuf_iterator( file )), std::istreambuf_iterator() );
@@ -39,17 +58,17 @@ namespace utils
inline std::string get_steam_path()
{
- HKEY h_key {};
- if (RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Valve\\Steam", 0, KEY_QUERY_VALUE, &h_key ) != ERROR_SUCCESS)
+ HKEY h_key{};
+ if ( RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Valve\\Steam", 0, KEY_QUERY_VALUE, &h_key ) != ERROR_SUCCESS )
{
RegCloseKey( h_key );
return {};
}
- char steam_path_reg[MAX_PATH] {}; steam_path_reg[0] = '"';
+ char steam_path_reg[MAX_PATH]{}; steam_path_reg[0] = '"';
DWORD steam_path_size = sizeof( steam_path_reg ) - sizeof( char );
- if (RegQueryValueEx( h_key, "SteamExe", nullptr, nullptr, (LPBYTE) (steam_path_reg + 1), &steam_path_size ) != ERROR_SUCCESS)
+ if ( RegQueryValueEx( h_key, "SteamExe", nullptr, nullptr, (LPBYTE) (steam_path_reg + 1), &steam_path_size ) != ERROR_SUCCESS )
{
RegCloseKey( h_key );
return {};
@@ -59,10 +78,10 @@ namespace utils
return std::string( steam_path_reg ) + "\"";
}
+ }
- inline bool safe_close_handle( HANDLE h_handle )
- {
- return h_handle && h_handle != INVALID_HANDLE_VALUE ? CloseHandle( h_handle ) : true;
- }
+ namespace vars
+ {
+ inline std::string cheat_filename = "cheat.dll";
}
}
\ No newline at end of file