Skip to content

Commit

Permalink
feat: add ResourceName::raw_data method
Browse files Browse the repository at this point in the history
Gives access to the raw bytes of the name string, instead of a u16
slice.
  • Loading branch information
vthib committed Nov 19, 2022
1 parent b7d879d commit 510ba02
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/read/pe/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ impl ResourceName {
.read_slice::<U16Bytes<LE>>(&mut offset, len.get(LE).into())
.read_error("Invalid resource name length")
}

/// Returns the string buffer as raw bytes.
pub fn raw_data<'data>(&self, directory: ResourceDirectory<'data>) -> Result<&'data [u8]> {
let mut offset = u64::from(self.offset);
let len = directory
.data
.read::<U16Bytes<LE>>(&mut offset)
.read_error("Invalid resource name offset")?;
// This is a length of the u16 string, multiply by 2 to get the length in bytes.
let len = u64::from(len.get(LE)) * 2;
directory
.data
.read_bytes(&mut offset, len)
.read_error("Invalid resource name length")
}
}

/// A resource name or ID.
Expand Down

0 comments on commit 510ba02

Please sign in to comment.