Skip to main content

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 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 try_swap(&mut self, a: usize, b: usize) -> Result<(), Error>

Swap two bytes at the given offsets. Read more
Source§

fn reverse(&mut self)

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

fn try_reverse(&mut self) -> Result<(), Error>

Reverse the buffer, returning an error on failure. Read more
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 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 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 more
Source§

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 more
Source§

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 more
Source§

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 more
Source§

fn get_aligned_ref<T: Copy>(&self, offset: usize) -> Result<&T, Error>

Get a reference to T at the given offset, verifying alignment. Read more
Source§

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 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_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 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 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<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_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 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 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)

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

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)

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

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)
where F: FnMut() -> u8,

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>
where F: FnMut() -> u8,

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)

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

fn try_clone_from_data<B: AsRef<[u8]>>(&mut self, src: B) -> Result<(), Error>

Clone the given u8 slice data src into the given buffer. Read more
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 try_copy_from_data<B: AsRef<[u8]>>(&mut self, src: B) -> Result<(), Error>

Copy the given u8 slice data src into the given buffer. Read more
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 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)

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

fn try_swap_with_data<B: AsMut<[u8]>>(&mut self, other: B) -> Result<(), Error>

Swap the data in this buffer with the given u8 slice reference. Read more
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 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)
where F: FnMut(&u8, &u8) -> Ordering,

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>
where F: FnMut(&u8, &u8) -> Ordering,

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)
where F: FnMut(&u8) -> K, K: Ord,

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>
where F: FnMut(&u8) -> K, K: Ord,

Sorts the slice with a key extraction function, returning an error on failure. Read more
Source§

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

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

fn try_repeat(&self, n: usize) -> Result<Vec<u8>, Error>

Creates a new Buffer object by repeating the current buffer n times. Read more
Source§

impl Clone for PtrBuffer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for PtrBuffer

Source§

impl Debug for PtrBuffer

Source§

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

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

impl Eq for PtrBuffer

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<T: Buffer> PartialEq<T> for PtrBuffer

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Vec<u8>> for PtrBuffer

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<[u8]> for PtrBuffer

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.