SafetyHook: safetyhook::Allocator Class Reference

SafetyHook

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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
Allocator & | operator= (const Allocator &)=delete
Allocator & | operator= (Allocator &&) noexcept=delete
std::expected< Allocation, Error > | allocate (size_t size)
| Allocates memory.
std::expected< Allocation, Error > | allocate_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< Allocator > | global ()
| Returns the global Allocator.
static std::shared_ptr< Allocator > | create ()
| 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

  size | The 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_addresses | The target address.
  size | The size of the allocation.
  max_distance | The 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:

- C:/M/B/src/safetyhook-0.6.5/include/safetyhook/allocator.hpp