pub struct PtrBuffer { /* private fields */ }Expand description
A Buffer object backed by a pointer/size pair. Use this buffer type
when accessing unowned memory or arbitrary allocated memory.
Implementations§
Source§impl PtrBuffer
impl PtrBuffer
Sourcepub fn new(pointer: *const u8, size: usize) -> Self
pub fn new(pointer: *const u8, size: usize) -> Self
Create a new buffer object with a given pointer and size. Just make sure the pointer outlives the object and not the other way around.
Sourcepub fn set_pointer(&mut self, pointer: *const u8)
pub fn set_pointer(&mut self, pointer: *const u8)
Set the new pointer of this buffer.
Trait Implementations§
Source§impl Buffer for PtrBuffer
impl Buffer for PtrBuffer
Source§fn as_mut_ptr(&mut self) -> *mut u8
fn as_mut_ptr(&mut self) -> *mut u8
Get the PtrBuffer object as a mutable pointer.
Source§fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Get the PtrBuffer object as a mutable slice.
Source§fn as_ptr_range(&self) -> Range<*const u8> ⓘ
fn as_ptr_range(&self) -> Range<*const u8> ⓘ
Get a pointer range of this buffer. See slice::as_ptr_range for more details.
Source§fn as_mut_ptr_range(&mut self) -> Range<*mut u8> ⓘ
fn as_mut_ptr_range(&mut self) -> Range<*mut u8> ⓘ
Get a mutable pointer range of this buffer. See slice::as_mut_ptr_range for more details.
Source§fn validate_ptr(&self, ptr: *const u8) -> bool
fn validate_ptr(&self, ptr: *const u8) -> bool
Validate that the given pointer object is within the range of this buffer.
Source§fn ptr_to_offset(&self, ptr: *const u8) -> Result<usize, Error>
fn ptr_to_offset(&self, ptr: *const u8) -> Result<usize, Error>
Convert a pointer to an offset into the buffer. Read more
Source§fn swap(&mut self, a: usize, b: usize)
fn swap(&mut self, a: usize, b: usize)
Swap two bytes at the given offsets. This panics if the offsets are out of bounds. See
slice::swap
for more details.Source§fn try_swap(&mut self, a: usize, b: usize) -> Result<(), Error>
fn try_swap(&mut self, a: usize, b: usize) -> Result<(), Error>
Swap two bytes at the given offsets. Read more
Source§fn reverse(&mut self)
fn reverse(&mut self)
Reverse the buffer. See
slice::reverse for more details.Source§fn try_reverse(&mut self) -> Result<(), Error>
fn try_reverse(&mut self) -> Result<(), Error>
Reverse the buffer, returning an error on failure. Read more
Source§fn iter(&self) -> BufferIter<'_> ⓘ
fn iter(&self) -> BufferIter<'_> ⓘ
Return an iterator object (
BufferIter) into the buffer.Source§fn iter_mut(&mut self) -> BufferIterMut<'_> ⓘ
fn iter_mut(&mut self) -> BufferIterMut<'_> ⓘ
Return a mutable iterator object (
BufferIterMut) into the buffer.Source§fn get<I: SliceIndex<[u8]>>(&self, index: I) -> Option<&I::Output>
fn get<I: SliceIndex<[u8]>>(&self, index: I) -> Option<&I::Output>
Get the given byte or range of bytes from the buffer. See
slice::get for more details.Source§fn get_mut<I: SliceIndex<[u8]>>(&mut self, index: I) -> Option<&mut I::Output>
fn get_mut<I: SliceIndex<[u8]>>(&mut self, index: I) -> Option<&mut I::Output>
Get the given byte or range of bytes from the buffer as mutable. See
slice::get_mut for more details.Source§fn read(&self, offset: usize, size: usize) -> Result<&[u8], Error>
fn read(&self, offset: usize, size: usize) -> Result<&[u8], Error>
Read an arbitrary size amount of bytes from the given offset. Read more
Source§fn read_mut(&mut self, offset: usize, size: usize) -> Result<&mut [u8], Error>
fn read_mut(&mut self, offset: usize, size: usize) -> Result<&mut [u8], Error>
Read an arbitrary size amount of bytes from the given offset, but mutable. Read more
Source§fn read_val<T: Copy>(&self, offset: usize) -> Result<T, Error>
fn read_val<T: Copy>(&self, offset: usize) -> Result<T, Error>
Read a value of type
T from the buffer at the given offset, without requiring alignment. Read moreSource§fn read_val_array<T: Copy>(
&self,
offset: usize,
count: usize,
) -> Result<Vec<T>, Error>
fn read_val_array<T: Copy>( &self, offset: usize, count: usize, ) -> Result<Vec<T>, Error>
Read a series of values of type
T from the buffer at the given offset. Read moreSource§fn get_slice_ref<T>(&self, offset: usize, count: usize) -> Result<&[T], Error>
fn get_slice_ref<T>(&self, offset: usize, count: usize) -> Result<&[T], Error>
Get a slice reference of
T values from the buffer at the given offset. Read moreSource§fn get_mut_slice_ref<T>(
&mut self,
offset: usize,
count: usize,
) -> Result<&mut [T], Error>
fn get_mut_slice_ref<T>( &mut self, offset: usize, count: usize, ) -> Result<&mut [T], Error>
Get a mutable slice reference of
T values from the buffer at the given offset. Read moreSource§fn get_aligned_ref<T: Copy>(&self, offset: usize) -> Result<&T, Error>
fn get_aligned_ref<T: Copy>(&self, offset: usize) -> Result<&T, Error>
Get a reference to
T at the given offset, verifying alignment. Read moreSource§fn get_aligned_mut<T: Copy>(&mut self, offset: usize) -> Result<&mut T, Error>
fn get_aligned_mut<T: Copy>(&mut self, offset: usize) -> Result<&mut T, Error>
Get a mutable reference to
T at the given offset, verifying alignment. Read moreSource§fn write_val<T: Copy>(&mut self, offset: usize, data: &T) -> Result<(), Error>
fn write_val<T: Copy>(&mut self, offset: usize, data: &T) -> Result<(), Error>
Write a value of type
T to the buffer at the given offset, without requiring alignment. Read moreSource§fn start_with<B: AsRef<[u8]>>(&mut self, data: B) -> Result<(), Error>
fn start_with<B: AsRef<[u8]>>(&mut self, data: B) -> Result<(), Error>
Start the buffer object with the given byte data. Read more
Source§fn end_with<B: AsRef<[u8]>>(&mut self, data: B) -> Result<(), Error>
fn end_with<B: AsRef<[u8]>>(&mut self, data: B) -> Result<(), Error>
End the buffer object with the given byte data. Read more
Source§fn search_dynamic<'a, B: AsRef<[Option<u8>]>>(
&'a self,
data: B,
) -> Result<BufferSearchDynamicIter<'a>, Error>
fn search_dynamic<'a, B: AsRef<[Option<u8>]>>( &'a self, data: B, ) -> Result<BufferSearchDynamicIter<'a>, Error>
Return a search iterator for a dynamic byte pattern within the binary. Read more
Source§fn starts_with<B: AsRef<[u8]>>(&self, needle: B) -> bool
fn starts_with<B: AsRef<[u8]>>(&self, needle: B) -> bool
Check if this buffer starts with the byte sequence needle. See
slice::starts_with.Source§fn ends_with<B: AsRef<[u8]>>(&self, needle: B) -> bool
fn ends_with<B: AsRef<[u8]>>(&self, needle: B) -> bool
Check if this buffer ends with the byte sequence needle. See
slice::ends_with.Source§fn rotate_left(&mut self, mid: usize)
fn rotate_left(&mut self, mid: usize)
Rotate the buffer left at midpoint mid. See
slice::rotate_left.Source§fn try_rotate_left(&mut self, mid: usize) -> Result<(), Error>
fn try_rotate_left(&mut self, mid: usize) -> Result<(), Error>
Rotate the buffer left at midpoint mid. Read more
Source§fn rotate_right(&mut self, mid: usize)
fn rotate_right(&mut self, mid: usize)
Rotate the buffer right at midpoint mid. See
slice::rotate_right.Source§fn try_rotate_right(&mut self, mid: usize) -> Result<(), Error>
fn try_rotate_right(&mut self, mid: usize) -> Result<(), Error>
Rotate the buffer right at midpoint mid. Read more
Source§fn fill(&mut self, value: u8)
fn fill(&mut self, value: u8)
Fill the given buffer with the given value. See
slice::fill.Source§fn try_fill(&mut self, value: u8) -> Result<(), Error>
fn try_fill(&mut self, value: u8) -> Result<(), Error>
Fill the given buffer with the given value, returning an error on failure. Read more
Source§fn fill_with<F>(&mut self, f: F)
fn fill_with<F>(&mut self, f: F)
Fill the given buffer with the given closure f. See
slice::fill_with.Source§fn try_fill_with<F>(&mut self, f: F) -> Result<(), Error>
fn try_fill_with<F>(&mut self, f: F) -> Result<(), Error>
Fill the given buffer with the given closure f, returning an error on failure. Read more
Source§fn clone_from_data<B: AsRef<[u8]>>(&mut self, src: B)
fn clone_from_data<B: AsRef<[u8]>>(&mut self, src: B)
Source§fn copy_from_data<B: AsRef<[u8]>>(&mut self, src: B)
fn copy_from_data<B: AsRef<[u8]>>(&mut self, src: B)
Source§fn copy_within<R>(&mut self, src: R, dest: usize)where
R: RangeBounds<usize>,
fn copy_within<R>(&mut self, src: R, dest: usize)where
R: RangeBounds<usize>,
Copy from within the given buffer. See
slice::copy_within.Source§fn try_copy_within<R>(&mut self, src: R, dest: usize) -> Result<(), Error>where
R: RangeBounds<usize>,
fn try_copy_within<R>(&mut self, src: R, dest: usize) -> Result<(), Error>where
R: RangeBounds<usize>,
Copy from within the given buffer. Read more
Source§fn swap_with_data<B: AsMut<[u8]>>(&mut self, other: B)
fn swap_with_data<B: AsMut<[u8]>>(&mut self, other: B)
Source§fn is_ascii(&self) -> bool
fn is_ascii(&self) -> bool
Check if this buffer is ASCII. See
slice::is_ascii.Source§fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool
fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool
Check if this buffer is equal while ignoring case of letters. See
slice::eq_ignore_ascii_case.Source§fn make_ascii_uppercase(&mut self)
fn make_ascii_uppercase(&mut self)
Make this buffer ASCII uppercase. See
slice::make_ascii_uppercase.Source§fn make_ascii_lowercase(&mut self)
fn make_ascii_lowercase(&mut self)
Make this buffer ASCII lowercase. See
slice::make_ascii_lowercase.Source§fn sort(&mut self)
fn sort(&mut self)
Sort this buffer. See
slice::sort.Source§fn try_sort(&mut self) -> Result<(), Error>
fn try_sort(&mut self) -> Result<(), Error>
Sort this buffer, returning an error on failure. Read more
Source§fn sort_by<F>(&mut self, compare: F)
fn sort_by<F>(&mut self, compare: F)
Sort by the given closure comparing each individual byte. See
slice::sort_by.Source§fn try_sort_by<F>(&mut self, compare: F) -> Result<(), Error>
fn try_sort_by<F>(&mut self, compare: F) -> Result<(), Error>
Sort by the given closure comparing each individual byte, returning an error on failure. Read more
Source§fn sort_by_key<K, F>(&mut self, f: F)
fn sort_by_key<K, F>(&mut self, f: F)
Sorts the slice with a key extraction function. See
slice::sort_by_key.Source§fn try_sort_by_key<K, F>(&mut self, f: F) -> Result<(), Error>
fn try_sort_by_key<K, F>(&mut self, f: F) -> Result<(), Error>
Sorts the slice with a key extraction function, returning an error on failure. Read more
impl Copy for PtrBuffer
impl Eq for PtrBuffer
Source§impl IntoIterator for PtrBuffer
impl IntoIterator for PtrBuffer
Auto Trait Implementations§
impl !Send for PtrBuffer
impl !Sync for PtrBuffer
impl Freeze for PtrBuffer
impl RefUnwindSafe for PtrBuffer
impl Unpin for PtrBuffer
impl UnsafeUnpin for PtrBuffer
impl UnwindSafe for PtrBuffer
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
Mutably borrows from an owned value. Read more