gimli::read

Type Alias EndianBuf

Source
pub type EndianBuf<'input, Endian> = EndianSlice<'input, Endian>;
👎Deprecated: EndianBuf has been renamed to EndianSlice, use that instead.
Expand description

EndianBuf has been renamed to EndianSlice. For ease of upgrading across gimli versions, we export this type alias.

Aliased Type§

struct EndianBuf<'input, Endian> {
    slice: &'input [u8],
    endian: Endian,
}

Fields§

§slice: &'input [u8]§endian: Endian

Implementations

Source§

impl<'input, Endian> EndianSlice<'input, Endian>
where Endian: Endianity,

§Range Methods

Unfortunately, std::ops::Index must return a reference, so we can’t implement Index<Range<usize>> to return a new EndianSlice the way we would like to. Instead, we abandon fancy indexing operators and have these plain old methods.

Source

pub fn range(&self, idx: Range<usize>) -> EndianSlice<'input, Endian>

Take the given start..end range of the underlying slice and return a new EndianSlice.

use gimli::{EndianSlice, LittleEndian};

let slice = &[0x01, 0x02, 0x03, 0x04];
let endian_slice = EndianSlice::new(slice, LittleEndian);
assert_eq!(endian_slice.range(1..3),
           EndianSlice::new(&slice[1..3], LittleEndian));
Source

pub fn range_from(&self, idx: RangeFrom<usize>) -> EndianSlice<'input, Endian>

Take the given start.. range of the underlying slice and return a new EndianSlice.

use gimli::{EndianSlice, LittleEndian};

let slice = &[0x01, 0x02, 0x03, 0x04];
let endian_slice = EndianSlice::new(slice, LittleEndian);
assert_eq!(endian_slice.range_from(2..),
           EndianSlice::new(&slice[2..], LittleEndian));
Source

pub fn range_to(&self, idx: RangeTo<usize>) -> EndianSlice<'input, Endian>

Take the given ..end range of the underlying slice and return a new EndianSlice.

use gimli::{EndianSlice, LittleEndian};

let slice = &[0x01, 0x02, 0x03, 0x04];
let endian_slice = EndianSlice::new(slice, LittleEndian);
assert_eq!(endian_slice.range_to(..3),
           EndianSlice::new(&slice[..3], LittleEndian));
Source§

impl<'input, Endian> EndianSlice<'input, Endian>
where Endian: Endianity,

Source

