4 #include <plugify/load_flag.hpp>
5 #include <plugify/mem_addr.hpp>
6 #include <plugify_export.h>
33 Section(std::string_view sectionName, uintptr_t sectionBase,
size_t sectionSize)
34 :
name(sectionName),
base{sectionBase},
size{sectionSize} {}
67 using SearchDirs = std::vector<std::filesystem::path>;
76 explicit Assembly(std::string_view moduleName, LoadFlag flags = LoadFlag::Default,
const SearchDirs& additionalSearchDirectories = {},
bool sections =
false);
85 explicit Assembly(
const char* moduleName, LoadFlag flags = LoadFlag::Default,
const SearchDirs& additionalSearchDirectories = {},
bool sections =
false)
86 :
Assembly(std::string_view(moduleName), flags, additionalSearchDirectories, sections) {}
95 explicit Assembly(
const std::string& moduleName, LoadFlag flags = LoadFlag::Default,
const SearchDirs& additionalSearchDirectories = {},
bool sections =
false)
96 :
Assembly(std::string_view(moduleName), flags, additionalSearchDirectories, sections) {}
105 explicit Assembly(
const std::filesystem::path& modulePath, LoadFlag flags = LoadFlag::Default,
const SearchDirs& additionalSearchDirectories = {},
bool sections =
false);
114 explicit Assembly(
MemAddr moduleMemory, LoadFlag flags = LoadFlag::Default,
const SearchDirs& additionalSearchDirectories = {},
bool sections =
false);
180 const std::filesystem::path&
GetPath() const noexcept;
192 bool IsValid() const noexcept {
return _handle !=
nullptr; }
198 explicit operator bool() const noexcept {
return _handle !=
nullptr; }
216 bool Init(std::filesystem::path modulePath, LoadFlag flags,
const SearchDirs& additionalSearchDirectories,
bool sections);
227 bool InitFromName(std::string_view moduleName, LoadFlag flags,
const SearchDirs& additionalSearchDirectories,
bool sections,
bool extension =
false);
237 bool InitFromMemory(
MemAddr moduleMemory, LoadFlag flags,
const SearchDirs& additionalSearchDirectories,
bool sections);
241 std::filesystem::path _path;
243 Section _executableCode;
244 std::vector<Section> _sections;
253 int TranslateLoading(LoadFlag flags) noexcept;
261 LoadFlag TranslateLoading(
int flags) noexcept;
Represents an assembly (module) within a process.
Assembly()
Default constructor initializing handle to nullptr.
MemAddr GetFunctionByName(std::string_view functionName) const noexcept
Gets an address of a function by its name.
Section GetSectionByName(std::string_view sectionName) const noexcept
Gets a module section by name.
const std::string & GetError() const noexcept
Returns the module error.
MemAddr FindPattern(MemAddr pattern, std::string_view mask, MemAddr startAddress=nullptr, Section *moduleSection=nullptr) const
Finds an array of bytes in process memory using SIMD instructions.
Assembly(std::string_view moduleName, LoadFlag flags=LoadFlag::Default, const SearchDirs &additionalSearchDirectories={}, bool sections=false)
Constructs an Assembly object with the specified module name, flags, and sections.
void * GetHandle() const noexcept
Returns the module handle.
static std::pair< std::vector< uint8_t >, std::string > PatternToMaskedBytes(std::string_view input)
Converts a string pattern with wildcards to an array of bytes and mask.
bool operator==(const Assembly &assembly) const noexcept
Equality operator.
Assembly(const char *moduleName, LoadFlag flags=LoadFlag::Default, const SearchDirs &additionalSearchDirectories={}, bool sections=false)
Constructs an Assembly object with a char pointer as module name.
Assembly(MemAddr moduleMemory, LoadFlag flags=LoadFlag::Default, const SearchDirs &additionalSearchDirectories={}, bool sections=false)
Constructs an Assembly object with a memory address.
Assembly(const std::filesystem::path &modulePath, LoadFlag flags=LoadFlag::Default, const SearchDirs &additionalSearchDirectories={}, bool sections=false)
Constructs an Assembly object with a filesystem path as module path.
MemAddr FindPattern(std::string_view pattern, MemAddr startAddress=nullptr, Section *moduleSection=nullptr) const
Finds a string pattern in process memory using SIMD instructions.
const std::filesystem::path & GetPath() const noexcept
Returns the module path.
MemAddr GetVirtualTableByName(std::string_view tableName, bool decorated=false) const
Gets an address of a virtual method table by RTTI type descriptor name.
Assembly(const std::string &moduleName, LoadFlag flags=LoadFlag::Default, const SearchDirs &additionalSearchDirectories={}, bool sections=false)
Constructs an Assembly object with a string as module name.
MemAddr GetBase() const noexcept
Returns the module base address.
bool IsValid() const noexcept
Checks if the assembly is valid.
A wrapper class for memory addresses, providing utility functions for pointer manipulation.
Represents a section of the assembly.
Section(std::string_view sectionName, uintptr_t sectionBase, size_t sectionSize)
Parameterized constructor.
bool IsValid() const noexcept
Checks if the section is valid.
Section()
Default constructor initializing size to 0.
std::string name
The name of the section.
size_t size
The size of the section.
MemAddr base
The base address of the section.