-
Notifications
You must be signed in to change notification settings - Fork 163
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
Public utils + more examples #116
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fbef303
initial version
Pzixel c125562
typos
Pzixel fe1e933
Rename CLR -> CLI
Pzixel 24176a7
Fix review comments
Pzixel 58b4d5f
macro_use
Pzixel 2b03432
Make better API for getting data
Pzixel 55dee76
Fix no_std issues
Pzixel 76e0e03
Fix no_std issues 2
Pzixel 1468cc1
Fix 1.20 issues
Pzixel 1c9f864
revert cli->clr
Pzixel 10e88d7
Review fix
Pzixel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ Cargo.lock | |
*~ | ||
*# | ||
*.#* | ||
/cmake-build-debug/ | ||
/.idea/ | ||
**/*.rs.bk |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/// Demonstrates how to read additional metadata (i.e. .Net runtime ones) from PE context | ||
|
||
#[macro_use] | ||
extern crate scroll; | ||
extern crate goblin; | ||
|
||
use goblin::container::Endian; | ||
use goblin::pe::data_directories::DataDirectory; | ||
use goblin::pe::PE; | ||
use scroll::ctx::TryFromCtx; | ||
use scroll::Pread; | ||
use goblin::pe::utils::get_data; | ||
|
||
#[repr(C)] | ||
#[derive(Debug, Pread)] | ||
pub struct CliHeader { | ||
pub cb: u32, | ||
pub major_version: u16, | ||
pub minor_version: u16, | ||
pub metadata: DataDirectory, | ||
pub flags: u32, | ||
pub entry_point_token: u32, | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Debug)] | ||
struct MetadataRoot<'a> { | ||
pub signature: u32, | ||
pub major_version: u16, | ||
pub minor_version: u16, | ||
_reserved: u32, | ||
pub length: u32, | ||
pub version: &'a str, | ||
} | ||
|
||
impl<'a> TryFromCtx<'a, Endian> for MetadataRoot<'a> { | ||
type Error = scroll::Error; | ||
type Size = usize; | ||
|
||
fn try_from_ctx(src: &'a [u8], endian: Endian) -> Result<(Self, Self::Size), Self::Error> { | ||
let offset = &mut 0; | ||
let signature = src.gread_with(offset, endian)?; | ||
let major_version = src.gread_with(offset, endian)?; | ||
let minor_version = src.gread_with(offset, endian)?; | ||
let reserved = src.gread_with(offset, endian)?; | ||
let length = src.gread_with(offset, endian)?; | ||
let version = src.gread(offset)?; | ||
Ok(( | ||
Self { | ||
signature, | ||
major_version, | ||
minor_version, | ||
_reserved: reserved, | ||
length, | ||
version, | ||
}, | ||
*offset, | ||
)) | ||
} | ||
} | ||
|
||
fn main() { | ||
let file = include_bytes!("../assets/dotnet_executable_example.dll"); | ||
let file = &file[..]; | ||
let pe = PE::parse(file).unwrap(); | ||
if pe.header.coff_header.machine != 0x14c { | ||
panic!("Is not a .Net executable"); | ||
} | ||
let optional_header = pe.header.optional_header.expect("No optional header"); | ||
let file_alignment = optional_header.windows_fields.file_alignment; | ||
let cli_header = optional_header | ||
.data_directories | ||
.get_clr_runtime_header() | ||
.expect("No CLI header"); | ||
let sections = &pe.sections; | ||
|
||
let cli_header_value: CliHeader = get_data(file, sections, &cli_header, file_alignment).unwrap(); | ||
println!("{:#?}", cli_header_value); | ||
let metadata_root: MetadataRoot = get_data(file, sections, &cli_header_value.metadata, file_alignment).unwrap(); | ||
println!("{:#?}", metadata_root); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it belongs as a method in DataDirectories ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, because it belongs to SectionTable as well.. Utils is the good place for this imo