Skip to content

Commit

Permalink
Select process name
Browse files Browse the repository at this point in the history
  • Loading branch information
b1scoito committed May 27, 2021
1 parent caefc6d commit 22fe234
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 208 deletions.
3 changes: 2 additions & 1 deletion cozinha_loader/cozinha_loader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<CompileAs>CompileAsCpp</CompileAs>
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -97,6 +98,7 @@
<DebugInformationFormat>None</DebugInformationFormat>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CompileAs>CompileAsCpp</CompileAs>
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -117,7 +119,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="singleton.hpp" />
<ClInclude Include="vac3_bypass_data.hpp" />
<ClInclude Include="injection.hpp" />
<ClInclude Include="logger.hpp" />
Expand Down
24 changes: 9 additions & 15 deletions cozinha_loader/cozinha_loader.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@
<Filter Include="pch">
<UniqueIdentifier>{ebfadaa9-2c80-4c74-b27c-c01e8ed57886}</UniqueIdentifier>
</Filter>
<Filter Include="helpers">
<Filter Include="ext">
<UniqueIdentifier>{ba7bf719-1929-4eed-a323-02c32e116f3f}</UniqueIdentifier>
</Filter>
<Filter Include="helpers\memory">
<Filter Include="ext\memory">
<UniqueIdentifier>{8f4f41f8-3272-4c46-a64b-a5209764d0cf}</UniqueIdentifier>
</Filter>
<Filter Include="helpers\logging">
<Filter Include="ext\logging">
<UniqueIdentifier>{10d10d53-65fa-4875-965f-f7ec0fa57614}</UniqueIdentifier>
</Filter>
<Filter Include="helpers\utils">
<Filter Include="ext\utils">
<UniqueIdentifier>{5dfeec10-d957-4322-8a9a-3f33434a2c17}</UniqueIdentifier>
</Filter>
<Filter Include="helpers\vac3_bypass">
<Filter Include="ext\vac3_bypass">
<UniqueIdentifier>{1771c7ca-3cf1-4f5a-8fb0-c784c17f5d96}</UniqueIdentifier>
</Filter>
<Filter Include="helpers\singleton">
<UniqueIdentifier>{526d0e79-9eb5-4faa-8937-dab1afdc9273}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
Expand All @@ -40,22 +37,19 @@
<Filter>pch</Filter>
</ClInclude>
<ClInclude Include="logger.hpp">
<Filter>helpers\logging</Filter>
<Filter>ext\logging</Filter>
</ClInclude>
<ClInclude Include="memory.hpp">
<Filter>helpers\memory</Filter>
<Filter>ext\memory</Filter>
</ClInclude>
<ClInclude Include="utils.hpp">
<Filter>helpers\utils</Filter>
<Filter>ext\utils</Filter>
</ClInclude>
<ClInclude Include="injection.hpp">
<Filter>loader</Filter>
</ClInclude>
<ClInclude Include="vac3_bypass_data.hpp">
<Filter>helpers\vac3_bypass</Filter>
</ClInclude>
<ClInclude Include="singleton.hpp">
<Filter>helpers\singleton</Filter>
<Filter>ext\vac3_bypass</Filter>
</ClInclude>
</ItemGroup>
</Project>
141 changes: 76 additions & 65 deletions cozinha_loader/injection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,170 +3,181 @@

bool injector::map( std::string process, std::wstring module_name, std::vector<std::uint8_t> 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 );
};

bypass_nt_open_file( memory::get_process_id_by_name( process_list, process ) );
}

blackbone::Process bb_process {};
blackbone::Process bb_process;

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

log_debug( "Injecting into [ %s ] waiting for [ %ls ]...", process.c_str(), module_name.c_str() );
log_debug( "injecting into [ %s ] waiting for [ %ls ]...", process.c_str(), module_name.c_str() );

// Wait for a process module so we can continue with injection.
// ~ wait for a process module so we can continue with injection
//
auto mod_ready = false;
while (!mod_ready)
while ( !mod_ready )
{
std::this_thread::sleep_for( 500ms );

for (const auto &mod : bb_process.modules().GetAllModules())
for ( const auto& mod : bb_process.modules().GetAllModules() )
{
if (mod.first.first == module_name)
if ( mod.first.first == module_name )
{
mod_ready = true;
break;
}
}

if (mod_ready)
if ( mod_ready )
break;

std::this_thread::sleep_for( 500ms );
}

// Resolve PE imports
const auto mod_callback = []( blackbone::CallbackType type, void *, blackbone::Process &, const blackbone::ModuleData &modInfo )
// ~ 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 ( type == blackbone::PreCallback )
{
if (modInfo.name == std::wstring( user32.begin(), user32.end() ))
if ( modInfo.name == std::wstring( user32.begin(), user32.end() ) )
return blackbone::LoadData( blackbone::MT_Native, blackbone::Ldr_Ignore );
}
return blackbone::LoadData( blackbone::MT_Default, blackbone::Ldr_Ignore );
};

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

return false;
}

// Free memory and detach from process
// ~ free memory and detach from process
//
bb_process.Detach();

log_ok( "Injected into [ %s ] successfully!", process.c_str() );
log_ok( "injected into [ %s ] successfully!", process.c_str() );
return true;
}

bool injector::call()
bool injector::call( std::string process_name )
{
if (!std::filesystem::exists( cheat_filename ))
if ( !std::filesystem::exists( utils::vars::cheat_filename ) )
{
log_err( "[ %s ] not found! Try dragging and dropping the dll into the loader or putting a cheat dll called cheat.dll in the same folder as the loader.", cheat_filename.c_str() );
log_err( "[ %s ] not found!", utils::vars::cheat_filename.c_str() );
return false;
}

// Closing processes
close_processes( { "csgo.exe", "steam.exe" } );
// ~ closing processes
//
close_processes( { process_name, "steam.exe" } );

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

log_info( "Steam path [ %s ], Opening steam...", steam_path.c_str() );
log_debug( "opening steam [ %s ]...", steam_path.c_str() );

PROCESS_INFORMATION pi {};
if (!memory::open_process( steam_path, { "-console", "-applaunch 730" }, pi ))
PROCESS_INFORMATION pi{};
if ( !memory::open_process( steam_path, { "-console" }, pi ) )
{
log_err( "Failed to open steam! [ open_process_failed ]" );
log_err( "failed to open steam!" );

utils::other::safe_close_handle( pi.hProcess );
utils::other::safe_close_handle( pi.hThread );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );

return false;
}

utils::other::safe_close_handle( pi.hProcess );
utils::other::safe_close_handle( pi.hThread );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );

std::vector<std::uint8_t> cheat {};
std::vector<std::uint8_t> 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<std::string> 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 );
}
}
}
12 changes: 5 additions & 7 deletions cozinha_loader/injection.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#pragma once

using namespace std::chrono_literals;

class injector: public singleton<injector>
class injector
{
private:
bool map( std::string process, std::wstring module_name, std::vector<std::uint8_t> binary_bytes );
void close_processes( std::vector<std::string> processes );

public:
std::string cheat_filename = "cheat.dll";

injector() = default;
~injector() = default;

bool call();
};
bool call( std::string process_name );
};

inline auto g_injector = injector();
Loading

0 comments on commit 22fe234

Please sign in to comment.