22 MemAddr(uintptr_t ptr) noexcept : _ptr{ptr} {}
29 template<
typename T>
requires (std::is_pointer_v<T> or std::is_null_pointer_v<T>)
30 MemAddr(T ptr) noexcept : _ptr{
reinterpret_cast<uintptr_t
>(ptr)} {}
36 operator uintptr_t() const noexcept {
44 operator void*()
const noexcept {
45 return reinterpret_cast<void*
>(_ptr);
52 explicit operator bool() const noexcept {
62 return _ptr != addr._ptr;
71 return _ptr == addr._ptr;
98 return *
reinterpret_cast<T*
>(_ptr);
118 return reinterpret_cast<T
>(_ptr);
132 return cast.m_ptr = _ptr, cast.cptr;
141 return _ptr +
static_cast<uintptr_t
>(offset);
150 _ptr +=
static_cast<uintptr_t
>(offset);
160 uintptr_t reference = _ptr;
164 reference = *
reinterpret_cast<uintptr_t*
>(reference);
178 _ptr = *
reinterpret_cast<uintptr_t*
>(_ptr);
211 const uintptr_t skipRegister = _ptr +
static_cast<uintptr_t
>(registerOffset);
212 const int32_t relativeAddress = *
reinterpret_cast<int32_t*
>(skipRegister);
213 const uintptr_t nextInstruction = _ptr +
static_cast<uintptr_t
>(nextInstructionOffset);
214 return nextInstruction + (uintptr_t) relativeAddress;
224 const uintptr_t skipRegister = _ptr +
static_cast<uintptr_t
>(registerOffset);
225 const int32_t relativeAddress = *
reinterpret_cast<int32_t*
>(skipRegister);
226 const uintptr_t nextInstruction = _ptr +
static_cast<uintptr_t
>(nextInstructionOffset);
227 _ptr = nextInstruction +
static_cast<uintptr_t
>(relativeAddress);
A wrapper class for memory addresses, providing utility functions for pointer manipulation.
MemAddr & FollowNearCallSelf(ptrdiff_t opcodeOffset=0x1, ptrdiff_t nextInstructionOffset=0x5)
Follows a near call to resolve the address in-place.
requires(std::is_pointer_v< T > or std::is_null_pointer_v< T >) MemAddr(T ptr) noexcept
Template constructor initializing the pointer with a typed pointer.
MemAddr Offset(ptrdiff_t offset) const noexcept
Offsets the memory address by a specified amount.
MemAddr() noexcept
Default constructor initializing the pointer to 0.
MemAddr(uintptr_t ptr) noexcept
Constructor initializing the pointer with a uintptr_t value.
MemAddr ResolveRelativeAddress(ptrdiff_t registerOffset=0x0, ptrdiff_t nextInstructionOffset=0x4) const
Resolves a relative address.
MemAddr & ResolveRelativeAddressSelf(ptrdiff_t registerOffset=0x0, ptrdiff_t nextInstructionOffset=0x4)
Resolves a relative address in-place.
MemAddr & OffsetSelf(ptrdiff_t offset) noexcept
Offsets the memory address by a specified amount in-place.
T RCast() const noexcept
Casts the pointer to a specified type using reinterpret_cast.
MemAddr & DerefSelf(ptrdiff_t deref=1)
Dereferences the memory address a specified number of times in-place.
T UCast() const noexcept
Casts the pointer to a specified type using a union cast.
bool operator==(const MemAddr &addr) const noexcept
Equality operator.
bool operator==(const uintptr_t &addr) const noexcept
Equality operator for comparing with uintptr_t.
MemAddr FollowNearCall(ptrdiff_t opcodeOffset=0x1, ptrdiff_t nextInstructionOffset=0x5) const
Follows a near call to resolve the address.
MemAddr Deref(ptrdiff_t deref=1) const
Dereferences the memory address a specified number of times.
uintptr_t GetPtr() const noexcept
Returns the uintptr_t representation of the pointer.
T CCast() const noexcept
Casts the pointer to a specified type using C-style cast.
bool operator!=(const MemAddr &addr) const noexcept
Inequality operator.
T GetValue() const noexcept
Retrieves the value at the memory address.