Skip to content

Commit

Permalink
added: list of app_ids for automatic game opening
Browse files Browse the repository at this point in the history
  • Loading branch information
b1scoito committed Jul 7, 2021
1 parent 1710964 commit 44df96d
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 97 deletions.
192 changes: 103 additions & 89 deletions cozinha_loader/injection.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,94 @@
#include "pch.hpp"
#include "injection.hpp"

bool injector::map( std::string process, std::wstring module_name, std::vector<std::uint8_t> binary_bytes )
bool c_injector::init( std::string proc_name, std::string cheat_name )
{
// ~ closing processes
close_processes( { proc_name, "steam.exe" } );

const auto steam_path = other::get_steam_path();
if ( steam_path.empty() )
{
log_err( "Failed to retrieve steam path!" );
return false;
}

log_debug( "Opening steam [ %ls ]...", steam_path.c_str() );

std::string append_option {};

for ( const auto& id : app_ids )
{
if ( id.second.find( proc_name ) != std::string::npos )
append_option = string::format( "-applaunch %d", id.first );
}

PROCESS_INFORMATION pi {};
if ( !memory::open_process( steam_path, { L"-console", string::to_unicode( append_option ) }, pi ) )
{
log_err( "Failed to open steam!" );

if ( pi.hProcess )
CloseHandle( pi.hProcess );

if ( pi.hThread )
CloseHandle( pi.hThread );

return false;
}

if ( pi.hProcess )
CloseHandle( pi.hProcess );

if ( pi.hThread )
CloseHandle( pi.hThread );

std::vector<std::uint8_t> cheat_buf {};

// ~ reading file and writing it to a variable
if ( !other::read_file_to_memory( std::filesystem::absolute( cheat_name ).string(), &cheat_buf ) )
{
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 ) )
{
log_err( "Steam memory mapping failure!" );
return false;
}

// ~ inject cheat to process
if ( !map( proc_name, L"serverbrowser.dll", cheat_buf ) )
{
log_err( "Cheat memory mapping failure!" );
return false;
}

log_ok( "All done." );

return true;
}

bool c_injector::map( std::string proc, std::wstring mod_name, std::vector<std::uint8_t> buf )
{
// ~ wait for process to be opened
log_debug( "Waiting for [ %s ] to be opened...", process.c_str() );
log_debug( "Waiting for - [ %s ] to be opened...", proc.c_str() );

auto process_list = memory::get_process_list();
auto proc_list = memory::get_process_list();
do
{
process_list = memory::get_process_list();
proc_list = memory::get_process_list();

std::this_thread::sleep_for( 500ms );
} while ( !memory::is_process_open( process_list, process ) );

} while ( !memory::is_process_open( proc_list, proc ) );

