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

A common string table format which is indexed by byte offsets (and not member index). Constructed using parse with your choice of delimiter. Please be careful.

Implementations

Creates a Strtab with bytes as the backing string table, using delim as the delimiter between entries.

NB: this does not preparse the string table, which can have non-optimal access patterns. See https://github.com/m4b/goblin/pull/275#issue-660364025

Creates a Strtab directly without bounds check and without parsing it.

This is potentially unsafe and should only be used if feature = "alloc" is disabled.

Gets a str reference from the backing bytes starting at byte offset.

If the index is out of bounds, None is returned. Panics if bytes are invalid UTF-8. Use this method if the Strtab was created using from_slice_unparsed().

Parses a Strtab from bytes at offset with len size as the backing string table, using delim as the delimiter.

Errors if bytes are invalid UTF-8. Requires feature = "alloc"

Parses a Strtab with bytes as the backing string table, using delim as the delimiter between entries.

Requires feature = "alloc"

Converts the string table to a vector of parsed strings.

Note: This method is used to check the parsed contents of strtab. If you want to get the correct contents of strtab as Vec, use the following example.

Examples
use goblin::error::Error;

pub fn show_shdr_strtab(bytes: &[u8]) -> Result<(), Error> {
    let elf = goblin::elf::Elf::parse(&bytes)?;

    for section in elf.section_headers {
        println!("{}", elf.shdr_strtab.get_at(section.sh_name).unwrap_or(""));
    }

    Ok(())
}

Requires feature = "alloc"

Safely gets a str reference from the parsed table starting at byte offset.

If the index is out of bounds, None is returned. Requires feature = "alloc"

👎 Deprecated since 0.4.2:

Use from_slice_unparsed() instead

Construct a strtab from a ptr, and a size, using delim as the delimiter

Safety

This function creates a Strtab directly from a raw pointer and size

👎 Deprecated since 0.4.2:

Bad performance, use get_at() instead

Parses a str reference from the parsed table starting at byte offset.

If the index is out of bounds, None is returned. Requires feature = "alloc"

Trait Implementations

Formats the value using the given formatter. Read more

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

Gets str reference at starting at byte offset. NB: this will panic if the underlying bytes are not valid utf8, or the offset is invalid

The returned type after indexing.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.