#[repr(transparent)]
pub struct Pointer<U: Sized, T: ?Sized = ()> { pub inner: U, /* private fields */ }
Expand description

This type can be used in structs that are being read from the target memory. It holds a phantom type that can be used to describe the proper type of the pointer and to read it in a more convenient way.

This module is a direct adaption of CasualX’s great IntPtr crate.

Generally the generic Type should implement the Pod trait to be read into easily. See here for more information on the Pod trait.

Examples

use memflow::types::Pointer64;
use memflow::mem::MemoryView;
use memflow::dataview::Pod;

#[repr(C)]
#[derive(Clone, Debug, Pod)]
struct Foo {
    pub some_value: i64,
}

#[repr(C)]
#[derive(Clone, Debug, Pod)]
struct Bar {
    pub foo_ptr: Pointer64<Foo>,
}

fn read_foo_bar(mem: &mut impl MemoryView) {
    let bar: Bar = mem.read(0x1234.into()).unwrap();
    let foo = bar.foo_ptr.read(mem).unwrap();
    println!("value: {}", foo.some_value);
}
use memflow::types::Pointer64;
use memflow::mem::MemoryView;
use memflow::dataview::Pod;

#[repr(C)]
#[derive(Clone, Debug, Pod)]
struct Foo {
    pub some_value: i64,
}

#[repr(C)]
#[derive(Clone, Debug, Pod)]
struct Bar {
    pub foo_ptr: Pointer64<Foo>,
}

fn read_foo_bar(mem: &mut impl MemoryView) {
    let bar: Bar = mem.read(0x1234.into()).unwrap();
    let foo = mem.read_ptr(bar.foo_ptr).unwrap();
    println!("value: {}", foo.some_value);
}

Fields

inner: U

Implementations

Returns a pointer64 with a value of zero.

Examples
use memflow::types::Pointer64;

println!("pointer: {}", Pointer64::<()>::null());

Returns true if the pointer64 is null.

Examples
use memflow::types::Pointer32;

let ptr = Pointer32::<()>::from(0x1000u32);
assert!(!ptr.is_null());

Converts the pointer64 to an Option that is None when it is null

Examples
use memflow::types::Pointer64;

assert_eq!(Pointer64::<()>::null().non_null(), None);
assert_eq!(Pointer64::<()>::from(0x1000u64).non_null(), Some(Pointer64::from(0x1000u64)));

Converts the pointer into a raw umem value.

Examples
use memflow::types::{Pointer64, umem};

let ptr = Pointer64::<()>::from(0x1000u64);
let ptr_umem: umem = ptr.to_umem();
assert_eq!(ptr_umem, 0x1000);

Calculates the offset from a pointer64

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

Panics

This function panics if T is a Zero-Sized Type (“ZST”). This function also panics when offset * size_of::<T>() causes overflow of a signed 64-bit integer.

Examples:
use memflow::types::Pointer64;

let ptr = Pointer64::<u16>::from(0x1000u64);

println!("{:?}", ptr.offset(3));

Calculates the distance between two pointers. The returned value is in units of T: the distance in bytes is divided by mem::size_of::<T>().

This function is the inverse of offset.

Panics

This function panics if T is a Zero-Sized Type (“ZST”).

Examples:
use memflow::types::Pointer64;

let ptr1 = Pointer64::<u16>::from(0x1000u64);
let ptr2 = Pointer64::<u16>::from(0x1008u64);

assert_eq!(ptr2.offset_from(ptr1), 4);
assert_eq!(ptr1.offset_from(ptr2), -4);

Calculates the offset from a pointer (convenience for .offset(count as i64)).

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

Panics

This function panics if T is a Zero-Sized Type (“ZST”).

Examples

Basic usage:

use memflow::types::Pointer64;

let ptr = Pointer64::<u16>::from(0x1000u64);

println!("{:?}", ptr.add(3));

Calculates the offset from a pointer (convenience for .offset((count as isize).wrapping_neg())).

count is in units of T; e.g., a count of 3 represents a pointer offset of 3 * size_of::<T>() bytes.

Panics

This function panics if T is a Zero-Sized Type (“ZST”).

Examples

Basic usage:

use memflow::types::Pointer64;

let ptr = Pointer64::<u16>::from(0x1000u64);

println!("{:?}", ptr.sub(3));

Implement special phys/virt read/write for Pod types

Implement special phys/virt read/write for CReprStr

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the conversion.

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Converts any Pointer into an Address.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Formats the value using the given formatter.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns a zero-initialized instance of the type.

Returns the object’s memory as a byte slice.

Returns the object’s memory as a mutable byte slice.

Returns a data view into the object’s memory.

Returns a mutable data view into the object’s memory.

Safely transmutes to another type. Read more

Safely transmutes references to another type. Read more

Safely transmutes references to another type. Read more

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Formats the value using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

The owned type, stored in RCow::Owned

The borrowed type, stored in RCow::Borrowed

Returns the argument unchanged.

This is always WithMetadata_<Self, Self>

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Gets a reference to a field, determined by offset. Read more

Gets a muatble reference to a field, determined by offset. Read more

Gets a const pointer to a field, the field is determined by offset. Read more

Gets a mutable pointer to a field, determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

Compares the address of self with the address of other. Read more

Emulates the pipeline operator, allowing method syntax in more places. Read more

The same as piped except that the function takes &Self Useful for functions that take &Self instead of Self. Read more

The same as piped, except that the function takes &mut Self. Useful for functions that take &mut Self instead of Self. Read more

Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more

Observes the value of self, passing it along unmodified. Useful in long method chains. Read more

Performs a conversion with Into. using the turbofish .into_::<_>() syntax. Read more

Performs a reference to reference conversion with AsRef, using the turbofish .as_ref_::<_>() syntax. Read more

Performs a mutable reference to mutable reference conversion with AsMut, using the turbofish .as_mut_::<_>() syntax. Read more

Drops self using method notation. Alternative to std::mem::drop. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

Transmutes the element type of this pointer.. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

This is always Self.

Converts a value back to the original type.

Converts a reference back to the original type.

Converts a mutable reference back to the original type.

Converts a box back to the original type.

Converts an Arc back to the original type. Read more

Converts an Rc back to the original type. Read more

Converts a value back to the original type.

Converts a reference back to the original type.

Converts a mutable reference back to the original type.

Converts a box back to the original type.

Converts an Arc back to the original type.

Converts an Rc back to the original type.