PtrBuffer

Struct PtrBuffer 

Source
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

Source

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.

Source

pub fn set_pointer(&mut self, pointer: *const u8)

Set the new pointer of this buffer.

Source

pub fn set_size(&mut self, size: usize)

Set the new size of this buffer.

Source

pub fn sub_buffer(&self, offset: usize, size: usize) -> Result<Self, Error>

Create a new PtrBuffer object within the bounds of the current buffer.

Source

pub fn split_at(&self, mid: usize) -> Result<(Self, Self), Error>

Split this buffer into two separate buffers at the given splitpoint mid.

Returns an Error::OutOfBounds error if this split goes out of bounds of the buffer.

Trait Implementations§

Source§

impl AsMut<[u8]> for PtrBuffer

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<[u8]> for PtrBuffer

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Buffer for PtrBuffer

Source§

fn len(&self) -> usize

Get the length of this PtrBuffer object.

Source§

fn as_ptr(&self) -> *const u8

Get the PtrBuffer object as a pointer.

Source§

fn as_mut_ptr(&mut self) -> *mut u8

Get the PtrBuffer object as a mutable pointer.

Source§

fn as_slice(&self) -> &[u8]

Get the PtrBuffer object as a slice.

Source§

fn as_mut_slice(&mut self) -> &mut [u8]

Get the PtrBuffer object as a mutable slice.

Source§

fn eob(&self) -> *const u8

Get a pointer to the end of the buffer. Read more
Source§

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>

Get a mutable pointer range of this buffer. See slice::as_mut_ptr_range for more details.
Source§

fn is_empty(&self) -> bool

Check whether or not this buffer is empty.
Source§

fn validate_ptr(&self, ptr: *const u8) -> bool

Validate that the given pointer object is within the range of this buffer.
Source§

fn offset_to_ptr(&self, offset: usize) -> Result<*const u8, Error>

Convert an offset to a u8 pointer. Read more
Source§

fn offset_to_mut_ptr(&mut self, offset: usize) -> Result<*mut u8, Error>

Convert an offset to a mutable u8 pointer. Read more
Source§

fn ptr_to_offset(&self, ptr: *const u8) -> Result<usize, Error>

Convert a pointer to an offset into the buffer. Read more
Source§

fn ref_to_offset<T>(&self, data: &T) -> Result<usize, Error>

Convert a given reference to an object into an offset into the buffer. Read more
Source§

fn slice_ref_to_offset<T>(&self, data: &[T]) -> Result<usize, Error>

Convert a given slice reference to an offset into the buffer. Read more
Source§

fn to_vec(&self) -> Vec<u8>

Convert this buffer to a u8 Vec object.
Source§

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 reverse(&mut self)

Reverse the buffer. See slice::reverse for more details.
Source§

fn iter(&self) -> BufferIter<'_>

Return an iterator object (BufferIter) into the buffer.
Source§

fn iter_mut(&mut self) -> BufferIterMut<'_>

Return a mutable iterator object (BufferIterMut) into the buffer.
Source§

fn save<P: AsRef<Path>>(&self, filename: P) -> Result<(), Error>

Save this buffer to disk.
Source§

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>

Get the given byte or range of bytes from the buffer as mutable. See slice::get_mut for more details.
Source§

fn get_ref<T: Castable>(&self, offset: usize) -> Result<&T, Error>

Get a reference to a given object within the buffer. Typically the main interface by which objects are retrieved. Read more
Source§

unsafe fn get_ref_unaligned<T>(&self, offset: usize) -> Result<&T, Error>

Get a reference to a given object within the buffer, but in an unaligned way. Read more
Source§

unsafe fn force_get_ref<T: Castable>(&self, offset: usize) -> Result<&T, Error>

Get a reference regardless of potential alignment issues. Read more
Source§

fn get_mut_ref<T: Castable>(&mut self, offset: usize) -> Result<&mut T, Error>

Get a mutable reference to a given object within the buffer. See Buffer::get_ref.
Source§

