#include <windows.h>
#include <string>
#include <vector>
#include <iostream>
bool is_valid_path(const std::string& path) {
if (path.length() < 3) return false;
if (!isalpha(path[0])) return false;
if (path[1] != ':') return false;
if (path[2] != '\\') return false;
return true;
}
void search_registry_key(HKEY root, const std::string& sub_key, const std::string& search_str, std::vector<std::string>& results) {
HKEY h_key;
if (RegOpenKeyExA(root, sub_key.c_str(), 0, KEY_READ, &h_key) != ERROR_SUCCESS) return;
char value_name[16384];
DWORD value_name_size;
DWORD value_type;
char value_data[32767];
DWORD value_data_size;
int index = 0;
while (true) {
value_name_size = sizeof(value_name);
value_data_size = sizeof(value_data);
LONG result = RegEnumValueA(h_key, index, value_name, &value_name_size, nullptr, &value_type, (LPBYTE)value_data, &value_data_size);
if (result == ERROR_NO_MORE_ITEMS) break;
if (result == ERROR_SUCCESS && value_type == REG_SZ) {
std::string data(value_data);
if (data.find(search_str) != std::string::npos && is_valid_path(data)) {
results.push_back(data);
}
}
index++;
}
RegCloseKey(h_key);
}
void search_registry_recursive(HKEY root, const std::string& current_path, const std::string& search_str, std::vector<std::string>& results, int depth = 0) {
if (depth > 6) return;
HKEY h_key;
if (RegOpenKeyExA(root, current_path.c_str(), 0, KEY_READ, &h_key) != ERROR_SUCCESS) return;
search_registry_key(root, current_path, search_str, results);
char sub_key_name[256];
DWORD sub_key_name_size;
int index = 0;
while (true) {
sub_key_name_size = sizeof(sub_key_name);
LONG result = RegEnumKeyExA(h_key, index, sub_key_name, &sub_key_name_size, nullptr, nullptr, nullptr, nullptr);
if (result == ERROR_NO_MORE_ITEMS) break;
if (result == ERROR_SUCCESS) {
std::string new_path = current_path.empty() ? sub_key_name : current_path + "\\" + sub_key_name;
search_registry_recursive(root, new_path, search_str, results, depth + 1);
}
index++;
}
RegCloseKey(h_key);
}
int main() {
std::vector<std::string> results;
std::string search_str = "steamapps\\common\\Counter-Strike Global Offensive\\game\\bin\\win64\\cs2.exe";
search_registry_recursive(HKEY_LOCAL_MACHINE, "", search_str, results);
search_registry_recursive(HKEY_CURRENT_USER, "", search_str, results);
for (const auto& path : results) {
std::cout << "found: " << path << std::endl;
if (GetFileAttributesA(path.c_str()) != INVALID_FILE_ATTRIBUTES) {
std::cout << "file exists and is valid" << std::endl;
STARTUPINFOA si = { sizeof(si) };
PROCESS_INFORMATION pi;
if (CreateProcessA(path.c_str(), nullptr, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi)) {
std::cout << "cs2 launched successfully!" << std::endl;
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else {
std::cout << "failed to launch cs2" << std::endl;
}
}
}
if (results.empty()) {
std::cout << "cs2 not found in registry" << std::endl;
}
return 0;
}