pub struct BinaryReader<'a> { /* private fields */ }Expand description
Binary reader for Unity file formats
Implementations§
Source§impl<'a> BinaryReader<'a>
impl<'a> BinaryReader<'a>
Sourcepub const DEFAULT_MAX_STRING_LEN: usize = 16_777_216usize
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.
Sourcepub fn new(data: &'a [u8], byte_order: ByteOrder) -> Self
pub fn new(data: &'a [u8], byte_order: ByteOrder) -> Self
Create a new binary reader from byte slice
Sourcepub fn set_position(&mut self, pos: u64) -> Result<()>
pub fn set_position(&mut self, pos: u64) -> Result<()>
Set position in the stream
Sourcepub fn seek(&mut self, offset: i64) -> Result<u64>
pub fn seek(&mut self, offset: i64) -> Result<u64>
Seek to a position relative to the current position
Sourcepub fn skip_bytes(&mut self, count: usize) -> Result<()>
pub fn skip_bytes(&mut self, count: usize) -> Result<()>
Skip a fixed number of bytes without allocating.
Sourcepub fn read_remaining(&mut self) -> &[u8] ⓘ
pub fn read_remaining(&mut self) -> &[u8] ⓘ
Read all remaining bytes
Sourcepub fn read_cstring(&mut self) -> Result<String>
pub fn read_cstring(&mut self) -> Result<String>
Read a null-terminated string
Sourcepub fn read_string(&mut self) -> Result<String>
pub fn read_string(&mut self) -> Result<String>
Read a string with a length prefix (32-bit)
Sourcepub fn read_string_limited(&mut self, max_len: usize) -> Result<String>
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.
Sourcepub fn read_string_fixed(&mut self, length: usize) -> Result<String>
pub fn read_string_fixed(&mut self, length: usize) -> Result<String>
Read a string with a specific length
Sourcepub fn read_aligned_string(&mut self) -> Result<String>
pub fn read_aligned_string(&mut self) -> Result<String>
Read an aligned string (Unity format)
Sourcepub fn byte_order(&self) -> ByteOrder
pub fn byte_order(&self) -> ByteOrder
Get the current byte order
Sourcepub fn set_byte_order(&mut self, byte_order: ByteOrder)
pub fn set_byte_order(&mut self, byte_order: ByteOrder)
Set the byte order
Sourcepub fn remaining_slice(&self) -> &[u8] ⓘ
pub fn remaining_slice(&self) -> &[u8] ⓘ
Get a slice of the remaining data
Sourcepub fn sub_reader(
&self,
offset: usize,
length: usize,
) -> Result<BinaryReader<'a>>
pub fn sub_reader( &self, offset: usize, length: usize, ) -> Result<BinaryReader<'a>>
Create a new reader for a subset of the data