From 05656b4f0b021f7904f6e73f5faa05a32e411c23 Mon Sep 17 00:00:00 2001 From: a2x <45197573+a2x@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:10:58 +1000 Subject: [PATCH] Rename `IsNull` trait to `PointerExt` This allows for more pointer extension methods to be added in the future. --- src/mem.rs | 10 +++++----- src/source2/tier1/utl_memory.rs | 3 +-- src/source2/tier1/utl_ts_hash.rs | 12 +++++++----- src/source2/tier1/utl_vector.rs | 1 - 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/mem.rs b/src/mem.rs index 14a68ff..16b5ebd 100644 --- a/src/mem.rs +++ b/src/mem.rs @@ -1,13 +1,13 @@ -use memflow::types::Pointer64; +use memflow::types::{Pointer, PrimitiveAddress}; -pub trait IsNull { +pub trait PointerExt { + /// Returns `true` if the pointer is null. fn is_null(&self) -> bool; } -impl IsNull for Pointer64 { - /// Returns `true` if the pointer is null. +impl PointerExt for Pointer { #[inline] fn is_null(&self) -> bool { - self.inner == 0 + self.inner.is_null() } } diff --git a/src/source2/tier1/utl_memory.rs b/src/source2/tier1/utl_memory.rs index d86d689..42ad463 100644 --- a/src/source2/tier1/utl_memory.rs +++ b/src/source2/tier1/utl_memory.rs @@ -19,7 +19,6 @@ impl UtlMemory { /// Returns the element at the specified index. pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result { - // Check if the index is out of bounds. if idx >= self.count() as usize { return Err(Error::Other("index out of bounds")); } @@ -27,7 +26,7 @@ impl UtlMemory { self.mem.at(idx as _).read(process).map_err(Into::into) } - /// Returns `true` if the memory is externally allocated. + /// Returns `true` if the memory was externally allocated. #[inline] pub fn is_externally_allocated(&self) -> bool { self.grow_size < 0 diff --git a/src/source2/tier1/utl_ts_hash.rs b/src/source2/tier1/utl_ts_hash.rs index 8b454a5..79e3f17 100644 --- a/src/source2/tier1/utl_ts_hash.rs +++ b/src/source2/tier1/utl_ts_hash.rs @@ -3,7 +3,7 @@ use memflow::prelude::v1::*; use super::UtlMemoryPoolBase; use crate::error::Result; -use crate::mem::IsNull; +use crate::mem::PointerExt; #[repr(C)] pub struct HashAllocatedBlob { @@ -17,7 +17,7 @@ unsafe impl Pod for HashAllocatedBlob {} #[repr(C)] pub struct HashBucket { - pad_0000: [u8; 0x18], // 0x0000, + pad_0000: [u8; 0x18], // 0x0000 pub first: Pointer64>, // 0x0018 pub first_uncommitted: Pointer64>, // 0x0020 } @@ -40,7 +40,11 @@ pub struct UtlTsHash { pad_2881: [u8; 0xF], // 0x2881 } -impl UtlTsHash { +impl UtlTsHash +where + D: Pod + PointerExt, + K: Pod, +{ /// Returns the number of allocated blocks. #[inline] pub fn blocks_alloc(&self) -> i32 { @@ -77,7 +81,6 @@ impl UtlTsHash { unallocated_list.push(element.data); } - // Check if we have too many elements. if unallocated_list.len() >= blocks_alloc { break; } @@ -96,7 +99,6 @@ impl UtlTsHash { allocated_list.push(blob.data); } - // Check if we have too many elements. if allocated_list.len() >= peak_alloc { break; } diff --git a/src/source2/tier1/utl_vector.rs b/src/source2/tier1/utl_vector.rs index eeba806..cad45b3 100644 --- a/src/source2/tier1/utl_vector.rs +++ b/src/source2/tier1/utl_vector.rs @@ -18,7 +18,6 @@ impl UtlVector { /// Returns the element at the specified index. pub fn element(&self, process: &mut IntoProcessInstanceArcBox<'_>, idx: usize) -> Result { - // Check if the index is out of bounds. if idx >= self.count() as usize { return Err(Error::Other("index out of bounds")); }