pub fn new(slice: &'input [u8], endian: Endian) -> EndianSlice<'input, Endian>

Construct a new EndianSlice with the given slice and endianity.

Source

pub fn slice(&self) -> &'input [u8]

Return a reference to the raw slice.

Source

pub fn split_at( &self, idx: usize, ) -> (EndianSlice<'input, Endian>, EndianSlice<'input, Endian>)

Split the slice in two at the given index, resulting in the tuple where the first item has range [0, idx), and the second has range [idx, len). Panics if the index is out of bounds.

Source

pub fn find(&self, byte: u8) -> Option<usize>

Find the first occurrence of a byte in the slice, and return its index.

Source

pub fn offset_from(&self, base: EndianSlice<'input, Endian>) -> usize

Return the offset of the start of the slice relative to the start of the given slice.

Source

pub fn to_string(&self) -> Result<&'input str>

Converts the slice to a string using str::from_utf8.

Returns an error if the slice contains invalid characters.

Source

pub fn to_string_lossy(&self) -> Cow<'input, str>

Converts the slice to a string, including invalid characters, using String::from_utf8_lossy.

Source

fn read_slice(&mut self, len: usize) -> Result<&'input [u8]>

Trait Implementations

Source§

impl<'input, Endian> Clone for EndianSlice<'input, Endian>
where Endian: Endianity + Clone,

Source§

fn clone(&self) -> EndianSlice<'input, Endian>

Returns a copy 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<'input, Endian: Endianity> Debug for EndianSlice<'input, Endian>

Source§

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

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

impl<'input, Endian> Default for EndianSlice<'input, Endian>
where Endian: Endianity + Default,

Source§

fn default() -> EndianSlice<'input, Endian>

Returns the “default value” for a type. Read more
Source§

impl<'input, Endian> Deref for EndianSlice<'input, Endian>
where Endian: Endianity,

Source§

type Target = [u8]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'input, Endian> Hash for EndianSlice<'input, Endian>
where Endian: Endianity + Hash,

Source§

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

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

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

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

impl<'input, Endian> PartialEq for EndianSlice<'input, Endian>
where Endian: Endianity + PartialEq,

Source§

fn eq(&self, other: &EndianSlice<'input, Endian>) -> 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<'input, Endian> Reader for EndianSlice<'input, Endian>
where Endian: Endianity,

Source§

type Endian = Endian

The endianity of bytes that are read.
Source§

type Offset = usize

The type used for offsets and lengths.
Source§

fn endian(&self) -> Endian

Return the endianity of bytes that are read.
Source§

fn len(&self) -> usize

Return the number of bytes remaining.
Source§

fn is_empty(&self) -> bool

Return true if the number of bytes remaining is zero.
Source§

fn empty(&mut self)

Set the number of bytes remaining to zero.
Source§

fn truncate(&mut self, len: usize) -> Result<()>

Set the number of bytes remaining to the specified length.
Source§

fn offset_from(&self, base: &Self) -> usize

Return the offset of this reader’s data relative to the start of the given base reader’s data. Read more
Source§

fn offset_id(&self) -> ReaderOffsetId

Return an identifier for the current reader offset.
Source§

fn lookup_offset_id(&self, id: ReaderOffsetId) -> Option<Self::Offset>

Return the offset corresponding to the given id if it is associated with this reader.
Source§

fn find(&self, byte: u8) -> Result<usize>

Find the index of the first occurrence of the given byte. The offset of the reader is not changed.
Source§

fn skip(&mut self, len: usize) -> Result<()>

Discard the specified number of bytes.
Source§

fn split(&mut self, len: usize) -> Result<Self>

Split a reader in two. Read more
Source§

fn to_slice(&self) -> Result<Cow<'_, [u8]>>

Return all remaining data as a clone-on-write slice. Read more
Source§

fn to_string(&self) -> Result<Cow<'_, str>>

Convert all remaining data to a clone-on-write string. Read more
Source§

fn to_string_lossy(&self) -> Result<Cow<'_, str>>

Convert all remaining data to a clone-on-write string, including invalid characters. Read more
Source§

fn read_slice(&mut self, buf: &mut [u8]) -> Result<()>

Read exactly buf.len() bytes into buf.
Source§

fn read_u8_array<A>(&mut self) -> Result<A>
where A: Sized + Default + AsMut<[u8]>,

Read a u8 array.
Source§

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

Read a u8.
Source§

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

Read an i8.
Source§

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

Read a u16.
Source§

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

Read an i16.
Source§

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

Read a u32.
Source§

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

Read an i32.
Source§

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

Read a u64.
Source§

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

Read an i64.
Source§

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

Read a f32.
Source§

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

Read a f64.
Source§

fn read_uint(&mut self, n: usize) -> Result<u64>

Read an unsigned n-bytes integer u64. Read more
Source§

fn read_null_terminated_slice(&mut self) -> Result<Self>

Read a null-terminated slice, and return it (excluding the null).
Source§

fn skip_leb128(&mut self) -> Result<()>

Skip a LEB128 encoded integer.
Source§

fn read_uleb128(&mut self) -> Result<u64>

Read an unsigned LEB128 encoded integer.
Source§

fn read_uleb128_u32(&mut self) -> Result<u32>

Read an unsigned LEB128 encoded u32.
Source§

fn read_uleb128_u16(&mut self) -> Result<u16>

Read an unsigned LEB128 encoded u16.
Source§

fn read_sleb128(&mut self) -> Result<i64>

Read a signed LEB128 encoded integer.
Source§

fn read_initial_length(&mut self) -> Result<(Self::Offset, Format)>

Read an initial length field. Read more
Source§

fn read_address_size(&mut self) -> Result<u8>

Read a byte and validate it as an address size.
Source§

fn read_address(&mut self, address_size: u8) -> Result<u64>

Read an address-sized integer, and return it as a u64.
Source§

fn read_word(&mut self, format: Format) -> Result<Self::Offset>

Parse a word-sized integer according to the DWARF format. Read more
Source§

fn read_length(&mut self, format: Format) -> Result<Self::Offset>

Parse a word-sized section length according to the DWARF format.
Source§

fn read_offset(&mut self, format: Format) -> Result<Self::Offset>

Parse a word-sized section offset according to the DWARF format.
Source§

fn read_sized_offset(&mut self, size: u8) -> Result<Self::Offset>

Parse a section offset of the given size. Read more
Source§

impl<'input, Endian> Copy for EndianSlice<'input, Endian>
where Endian: Endianity + Copy,

Source§

impl<'input, Endian> Eq for EndianSlice<'input, Endian>
where Endian: Endianity + Eq,

Source§

impl<'input, Endian> StructuralPartialEq for EndianSlice<'input, Endian>
where Endian: Endianity,