19 #ifndef PSYSTEM_FRAMEWORK_SHARED_LIBRARY_HPP
20 #define PSYSTEM_FRAMEWORK_SHARED_LIBRARY_HPP
25 #include <type_traits>
86 std::string library_name,
size_t num_functions)
noexcept;
187 export_names, export_names + N,
189 [
this] (
char const *export_name) {
222 template <
typename T>
226 std::is_function<T>::value,
227 "Template argument must be a function pointer.");
297 template <
typename T,
typename is_
void_ref = has_
void_return_type<T>>
328 template <
typename... Args>
334 -> decltype(std::declval<T>()(std::forward<Args>(args)...))
337 return (*this->
m_function)(std::forward<Args>(args)...);
354 template <
typename T>
383 template <
typename... Args>
387 this->
m_function(std::forward<Args>(args)...);
394 #endif // PSYSTEM_FRAMEWORK_SHARED_LIBRARY_HPP
bool is_loaded() const noexcept
Determines if the shared library is mapped into the process space.
Definition: shared_library.cpp:222
library_version get_version() const
Access the version for the library that this instance wraps.
Definition: shared_library.cpp:163
loaded_function_base(FARPROC proc)
Construct a loaded_function from a function pointer.
Definition: shared_library.hpp:235
FARPROC get_function(char const *export_name) const
Acquire a function pointer (by name) from a loaded library.
Definition: shared_library.cpp:258
void retarget(FARPROC proc) noexcept
Re-assign a function pointer to this functor instance.
Definition: shared_library.hpp:250
Defines the psystem::not_assignable interface.
loaded_function(FARPROC proc)
Construct a loaded_function from a function pointer.
Definition: shared_library.hpp:367
Definition: shared_handle.hpp:782
~shared_library() noexcept
Clean up the shared library.
Definition: shared_library.cpp:154
Remove the ability to copy or reassign from derived classes.
Definition: not_copyable.hpp:43
T * m_function
The function pointer that may be invoked.
Definition: shared_library.hpp:266
Load shared libraries into the current process for execution.
Definition: shared_library.hpp:55
Declare an RAII container for sharing system API handles (psystem::shared_handle).
T * get_ptr() const noexcept
Access the function pointer contained here directly.
Definition: shared_library.hpp:259
void load()
Loads the requested library into the current process space.
Definition: shared_library.cpp:228
std::vector< FARPROC > m_functions
The cache of function pointers gathered from a loaded library.
Definition: shared_library.hpp:199
std::string m_library_name
The (passed-in) name of the library that this class represents.
Definition: shared_library.hpp:205
void load_all_functions(char const *export_names[N])
Fully populate the m_functions data with addresses.
Definition: shared_library.hpp:181
Contains the process examination "system" and basic frameworks.
Definition: pstack_event_handler.hpp:28
psystem::shared_handle< HMODULE, nullptr > m_library_handle
The system handle to the loaded library. It may be nullptr.
Definition: shared_library.hpp:202
Wraps the C++ standard header, type_traits, to provide a few more metafunctions.
void operator()(Args &&...args)
Invoke the library function.
Definition: shared_library.hpp:384
shared_library(std::string library_name, size_t num_functions) noexcept
Construct a shared library instance (without loading the module).
Definition: shared_library.cpp:146
uint32_t library_version
Type for shared library versions.
Definition: shared_library.hpp:69
Encapsulate a loaded function's address into a callable functor.
Definition: shared_library.hpp:298
Common base class for all specializations of loaded_function.
Definition: shared_library.hpp:223
auto operator()(Args &&...args) -> decltype(std::declval< T >()(std::forward< Args >(args)...))
Invoke the library function.
Definition: shared_library.hpp:329
loaded_function(FARPROC proc)
Construct a loaded_function from a function pointer.
Definition: shared_library.hpp:310
void unload() noexcept
Unload this library and clear the function pointers.
Definition: shared_library.cpp:247