unsafe fn get_mut_ref_unaligned<T>( &mut self, offset: usize, ) -> Result<&mut T, Error>

Get a mutable reference to a given object within the buffer, but in an unaligned way. Read more
Source§

unsafe fn force_get_mut_ref<T: Castable>( &mut self, offset: usize, ) -> Result<&mut T, Error>

Get a mutable reference regardless of potential alignment issues. Read more
Source§

fn make_mut_ref<T: Castable>(&mut self, data: &T) -> Result<&mut T, Error>

Convert a given reference to a mutable reference within the buffer. Read more
Source§

unsafe fn make_mut_ref_unaligned<T>( &mut self, data: &T, ) -> Result<&mut T, Error>

Convert a given reference to a mutable reference without alignment guarantees. Read more
Source§

unsafe fn force_make_mut_ref<T: Castable>( &mut self, data: &T, ) -> Result<&mut T, Error>

Convert an object to a mutable reference regardless of potential alignment issues. Read more
Source§

fn get_slice_ref<T: Castable>( &self, offset: usize, size: usize, ) -> Result<&[T], Error>

Gets a slice reference of type T at the given offset with the given size. Read more
Source§

unsafe fn get_slice_ref_unaligned<T>( &self, offset: usize, size: usize, ) -> Result<&[T], Error>

Gets a slice ref of type T at the given offset regardless of potential alignment issues. Read more
Source§

unsafe fn force_get_slice_ref<T: Castable>( &self, offset: usize, size: usize, ) -> Result<&[T], Error>

Get a slice reference regardless of potential alignment issues. Read more
Source§

fn get_mut_slice_ref<T: Castable>( &mut self, offset: usize, size: usize, ) -> Result<&mut [T], Error>

Gets a mutable slice reference of type T at the given offset with the given size. See Buffer::get_slice_ref.
Source§

unsafe fn get_mut_slice_ref_unaligned<T>( &mut self, offset: usize, size: usize, ) -> Result<&mut [T], Error>

Gets a mutable slice reference of type T at the given offset with the given size, but without alignment checking. See Buffer::get_slice_ref_unaligned.
Source§

unsafe fn force_get_mut_slice_ref<T: Castable>( &mut self, offset: usize, size: usize, ) -> Result<&mut [T], Error>

Get a mutable slice reference regardless of potential alignment issues. Read more
Source§

fn make_mut_slice_ref<T: Castable>( &mut self, data: &[T], ) -> Result<&mut [T], Error>

Convert a given slice reference to a mutable slice reference within the buffer. Read more
Source§

unsafe fn make_mut_slice_ref_unaligned<T>( &mut self, data: &[T], ) -> Result<&mut [T], Error>

Convert a given slice reference to a mutable slice reference without alignment guarantees. Read more
Source§

unsafe fn force_make_mut_slice_ref<T: Castable>( &mut self, data: &[T], ) -> Result<&mut [T], Error>

Convert an object to a mutable reference regardless of potential alignment issues. Read more
Source§

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>

Read an arbitrary size amount of bytes from the given offset, but mutable. Read more
Source§

fn write<B: AsRef<[u8]>>(&mut self, offset: usize, data: B) -> Result<(), Error>

Write an arbitrary u8 slice to the given offset. Read more
Source§

fn write_ref<T: Castable>( &mut self, offset: usize, data: &T, ) -> Result<(), Error>

Write a given object of type T to the given buffer at the given offset. Read more
Source§

fn write_slice_ref<T: Castable>( &mut self, offset: usize, data: &[T], ) -> Result<(), Error>

Write a given slice object of type T to the given buffer at the given offset. Read more
Source§

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 start_with_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>

Start the buffer with the given reference data. Read more
Source§

fn start_with_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>

Start the buffer with the given slice reference data. Read more
Source§

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 end_with_ref<T: Castable>(&mut self, data: &T) -> Result<(), Error>

End the buffer with the given reference data. Read more
Source§

fn end_with_slice_ref<T: Castable>(&mut self, data: &[T]) -> Result<(), Error>