// ~ bypassing injection block by csgo (-allow_third_party_software) the easiest way
if ( process.find( "csgo" ) != std::string::npos )
if ( proc.find( "csgo" ) != std::string::npos )
{
const auto bypass_nt_open_file = []( DWORD pid )
const auto bypass_nt_open_file = []( uint32_t pid )
{
const auto h_process = OpenProcess( PROCESS_ALL_ACCESS, false, pid );
const auto nt_dll = LoadLibrary( L"ntdll" );
Expand All @@ -43,23 +114,23 @@ bool injector::map( std::string process, std::wstring module_name, std::vector<s
return true;
};

if ( !bypass_nt_open_file( memory::get_process_id_by_name( process_list, process ) ) )
if ( !bypass_nt_open_file( memory::get_process_id_by_name( proc_list, proc ) ) )
return false;
}

blackbone::Process bb_process;
blackbone::Process bb_proc;

bb_process.Attach( memory::get_process_id_by_name( process_list, process ), PROCESS_ALL_ACCESS );
bb_proc.Attach( memory::get_process_id_by_name( proc_list, proc ), PROCESS_ALL_ACCESS );

log_debug( "Injecting into [ %s ] waiting for [ %ls ]...", process.c_str(), module_name.c_str() );
log_debug( "Waiting for - [ %ls ] in %s...", mod_name.c_str(), proc.c_str() );

// ~ wait for a process module so we can continue with injection
auto mod_ready = false;
while ( !mod_ready )
{
for ( const auto& mod : bb_process.modules().GetAllModules() )
for ( const auto& mod : bb_proc.modules().GetAllModules() )
{
if ( mod.first.first == module_name )
if ( mod.first.first == mod_name )
{
mod_ready = true;
break;
Expand All @@ -75,108 +146,51 @@ bool injector::map( std::string process, std::wstring module_name, std::vector<s
// ~ resolve PE imports
const auto mod_callback = []( blackbone::CallbackType type, void*, blackbone::Process&, const blackbone::ModuleData& modInfo )
{
std::string user32 = "user32.dll";

if ( type == blackbone::PreCallback )
{
if ( modInfo.name == std::wstring( user32.begin(), user32.end() ) )
if ( modInfo.name == L"user32.dll" )
return blackbone::LoadData( blackbone::MT_Native, blackbone::Ldr_Ignore );
}

return blackbone::LoadData( blackbone::MT_Default, blackbone::Ldr_Ignore );
};

const auto call_result = bb_proc.mmap().MapImage( buf.size(), buf.data(), false, blackbone::WipeHeader | blackbone::NoThreads, mod_callback );

// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55
log_debug( "Map Result - [ 0x%.8X ]", call_result.status );

// ~ mapping dll bytes to the process
if ( !bb_process.mmap().MapImage( binary_bytes.size(), binary_bytes.data(), false, blackbone::WipeHeader | blackbone::NoThreads, mod_callback, nullptr, nullptr ).success() )
if ( !call_result.success() )
{
log_err( "Failed to inject into [ %s ]!", process.c_str() );
bb_process.Detach();

return false;
}

// ~ free memory and detach from process
bb_process.Detach();
log_err( "Failed to inject into [ %s ]!", proc.c_str() );

log_ok( "Injected into [ %s ] successfully!", process.c_str() );
bb_proc.Terminate();
bb_proc.Detach();

return true;
}

bool injector::call( std::string process_name, std::string cheat_filename )
{
// ~ closing processes
close_processes( { process_name, "steam.exe" } );

const auto steam_path = other::get_steam_path();
if ( steam_path.empty() )
{
log_err( "Failed to retrieve steam path!" );
return false;
}

log_debug( "Opening steam [ %ls ]...", steam_path.c_str() );

PROCESS_INFORMATION pi {};
if ( !memory::open_process( steam_path, { L"-console" }, pi ) )
{
log_err( "Failed to open steam!" );

if ( pi.hProcess )
CloseHandle( pi.hProcess );

if ( pi.hThread )
CloseHandle( pi.hThread );

return false;
}

if ( pi.hProcess )
CloseHandle( pi.hProcess );

if ( pi.hThread )
CloseHandle( pi.hThread );

std::vector<std::uint8_t> cheat_buf {};

// ~ reading file and writing it to a variable
if ( !other::read_file_to_memory( std::filesystem::absolute( cheat_filename ).string(), &cheat_buf ) )
{
log_err( "Failed to write dll buffer to memory!" );
return false;
}

// ~ inject vac bypass to steam
if ( !map( "steam.exe", L"tier0_s.dll", vac3_data ) )
{
log_err( "Steam memory mapping failure!" );
return false;
}

// ~ inject cheat to process
if ( !map( process_name, L"serverbrowser.dll", cheat_buf ) )
{
log_err( "Cheat memory mapping failure!" );
return false;
}
// ~ free memory and detach from process
bb_proc.Detach();

log_ok( "All done!" );
log_ok( "Injected into %s.", proc.c_str() );

return true;
}

void injector::close_processes( std::vector<std::string> processes )
void c_injector::close_processes( std::vector<std::string> processes )
{
auto process_list = memory::get_process_list();
for ( const auto& process : processes )
auto proc_list = memory::get_process_list();
for ( const auto& proc : processes )
{
do
{
memory::kill_process( process_list, process );
process_list = memory::get_process_list();
memory::kill_process( proc_list, proc );
proc_list = memory::get_process_list();

std::this_thread::sleep_for( 500ms );
} while ( memory::is_process_open( process_list, process ) );

} while ( memory::is_process_open( proc_list, proc ) );
}
}
17 changes: 11 additions & 6 deletions cozinha_loader/injection.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#pragma once

class injector
class c_injector
{
private:
bool map( std::string process, std::wstring module_name, std::vector<std::uint8_t> binary_bytes );
bool map( std::string proc, std::wstring mod_name, std::vector<std::uint8_t> buf );

void close_processes( std::vector<std::string> processes );

std::vector<std::pair<int, std::string>> app_ids =
{
{ 730, "csgo.exe" } // Counter-Strike: Global Offensive
};

public:
injector() = default;
~injector() = default;
c_injector() = default;
~c_injector() = default;

bool call( std::string process_name, std::string cheat_filename );
bool init( std::string process_name, std::string cheat_filename );
};

inline auto g_injector = injector();
inline auto g_injector = std::make_unique<c_injector>();
2 changes: 1 addition & 1 deletion cozinha_loader/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class logger
}
};

inline auto g_logger = logger( L"-> cozinha loader" );
inline auto g_logger = logger( L"> cozinha loader" );
#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_err(...) g_logger.print( msg_type_t::LERROR, __FUNCTION__, __VA_ARGS__ )
Expand Down
2 changes: 1 addition & 1 deletion cozinha_loader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ INT WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
std::cin.clear();

// ~ this function will inject vac3 bypass and the cheat dll on the target process
if ( !g_injector.call( proc_name, cheat_name ) )
if ( !g_injector->init( proc_name, cheat_name ) )
return EXIT_FAILURE;

return EXIT_SUCCESS;
Expand Down
9 changes: 9 additions & 0 deletions cozinha_loader/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

namespace string
{
template<typename ... args>
std::string format( const std::string& format, args ... arg )
{
const size_t size = std::snprintf( nullptr, 0, format.c_str(), arg ... ) + 1;
std::unique_ptr<char[]> buf( new char[size] );
std::snprintf( buf.get(), size, format.c_str(), arg ... );
return std::string( buf.get(), buf.get() + size - 1 );
}

std::string to_lower( std::string str );
std::string to_upper( std::string str );

Expand Down

0 comments on commit 44df96d

Please sign in to comment.