SafetyHook
Loading...
Searching...
No Matches
safetyhook::Allocator Class Referencefinal

Allocates memory near target addresses. More...

#include <allocator.hpp>

Inheritance diagram for safetyhook::Allocator:

Public Types

enum class  Error : uint8_t { BAD_VIRTUAL_ALLOC , NO_MEMORY_IN_RANGE }
 The error type returned by the allocate functions. More...
 

Public Member Functions

 Allocator (const Allocator &)=delete
 
 Allocator (Allocator &&) noexcept=delete
 
Allocatoroperator= (const Allocator &)=delete
 
Allocatoroperator= (Allocator &&) noexcept=delete
 
std::expected< Allocation, Errorallocate (size_t size)
 Allocates memory.
 
std::expected< Allocation, Errorallocate_near (const std::vector< uint8_t * > &desired_addresses, size_t size, size_t max_distance=0x7FFF 'FFFF)
 Allocates memory near a target address.
 

Static Public Member Functions

static std::shared_ptr< Allocatorglobal ()
 Returns the global Allocator.
 
static std::shared_ptr< Allocatorcreate ()
 Creates a new Allocator.
 

Protected Member Functions

void free (uint8_t *address, size_t size)
 

Protected Attributes

friend Allocation
 

Detailed Description

Allocates memory near target addresses.

Member Enumeration Documentation

◆ Error

enum class safetyhook::Allocator::Error : uint8_t
strong

The error type returned by the allocate functions.

Enumerator
BAD_VIRTUAL_ALLOC 

VirtualAlloc failed.

NO_MEMORY_IN_RANGE 

No memory in range.

Member Function Documentation

◆ allocate()

std::expected< Allocation, Error > safetyhook::Allocator::allocate ( size_t size)
nodiscard

Allocates memory.

Parameters
sizeThe size of the allocation.
Returns
The Allocation or an Allocator::Error if the allocation failed.

◆ allocate_near()

std::expected< Allocation, Error > safetyhook::Allocator::allocate_near ( const std::vector< uint8_t * > & desired_addresses,
size_t size,
size_t max_distance = 0x7FFF 'FFFF )
nodiscard

Allocates memory near a target address.

Parameters
desired_addressesThe target address.
sizeThe size of the allocation.
max_distanceThe maximum distance from the target address.
Returns
The Allocation or an Allocator::Error if the allocation failed.

◆ create()

static std::shared_ptr< Allocator > safetyhook::Allocator::create ( )
staticnodiscard

Creates a new Allocator.

Returns
The new Allocator.

◆ global()

static std::shared_ptr< Allocator > safetyhook::Allocator::global ( )
staticnodiscard

Returns the global Allocator.

Returns
The global Allocator.

The documentation for this class was generated from the following file: