#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
#include <string>
#include <filesystem>
#include <thread>
namespace fs = std::filesystem;
DWORD GetProcessIdByName(const std::string& processName) {
PROCESSENTRY32 processEntry = { sizeof(PROCESSENTRY32) };
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE) {
return 0;
}
DWORD processId = 0;
if (Process32First(snapshot, &processEntry)) {
do {
if (processName == processEntry.szExeFile) {
processId = processEntry.th32ProcessID;
break;
}
} while (Process32Next(snapshot, &processEntry));
}
CloseHandle(snapshot);
return processId;
}
bool InjectDLL(DWORD processId, const std::string& dllPath) {
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
if (!hProcess) {
std::cerr << "Failed to open target process." << std::endl;
return false;
}
void* pAlloc = VirtualAllocEx(hProcess, nullptr, dllPath.size() + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if (!pAlloc) {
std::cerr << "Failed to allocate memory in target process." << std::endl;
CloseHandle(hProcess);
return false;
}
if (!WriteProcessMemory(hProcess, pAlloc, dllPath.c_str(), dllPath.size() + 1, nullptr)) {
std::cerr << "Failed to write to target process memory." << std::endl;
VirtualFreeEx(hProcess, pAlloc, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
HMODULE hKernel32 = GetModuleHandle("kernel32.dll");
if (!hKernel32) {
std::cerr << "Failed to get handle to kernel32.dll." << std::endl;
VirtualFreeEx(hProcess, pAlloc, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
HANDLE hThread = CreateRemoteThread(hProcess, nullptr, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32, "LoadLibraryA"), pAlloc, 0, nullptr);
if (!hThread) {
std::cerr << "Failed to create remote thread in target process." << std::endl;
VirtualFreeEx(hProcess, pAlloc, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
VirtualFreeEx(hProcess, pAlloc, 0, MEM_RELEASE);
CloseHandle(hProcess);
return true;
}
int main() {
std::string dllName;
std::string dllPath;
for (const auto& entry : fs::directory_iterator(fs::current_path())) {
if (entry.path().extension() == ".dll") {
dllName = entry.path().filename().string();
dllPath = entry.path().string();
break;
}
}
if (dllName.empty()) {
std::cerr << "No DLL found in the current folder." << std::endl;
return 1;
}
std::cout << "Found DLL: " << dllName << std::endl;
DWORD steamProcessId = GetProcessIdByName("steam.exe");
if (steamProcessId == 0) {
std::cout << "steam.exe is not running. Continue without Steam? (1/Y to continue, anything else to cancel): ";
std::string response;
std::cin >> response;
if (response != "1" && response != "Y" && response != "y") {
std::cout << "Injection canceled. Exiting..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(5));
return 0;
}
} else {
std::string steamDllPath;
for (const auto& entry : fs::directory_iterator(fs::current_path())) {
if (entry.path().filename() == "steam.dll") {
steamDllPath = entry.path().string();
break;
}
}
if (!steamDllPath.empty()) {
std::cout << "Injecting steam.dll into steam.exe..." << std::endl;
if (InjectDLL(steamProcessId, steamDllPath)) {
std::cout << "Successfully injected steam.dll into steam.exe." << std::endl;
} else {
std::cerr << "Failed to inject steam.dll into steam.exe." << std::endl;
}
} else {
std::cout << "steam.dll not found. Continue without Steam injection? (1/Y to continue, anything else to cancel): ";
std::string response;
std::cin >> response;
if (response != "1" && response != "Y" && response != "y") {
std::cout << "Injection canceled. Exiting..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(5));
return 0;
}
}
}
std::cout << "Waiting for csgo.exe to open..." << std::endl;
DWORD csgoProcessId = 0;
while ((csgoProcessId = GetProcessIdByName("csgo.exe")) == 0) {
std::this_thread::sleep_for(std::chrono::seconds(5));
}
std::cout << "Injecting " << dllName << " into csgo.exe..." << std::endl;
if (InjectDLL(csgoProcessId, dllPath)) {
std::cout << "Successfully injected " << dllName << " into csgo.exe." << std::endl;
} else {
std::cerr << "Failed to inject " << dllName << " into csgo.exe." << std::endl;
}
std::this_thread::sleep_for(std::chrono::seconds(5));
return 0;
}