End the buffer with the given slice reference data. Read more
Source§

fn search<B: AsRef<[u8]>>(&self, data: B) -> Result<BufferSearchIter, Error>

Search for the given u8 slice data within the given buffer. Read more
Source§

fn search_ref<T: Castable>(&self, data: &T) -> Result<BufferSearchIter, Error>

Search for the following reference of type T. This converts the object into a u8 slice. See Buffer::search.
Source§

fn search_slice_ref<T: Castable>( &self, data: &[T], ) -> Result<BufferSearchIter, Error>

Search for the following slice reference of type T. This converts the slice into a u8 slice. See Buffer::search.
Source§

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 contains<B: AsRef<[u8]>>(&self, data: B) -> bool

Check if this buffer contains the following u8 slice sequence.
Source§

fn contains_ref<T: Castable>(&self, data: &T) -> Result<bool, Error>

Check if this buffer contains the following object of type T.
Source§

fn contains_slice_ref<T: Castable>(&self, data: &[T]) -> Result<bool, Error>

Check if this buffer contains the following slice of type T.
Source§

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

Check if this buffer ends with the byte sequence needle. See slice::ends_with.
Source§

fn rotate_left(&mut self, mid: usize)

Rotate the buffer left at midpoint mid. See slice::rotate_left.
Source§

fn rotate_right(&mut self, mid: usize)

Rotate the buffer right at midpoint mid. See slice::rotate_right.
Source§

fn fill(&mut self, value: u8)

Fill the given buffer with the given value. See slice::fill.
Source§

fn fill_with<F>(&mut self, f: F)
where F: FnMut() -> u8,

Fill the given buffer with the given closure f. See slice::fill_with.
Source§

fn clone_from_data<B: AsRef<[u8]>>(&mut self, src: B)

Clone the given u8 slice data src into the given buffer.
Source§

fn copy_from_data<B: AsRef<[u8]>>(&mut self, src: B)

Copy the given u8 slice data src into the given buffer.
Source§

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 swap_with_data<B: AsMut<[u8]>>(&mut self, other: B)

Swap the data in this buffer with the given u8 slice reference.
Source§

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

Check if this buffer is equal while ignoring case of letters. See slice::eq_ignore_ascii_case.
Source§

fn make_ascii_uppercase(&mut self)

Make this buffer ASCII uppercase. See slice::make_ascii_uppercase.
Source§

fn make_ascii_lowercase(&mut self)

Make this buffer ASCII lowercase. See slice::make_ascii_lowercase.
Source§

fn sort(&mut self)

Sort this buffer. See slice::sort.
Source§

fn sort_by<F>(&mut self, compare: F)
where F: FnMut(&u8, &u8) -> Ordering,

Sort by the given closure comparing each individual byte. See slice::sort_by.
Source§

fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(&u8) -> K, K: Ord,

Sorts the slice with a key extraction function. See slice::sort_by_key.
Source§

fn repeat(&self, n: usize) -> Vec<u8>

Creates a new Buffer object by repeating the current buffer n times. See slice::repeat.
Source§

impl Clone for PtrBuffer

Source§

fn clone(&self) -> PtrBuffer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PtrBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for PtrBuffer

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher,

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

impl<Idx: SliceIndex<[u8]>> Index<Idx> for PtrBuffer

Source§

type Output = <Idx as SliceIndex<[u8]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: Idx) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<Idx: SliceIndex<[u8]>> IndexMut<Idx> for PtrBuffer

Source§

fn index_mut(&mut self, index: Idx) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IntoIterator for PtrBuffer

Source§

type Item = u8

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<PtrBuffer as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq<[u8]> for PtrBuffer

Source§

fn eq(&self, other: &[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> PartialEq<[u8; N]> for PtrBuffer

Source§

fn eq(&self, other: &[u8; N]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Buffer> PartialEq<T> for PtrBuffer

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Vec<u8>> for PtrBuffer

Source§

fn eq(&self, other: &Vec<u8>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for PtrBuffer

Source§

impl Eq for PtrBuffer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.