#[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§
source§impl<U: PrimitiveAddress, T: ?Sized> Pointer<U, T>
impl<U: PrimitiveAddress, T: ?Sized> Pointer<U, T>
sourcepub fn null() -> Self
pub fn null() -> Self
Returns a pointer64 with a value of zero.
Examples
use memflow::types::Pointer64;
println!("pointer: {}", Pointer64::<()>::null());
sourcepub fn is_null(self) -> bool
pub fn is_null(self) -> bool
Returns true
if the pointer64 is null.
Examples
use memflow::types::Pointer32;
let ptr = Pointer32::<()>::from(0x1000u32);
assert!(!ptr.is_null());
sourcepub fn non_null(self) -> Option<Pointer<U, T>>
pub fn non_null(self) -> Option<Pointer<U, T>>
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)));
sourcepub fn to_umem(self) -> umem
pub fn to_umem(self) -> umem
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);
pub fn address(&self) -> Address
source§impl<U: PrimitiveAddress, T: Sized> Pointer<U, T>
impl<U: PrimitiveAddress, T: Sized> Pointer<U, T>
sourcepub fn offset(self, count: imem) -> Self
pub fn offset(self, count: imem) -> Self
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));
sourcepub fn offset_from(self, origin: Self) -> imem
pub fn offset_from(self, origin: Self) -> imem
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);
sourcepub fn add(self, count: umem) -> Self
pub fn add(self, count: umem) -> Self
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));
sourcepub fn sub(self, count: umem) -> Self
pub fn sub(self, count: umem) -> Self
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));
source§impl<U: PrimitiveAddress, T: Pod + ?Sized> Pointer<U, T>
impl<U: PrimitiveAddress, T: Pod + ?Sized> Pointer<U, T>
Implement special phys/virt read/write for Pod types
pub fn read_into<M: MemoryView>( self, mem: &mut M, out: &mut T ) -> PartialResult<()>
source§impl<U: PrimitiveAddress, T: Pod + Sized> Pointer<U, T>
impl<U: PrimitiveAddress, T: Pod + Sized> Pointer<U, T>
pub fn read<M: MemoryView>(self, mem: &mut M) -> PartialResult<T>
pub fn write<M: MemoryView>(self, mem: &mut M, data: &T) -> PartialResult<()>
source§impl<U: PrimitiveAddress> Pointer<U, ReprCString>
impl<U: PrimitiveAddress> Pointer<U, ReprCString>
Implement special phys/virt read/write for CReprStr
pub fn read_string<M: MemoryView>( self, mem: &mut M ) -> PartialResult<ReprCString>
Trait Implementations§
source§impl<U: PrimitiveAddress, T: ?Sized> From<Pointer<U, T>> for Address
impl<U: PrimitiveAddress, T: ?Sized> From<Pointer<U, T>> for Address
Converts any Pointer
into an Address.
source§impl<U: PrimitiveAddress, T: ?Sized> From<Pointer<U, T>> for PhysicalAddress
impl<U: PrimitiveAddress, T: ?Sized> From<Pointer<U, T>> for PhysicalAddress
source§impl<U: PrimitiveAddress, T: ?Sized> Ord for Pointer<U, T>
impl<U: PrimitiveAddress, T: ?Sized> Ord for Pointer<U, T>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<U: PrimitiveAddress, T: ?Sized> PartialEq for Pointer<U, T>
impl<U: PrimitiveAddress, T: ?Sized> PartialEq for Pointer<U, T>
source§impl<U: PrimitiveAddress, T: ?Sized> PartialOrd for Pointer<U, T>
impl<U: PrimitiveAddress, T: ?Sized> PartialOrd for Pointer<U, T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<U: PrimitiveAddress, T: ?Sized> Copy for Pointer<U, T>
impl<U: PrimitiveAddress, T: ?Sized> Eq for Pointer<U, T>
impl<U: Pod, T: ?Sized + 'static> Pod for Pointer<U, T>
Auto Trait Implementations§
impl<U, T: ?Sized> RefUnwindSafe for Pointer<U, T>where
U: RefUnwindSafe,
impl<U, T: ?Sized> Send for Pointer<U, T>where
U: Send,
impl<U, T: ?Sized> Sync for Pointer<U, T>where
U: Sync,
impl<U, T: ?Sized> Unpin for Pointer<U, T>where
U: Unpin,
impl<U, T: ?Sized> UnwindSafe for Pointer<U, T>where
U: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<'a, T> BorrowOwned<'a> for Twhere
T: 'a + Clone,
impl<'a, T> BorrowOwned<'a> for Twhere
T: 'a + Clone,
fn r_borrow( this: &'a <T as BorrowOwned<'a>>::ROwned ) -> <T as BorrowOwned<'a>>::RBorrowed
fn r_to_owned( this: <T as BorrowOwned<'a>>::RBorrowed ) -> <T as BorrowOwned<'a>>::ROwned
fn deref_borrowed(this: &<T as BorrowOwned<'a>>::RBorrowed) -> &T
fn deref_owned(this: &<T as BorrowOwned<'a>>::ROwned) -> &T
fn from_cow_borrow(this: &'a T) -> <T as BorrowOwned<'a>>::RBorrowed
fn from_cow_owned(this: <T as ToOwned>::Owned) -> <T as BorrowOwned<'a>>::ROwned
fn into_cow_borrow(this: <T as BorrowOwned<'a>>::RBorrowed) -> &'a T
fn into_cow_owned(this: <T as BorrowOwned<'a>>::ROwned) -> <T as ToOwned>::Owned
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> GetWithMetadata for T
impl<T> GetWithMetadata for T
§type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
WithMetadata_<Self, Self>
source§impl<T> PodMethods for T
impl<T> PodMethods for T
source§fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
source§fn as_data_view(&self) -> &DataView
fn as_data_view(&self) -> &DataView
source§fn as_data_view_mut(&mut self) -> &mut DataView
fn as_data_view_mut(&mut self) -> &mut DataView
§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read more§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read more§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read more§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read more§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read more§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read more§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
§fn piped_ref<'a, F, U>(&'a self, f: F) -> U
fn piped_ref<'a, F, U>(&'a self, f: F) -> U
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read more§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more