im not getting any string output #include <iostream> #include <fstream> #include…
- User
im not getting any string output #include #include #include #include #include <windows.h> #include <tlhelp32.h> #include <psapi.h> #include #include
// Struct for safely closing handles. struct HandleCloser { void operator()(HANDLE handle) const { if (handle && handle != INVALID_HANDLE_VALUE) { CloseHandle(handle); } } };
// Unique pointer type for Windows HANDLE using UniqueHandle = std::unique_ptr<std::remove_pointer::type, HandleCloser>;
// Section structure for storing section info struct Section { std::string name; uintptr_t start; uintptr_t end;
codeSection(const std::string& n = "", uintptr_t s = 0, uintptr_t e = 0) : name(n), start(s), end(e) {}};
// Function for logging messages to a file void log_message(std::ofstream& log_file, const char* format, ...) { va_list args; va_start(args, format); char buffer[2048]; vsnprintf(buffer, sizeof(buffer), format, args); va_end(args);
codelog_file << buffer << std::endl; log_file.flush();}
// Convert wide string to multibyte string for process and module names std::string ws2s(const std::wstring& wstr) { int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr); std::string str(bufferSize - 1, 0); WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], bufferSize, nullptr, nullptr); return str; }
// Retrieve a process ID by its process name. DWORD get_process_id_by_name(const std::string& process_name, std::ofstream& log_file) { UniqueHandle hSnapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)); if (!hSnapshot || hSnapshot.get() == INVALID_HANDLE_VALUE) { log_message(log_file, "CreateToolhelp32Snapshot failed with error: %lu", GetLastError()); return 0; }
codePROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); if (!Process32First(hSnapshot.get(), &pe32)) { log_message(log_file, "Process32First failed with error: %lu", GetLastError()); return 0; } do { if (_stricmp(ws2s(pe32.szExeFile).c_str(), process_name.c_str()) == 0) { return pe32.th32ProcessID; } } while (Process32Next(hSnapshot.get(), &pe32)); return 0;}
// Get base address of the main module for a given PID. uintptr_t get_base_address(DWORD pid, const std::string& process_name, std::ofstream& log_file) { UniqueHandle hSnapshot(CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid)); if (!hSnapshot || hSnapshot.get() == INVALID_HANDLE_VALUE) { log_message(log_file, "CreateToolhelp32Snapshot for modules failed with error: %lu", GetLastError()); return 0; }
- Assistant