BinaryReader

Struct BinaryReader 

Source
pub struct BinaryReader<'a> { /* private fields */ }
Expand description

Binary reader for Unity file formats

Implementations§

Source§

impl<'a> BinaryReader<'a>

Source

pub const DEFAULT_MAX_STRING_LEN: usize = 16_777_216usize

Default maximum length for length-prefixed strings.

Unity files can contain large text blobs (e.g. TextAsset), but unbounded allocations are a DoS risk when parsing hostile input.

Source

pub fn new(data: &'a [u8], byte_order: ByteOrder) -> Self

Create a new binary reader from byte slice

Source

pub fn position(&self) -> u64

Get current position in the stream

Source

pub fn set_position(&mut self, pos: u64) -> Result<()>

Set position in the stream

Source

pub fn seek(&mut self, offset: i64) -> Result<u64>

Seek to a position relative to the current position

Source

pub fn len(&self) -> usize

Get the total length of the data

Source

pub fn is_empty(&self) -> bool

Check if the reader is empty

Source

pub fn remaining(&self) -> usize

Get remaining bytes from current position

Source

pub fn has_bytes(&self, count: usize) -> bool

Check if we have at least count bytes remaining

Source

pub fn align(&mut self) -> Result<()>

Align to the next 4-byte boundary

Source

pub fn align_to(&mut self, alignment: u64) -> Result<()>

Align to the specified byte boundary

Source

pub fn read_u8(&mut self) -> Result<u8>

Read a single byte

Source

pub fn read_bool(&mut self) -> Result<bool>

Read a boolean (as u8, 0 = false, non-zero = true)

Source

pub fn read_i8(&mut self) -> Result<i8>

Read a signed 8-bit integer

Source

pub fn read_u16(&mut self) -> Result<u16>

Read an unsigned 16-bit integer

Source

pub fn read_i16(&mut self) -> Result<i16>

Read a signed 16-bit integer

Source

pub fn read_u32(&mut self) -> Result<u32>

Read an unsigned 32-bit integer

Source

pub fn read_i32(&mut self) -> Result<i32>

Read a signed 32-bit integer

Source

pub fn read_u64(&mut self) -> Result<u64>

Read an unsigned 64-bit integer

Source

pub fn read_i64(&mut self) -> Result<i64>

Read a signed 64-bit integer

Source

pub fn read_f32(&mut self) -> Result<f32>

Read a 32-bit floating point number

Source

pub fn read_f64(&mut self) -> Result<f64>

Read a 64-bit floating point number

Source

pub fn read_bytes(&mut self, count: usize) -> Result<Vec<u8>>

Read a fixed number of bytes

Source

pub fn skip_bytes(&mut self, count: usize) -> Result<()>

Skip a fixed number of bytes without allocating.

Source

pub fn read_remaining(&mut self) -> &[u8]

Read all remaining bytes

Source

pub fn read_cstring(&mut self) -> Result<String>

Read a null-terminated string

Source

pub fn read_string(&mut self) -> Result<String>

Read a string with a length prefix (32-bit)

Source

pub fn read_string_limited(&mut self, max_len: usize) -> Result<String>

Read a string with a length prefix and an explicit maximum size.

Unity typically encodes these lengths as signed 32-bit integers.

Source

pub fn read_string_fixed(&mut self, length: usize) -> Result<String>

Read a string with a specific length

Source

pub fn read_aligned_string(&mut self) -> Result<String>

Read an aligned string (Unity format)

Source

pub fn byte_order(&self) -> ByteOrder

Get the current byte order

Source

pub fn set_byte_order(&mut self, byte_order: ByteOrder)

Set the byte order

Source

pub fn remaining_slice(&self) -> &[u8]

Get a slice of the remaining data

Source

pub fn sub_reader( &self, offset: usize, length: usize, ) -> Result<BinaryReader<'a>>

Create a new reader for a subset of the data

Auto Trait Implementations§

§

impl<'a> Freeze for BinaryReader<'a>

§

impl<'a> RefUnwindSafe for BinaryReader<'a>

§

impl<'a> Send for BinaryReader<'a>

§

impl<'a> Sync for BinaryReader<'a>

§

impl<'a> Unpin for BinaryReader<'a>

§

impl<'a> UnwindSafe for BinaryReader<'a>

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> 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, 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.