ReXGlue SDK
Loading...
Searching...
No Matches
rex::kernel::MemoryView Class Reference

#include <rex/kernel/memory_view.h>

Public Member Functions

 MemoryView (const GuestAddressSpace &memory)
u8 * GetVirtualMembase () const
template<typename T = u8*>
T TranslateVirtual (u32 address) const
template<typename T = u8*>
T TryTranslateVirtual (u32 address, u32 required=kMemoryProtectRead) const
u32 HostToGuestVirtual (const void *host_address) const
template<typename T>
requires (detail::GuestScalar<T>)
T Load (u32 address) const
template<typename T>
requires (detail::GuestScalar<T>)
void Store (u32 address, T value) const
template<typename T>
requires (detail::GuestScalar<T>)
std::optional< T > TryLoad (u32 address) const
template<typename T>
requires (detail::GuestScalar<T>)
bool TryStore (u32 address, T value) const
std::string_view GetCString (u32 address) const
std::optional< std::string_view > TryGetCString (u32 address, size_t max_length=std::string_view::npos) const

Detailed Description

Translates between guest virtual addresses and host addresses with the same results as GuestAddressSpace. Valid while the GuestAddressSpace it was built from exists.

Member Function Documentation

◆ GetCString()

std::string_view rex::kernel::MemoryView::GetCString ( u32 address) const
inline

Reads a null terminated string from guest memory without checking the address.

Parameters
addressThe guest virtual address, 0 for an empty string.
Returns
The bytes before the terminator, a view into guest memory.

◆ HostToGuestVirtual()

u32 rex::kernel::MemoryView::HostToGuestVirtual ( const void * host_address) const
inline

Translates a host address inside the guest virtual address space to a guest virtual address.

◆ Load()

template<typename T>
requires (detail::GuestScalar<T>)
T rex::kernel::MemoryView::Load ( u32 address) const
inline

Reads a big endian value from guest memory without checking the address.

Parameters
addressThe guest virtual address, any alignment.
Returns
The value in native byte order.

◆ Store()

template<typename T>
requires (detail::GuestScalar<T>)
void rex::kernel::MemoryView::Store ( u32 address,
T value ) const
inline

Writes a value to guest memory in big endian order without checking the address.

Parameters
addressThe guest virtual address, any alignment.
valueThe value in native byte order.

◆ TryGetCString()

std::optional< std::string_view > rex::kernel::MemoryView::TryGetCString ( u32 address,
size_t max_length = std::string_view::npos ) const
inline

Reads a null terminated string from guest memory only as far as the title could read it.

Parameters
max_lengthThe most bytes to read, no limit by default.
Returns
A view into guest memory, cut short at max_length or at unreadable memory. No value when the address is 0 or its first byte is unreadable.

◆ TryLoad()

template<typename T>
requires (detail::GuestScalar<T>)
std::optional< T > rex::kernel::MemoryView::TryLoad ( u32 address) const
inline

Reads a big endian value from guest memory only when the title could read every byte.

Parameters
addressThe guest virtual address, any alignment.
Returns
The value in native byte order, nothing when the address is 0, wraps the address space, or a byte is in no heap or on an unreadable page.

◆ TryStore()

template<typename T>
requires (detail::GuestScalar<T>)
bool rex::kernel::MemoryView::TryStore ( u32 address,
T value ) const
inline

Writes a big endian value only when the title could write every byte. Store ignores the page protection.

Parameters
addressThe guest virtual address, any alignment.
valueThe value in native byte order.
Returns
True when the value was written, false when the address is 0, wraps the address space, or a byte is in no heap or on a page that is not writable.

◆ TryTranslateVirtual()

template<typename T = u8*>
T rex::kernel::MemoryView::TryTranslateVirtual ( u32 address,
u32 required = kMemoryProtectRead ) const
inline

Translates a guest virtual address to a host address only when the title could access it, as GuestAddressSpace does.

Parameters
requiredThe kMemoryProtect bits the page must grant, the read bit by default.
Returns
The host address, null when the address is 0, misaligned, in no heap, or on a page that lacks a required bit.

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