From fcb0d220f9bf6f9b31b2bcd751f49e92e9f657b7 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Sun, 18 Jul 2021 18:11:20 +0200 Subject: [PATCH] Fix Quit Hard --- src/STDInclude.hpp | 1 + src/Utils/Library.cpp | 29 +++++++++++++++++++++++++++++ src/Utils/Library.hpp | 8 +++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index e06ba418..3a7fc61a 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -149,6 +149,7 @@ template class Sizer { }; #pragma comment(lib, "Advapi32.lib") #pragma comment(lib, "rpcrt4.lib") #pragma comment(lib, "dbghelp.lib") +#pragma comment(lib, "ntdll.lib") // Enable additional literals using namespace std::literals; diff --git a/src/Utils/Library.cpp b/src/Utils/Library.cpp index a8773cb8..4b6fc0e8 100644 --- a/src/Utils/Library.cpp +++ b/src/Utils/Library.cpp @@ -2,11 +2,40 @@ namespace Utils { + Library Library::load(const std::string& name) + { + return Library(LoadLibraryA(name.data())); + } + + Library Library::load(const std::filesystem::path& path) + { + return Library::load(path.generic_string()); + } + + Library Library::get_by_address(void* address) + { + HMODULE handle = nullptr; + GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, static_cast(address), &handle); + return Library(handle); + } + Library::Library(const std::string& buffer, bool _freeOnDestroy) : _module(nullptr), freeOnDestroy(_freeOnDestroy) { this->_module = LoadLibraryExA(buffer.data(), nullptr, 0); } + Library::Library(const std::string& buffer) + { + this->_module = GetModuleHandleA(buffer.data()); + this->freeOnDestroy = true; + } + + Library::Library(const HMODULE handle) + { + this->_module = handle; + this->freeOnDestroy = true; + } + Library::~Library() { if (this->freeOnDestroy) diff --git a/src/Utils/Library.hpp b/src/Utils/Library.hpp index 92674eaf..b479a6cf 100644 --- a/src/Utils/Library.hpp +++ b/src/Utils/Library.hpp @@ -5,8 +5,14 @@ namespace Utils class Library { public: + static Library load(const std::string& name); + static Library load(const std::filesystem::path& path); + static Library get_by_address(void* address); + Library() : _module(nullptr), freeOnDestroy(false) {}; - Library(const std::string& buffer, bool freeOnDestroy = true); + Library(const std::string& buffer, bool freeOnDestroy); + explicit Library(const std::string& name); + explicit Library(HMODULE handle); ~Library(); bool is_valid() const;