Expand description
PKBuffer is a library built for arbitrary casting of data structures onto segments of memory! This includes sections of unowned memory, such as examining the headers of a currently running executable. It creates an interface for reading and writing data structures to an arbitrary buffer of bytes.
For example:
use pkbuffer::{Buffer, VecBuffer, Castable};
#[repr(packed)]
#[derive(Copy, Clone, Castable)]
struct Object {
byte: u8,
word: u16,
dword: u32,
}
let mut buffer = VecBuffer::with_initial_size(std::mem::size_of::<Object>());
let object = buffer.get_mut_ref::<Object>(0).unwrap();
object.byte = 0x01;
object.word = 0x0302;
object.dword = 0x07060504;
assert_eq!(buffer, [1,2,3,4,5,6,7]);
Objects retrieved from Buffer
objects must implement the Castable
trait. This trait ensures that a series of attributes are applied to the object. For
convenience, a derive macro is provided.
Buffer objects are derived from the Buffer
trait. This trait
implements much functionality of slice objects as well as data casting
abilities of the derived Buffer objects.
Buffer objects comes in two forms: pointer form (PtrBuffer
) and
allocated form (VecBuffer
). Each of these structures come
in handy for different reasons. PtrBuffer
is useful on unowned data
such as arbitrary locations in memory, whereas VecBuffer
’s
utility comes from being able to manipulate the underlying owned data.
VecBuffer
s are handy for creating a brand-new buffer of objects.
use pkbuffer::{Buffer, VecBuffer};
let mut buffer = VecBuffer::new();
buffer.append_ref::<u8>(&0x1);
buffer.append_ref::<u16>(&0x0302);
buffer.append_ref::<u32>(&0x07060504);
assert_eq!(buffer, [1,2,3,4,5,6,7]);
Structs§
- Buffer
Iter - An iterator for a
Buffer
object. - Buffer
Iter Mut - A mutable iterator for a
Buffer
object. - Buffer
Search Dynamic Iter - An iterator for searching over a
Buffer
’s space for a given dynamic search term. - Buffer
Search Iter - An iterator for searching over a
Buffer
’s space for a given binary search term. - PtrBuffer
- A
Buffer
object backed by a pointer/size pair. Use this buffer type when accessing unowned memory or arbitrary allocated memory. - VecBuffer
- An owned-data
Buffer
object.
Enums§
- Error
- Errors produced by the library.
Traits§
Functions§
- bytes_
to_ mut_ ref - Cast type
&mut T
from a mutableu8
slice. - bytes_
to_ ref - Cast type
&T
from au8
slice. - ref_
to_ bytes - Convert the given reference of type
T
to au8
slice. - ref_
to_ mut_ bytes - Convert the given reference of type
T
to a mutableu8
slice. - slice_
ref_ to_ bytes - Convert the given slice reference of type
T
to au8
slice. - slice_
ref_ to_ mut_ bytes - Convert the given slice reference of type
T
to a mutableu8
slice.
Derive Macros§
- Castable
- Derive the
Castable
trait for a given object.