21 constexpr MemAddr(
const uintptr_t ptr) noexcept : _ptr{ptr} {}
28 template<
typename T>
requires (std::is_pointer_v<T> or std::is_null_pointer_v<T>)
29 MemAddr(T ptr) noexcept : _ptr{
reinterpret_cast<uintptr_t
>(ptr)} {}
61 constexpr operator uintptr_t() const noexcept {
69 constexpr operator void*()
const noexcept {
77 constexpr explicit operator bool() const noexcept {
87 return _ptr != addr._ptr;
96 return _ptr < addr._ptr;
105 return _ptr == addr._ptr;
113 constexpr bool operator==(
const uintptr_t addr)
const noexcept {
121 constexpr uintptr_t
GetPtr() const noexcept {
132 return *
reinterpret_cast<T*
>(_ptr);
141 constexpr T
CCast() const noexcept {
151 constexpr T
RCast() const noexcept {
152 return reinterpret_cast<T
>(_ptr);
161 constexpr T
UCast() const noexcept {
166 return cast.ptr = _ptr, cast.val;
175 return _ptr +
static_cast<uintptr_t
>(offset);
184 _ptr +=
static_cast<uintptr_t
>(offset);
194 uintptr_t reference = _ptr;
198 reference = *
reinterpret_cast<uintptr_t*
>(reference);
212 _ptr = *
reinterpret_cast<uintptr_t*
>(_ptr);
245 const uintptr_t skipRegister = _ptr +
static_cast<uintptr_t
>(registerOffset);
246 const int32_t relativeAddress = *
reinterpret_cast<int32_t*
>(skipRegister);
247 const uintptr_t nextInstruction = _ptr +
static_cast<uintptr_t
>(nextInstructionOffset);
248 return nextInstruction +
static_cast<uintptr_t
>(relativeAddress);
258 const uintptr_t skipRegister = _ptr +
static_cast<uintptr_t
>(registerOffset);
259 const int32_t relativeAddress = *
reinterpret_cast<int32_t*
>(skipRegister);
260 const uintptr_t nextInstruction = _ptr +
static_cast<uintptr_t
>(nextInstructionOffset);
261 _ptr = nextInstruction +
static_cast<uintptr_t
>(relativeAddress);
A wrapper class for memory addresses, providing utility functions for pointer manipulation.
MemAddr & FollowNearCallSelf(const ptrdiff_t opcodeOffset=0x1, const ptrdiff_t nextInstructionOffset=0x5)
Follows a near call to resolve the address in-place.
MemAddr ResolveRelativeAddress(const ptrdiff_t registerOffset=0x0, const ptrdiff_t nextInstructionOffset=0x4) const
Resolves a relative address.
constexpr bool operator<(const MemAddr addr) const noexcept
Less-than comparison operator.
constexpr MemAddr & OffsetSelf(const ptrdiff_t offset) noexcept
Offsets the memory address by a specified amount in-place.
constexpr MemAddr(MemAddr &&other) noexcept=default
Move constructor initializing the pointer with another MemAddr.
constexpr bool operator==(const MemAddr addr) const noexcept
Equality operator.
constexpr uintptr_t GetPtr() const noexcept
Returns the uintptr_t representation of the pointer.
constexpr T CCast() const noexcept
Casts the pointer to a specified type using C-style cast.
constexpr T RCast() const noexcept
Casts the pointer to a specified type using reinterpret_cast.
constexpr MemAddr(const uintptr_t ptr) noexcept
Constructor initializing the pointer with a uintptr_t value.
constexpr MemAddr & operator=(MemAddr &&other) noexcept=default
Move assignment operator to move another MemAddr.
constexpr MemAddr & operator=(const MemAddr &other) noexcept=default
Assignment operator to copy another MemAddr.
constexpr MemAddr() noexcept
Default constructor initializing the pointer to 0.
constexpr MemAddr Offset(const ptrdiff_t offset) const noexcept
Offsets the memory address by a specified amount.
constexpr bool operator!=(const MemAddr addr) const noexcept
Inequality operator.
constexpr bool operator==(const uintptr_t addr) const noexcept
Equality operator for comparing with uintptr_t.
constexpr T UCast() const noexcept
Casts the pointer to a specified type using a union cast.
constexpr T GetValue() const noexcept
Retrieves the value at the memory address.
MemAddr(T ptr) noexcept
Template constructor initializing the pointer with a typed pointer.
MemAddr & ResolveRelativeAddressSelf(const ptrdiff_t registerOffset=0x0, const ptrdiff_t nextInstructionOffset=0x4)
Resolves a relative address in-place.
constexpr MemAddr(const MemAddr &other) noexcept=default
Constructor initializing the pointer with a void pointer.
MemAddr FollowNearCall(const ptrdiff_t opcodeOffset=0x1, const ptrdiff_t nextInstructionOffset=0x5) const
Follows a near call to resolve the address.
constexpr MemAddr Deref(ptrdiff_t deref=1) const
Dereferences the memory address a specified number of times.
constexpr MemAddr & DerefSelf(ptrdiff_t deref=1)
Dereferences the memory address a specified number of times in-place.