Struct UserStrings
pub struct UserStrings<'a> { /* private fields */ }Expand description
The UserStrings object provides helper methods to access the data within the ‘#US’ heap. That heap contains
all user defined Strings, and this object allows to interface with it, and parse and process it properly according
to the standard.
§Examples
use dotscope::metadata::streams::UserStrings;
let data = &[0u8, 65, 0, 0, 0];
let us = UserStrings::from(data).unwrap();
let s = us.get(1).unwrap();
assert_eq!(s.to_string_lossy(), "A");§Reference
Implementations§
§impl<'a> UserStrings<'a>
impl<'a> UserStrings<'a>
pub fn from(data: &'a [u8]) -> Result<UserStrings<'a>>
pub fn from(data: &'a [u8]) -> Result<UserStrings<'a>>
pub fn get(&self, index: usize) -> Result<&'a U16CStr>
pub fn get(&self, index: usize) -> Result<&'a U16CStr>
Get a view into the string contained at the provided location. This will process the heap information, and return a string slice which represents the object located there (if any)
§Arguments
- ‘index’ - The offset within the heap to be accessed (comes from metadata tables)
§Errors
Returns an error if the index is out of bounds or the string data is invalid
§Panics
May panic if the underlying slice conversion fails due to memory alignment issues
pub fn iter(&self) -> UserStringsIterator<'_> ⓘ
pub fn iter(&self) -> UserStringsIterator<'_> ⓘ
Returns an iterator over all user strings in the heap
Provides zero-copy access to all UTF-16 user strings with length prefixes.
Each iteration yields a Result<(usize, &U16CStr)> with the offset and string content.
§Examples
use dotscope::metadata::streams::UserStrings;
let data = &[0u8, 0x05, 0x48, 0x00, 0x69, 0x00, 0x00]; // "Hi" in UTF-16
let user_strings = UserStrings::from(data).unwrap();
for result in user_strings.iter() {
match result {
Ok((offset, string)) => println!("String at {}: '{}'", offset, string.to_string_lossy()),
Err(e) => eprintln!("Error: {}", e),
}
}Trait Implementations§
§impl<'a> IntoIterator for &'a UserStrings<'a>
impl<'a> IntoIterator for &'a UserStrings<'a>
Auto Trait Implementations§
impl<'a> Freeze for UserStrings<'a>
impl<'a> RefUnwindSafe for UserStrings<'a>
impl<'a> Send for UserStrings<'a>
impl<'a> Sync for UserStrings<'a>
impl<'a> Unpin for UserStrings<'a>
impl<'a> UnwindSafe for UserStrings<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more