Skip to content

Documentation

Noah edited this page Oct 17, 2021 · 19 revisions

Welcome to the documentation!

Table of contents:

Detour

Is used to hook functions.

Note: detour follows the RAII paradigm and will unhook the target function if the detour object is destroyed.


template <typename target_t, typename replacement_t>
std::unique_ptr<detour> create(const target_t &target, const replacement_t &replacement, detour_status &status);

Constructs a detour from the given arguments

target: Address of the function to be hooked
replacement: Address of the hook function
(optional) status: Reference to a status object

Returns: In case the hook creation fails a nullptr is returned and the status variable will be set to the corresponding error code.


template <typename type_t> 
func_t<type_t> get_original() const;

Returns: A function pointer to the original function with the given signature (type_t).

Address

Wraps a memory address


std::uintptr_t get() const;

Returns: The current memory address


std::optional<std::uintptr_t> get_safe() const;

Returns: The current memory address if it is at least readable, nullopt otherwise


template <typename T> 
T get_as() const;

Returns: The current memory address read as a T pointer.


template <typename T> 
std::optional<T> get_as_safe() const;

Returns: The current memory address read as a T pointer if it is at least readable, nullopt otherwise.


std::optional<address> follow() const;

Returns: The destination of the current instruction in case it leads somewhere.


std::optional<std::uint32_t> get_mnemonic() const;

Returns: The mnemonic of the current instruction.


std::optional<address> read_until(const std::uint32_t &mnemonic) const;

Reads the remaining memory of the current page until a instruction with the given mnemonic is reached.
If such an instruction is found it is returned, otherwise the return value is nullopt.

Console

Allows to allocate a console and redirect output to it or a file


void restore();

Restores cout to its initial state.


void alloc_console(const std::string &name);

Allocates a console with the given name and redirects cout to it.


void redirect_to_file(const std::filesystem::path &file);

Redirects cout to the given file.

Entrypoint

If you want to use the entrypoint header you need to include it and then define two functions:

template <typename... params_t> void entry(const params_t &...)
{
   // Called on entry
}

template <typename... params_t> void exit(const params_t &...)
{
   // Called on exit
}

The arguments the function is called with vary depending on the operating system.
On windows you will get all the parameters that are normally passed to DllMain.

You can check the operating system by making use of the constants in constants/os.hpp

Clone this wiki locally