This commit is contained in:
es3n1n
2025-05-07 17:01:09 +09:00
commit a49f027fde
33 changed files with 2609 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#pragma once
#include <filesystem>
#include <mutex>
#include <Windows.h>
namespace shared {
inline std::filesystem::path get_this_module_path() {
char result[_MAX_PATH] = {0};
/// \fixme @es3n1n: This is sketchy
HMODULE h_module = nullptr;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCSTR>(&get_this_module_path), &h_module);
GetModuleFileNameA(h_module, result, sizeof(result));
return result;
}
inline void alloc_console() {
static std::once_flag fl;
/// Most likely the process we're injecting to does not have allocated console
std::call_once(fl, []() -> void {
AllocConsole();
freopen_s(reinterpret_cast<FILE**>(stdout), "CONOUT$", "w", stdout);
freopen_s(reinterpret_cast<FILE**>(stderr), "CONOUT$", "w", stderr);
});
}
} // namespace shared