Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ResourceName::raw_data method #487

Merged
merged 1 commit into from Nov 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/read/pe/resource.rs
Expand Up @@ -166,6 +166,11 @@ 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]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating logic, can we implement in terms of data. Something like self.data(directory).map(pod::bytes_of_slice).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes! I didn't know about bytes_of_slice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since bytes_of_slice is public, this oneliner can be done on the user (my) side, so this helper is not that very useful anymore. I'll let you decide if it makes sense to keep it or not

self.data(directory).map(crate::pod::bytes_of_slice)
}
}

/// A resource name or ID.
Expand Down