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 to 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 found in constants/os.hpp.

Keyboard

A cross-platform GetAsyncKeyState implementation.


void press(const int &);

Presses the given key.


void release(const int &);

Releases the given key


bool is_down(const int &);

Checks if the given key is currently pressed.


bool was_pressed(const int &);

Checks whether the given key is pressed currently but was not pressed the last time any of the keyboard functions were called.

Memory

Provides function for interaction with memory.


bool write(const std::uintptr_t &address, const void *data, const std::size_t &size);

address: Address to write to data: Pointer to data which should be written size: Size of the data to be written

Returns: Whether or not the call was successful


template <class type_t> 
bool write(const std::uintptr_t &address, const type_t &value);

address: Address to write to value: Data to write

Returns: Whether or not the call was successful


std::unique_ptr<char[]> read(const std::uintptr_t &address, const std::size_t &size);

address: Address to read from size: Amount of data to read

Returns: A unique_ptr of the data that has been read


template <class type_t> 
std::optional<type_t> read(const std::uintptr_t &address);

address: Address to read from type_t: Type to read data as

Returns: Data read as type_t if successful, nullopt otherwise.


bool free(const std::uintptr_t &address, const std::size_t &size);

address: Address to free data at size: Size of data to free

Returns: Whether or not call was successful


bool protect(const std::uintptr_t &address, const std::size_t &size, const std::uint8_t &protection);

address: Address to change protection of size: Size of region to change protection of protection: New memory protection, you can make use of the constants in constants/protection.hpp here.

Returns: Whether or not call was successful


std::shared_ptr<std::uintptr_t> allocate(const std::size_t &size, const std::uint8_t &protection);

size: Size of memory to be allocated protection: Memory protection, you can make use of the constants in constants/protection.hpp here.

Returns: A shared_ptr to the memory allocted if successful, nullptr otherwise.

Remarks: The allocated memory will be freed as soon as the shared_ptr is destroyed.


bool allocate_at(const std::uintptr_t &address, const std::size_t &size, const std::uint8_t &protection);

address: The address to allocate memory at size: Size of memory to be allocated protection: Memory protection, you can make use of the constants in constants/protection.hpp here.

Returns: Whether or not call was successful


std::shared_ptr<std::uintptr_t> allocate_near(const std::uintptr_t &address, const std::size_t &size, const std::uint8_t &protection);```

> `address`: The address to allocate memory at
> `size`: Size of memory to be allocated
> `protection`: Memory protection, you can make use of the constants in `constants/protection.hpp` here.

> Returns: A `shared_ptr` to the memory allocted if successful, `nullptr` otherwise.
Clone this wiki locally