-
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
pe.import: Add get_imports_rva to SynthethicImportDirectoryEntry #278
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,11 @@ pub enum SyntheticImportLookupTableEntry<'a> { | |
HintNameTableRVA((u32, HintNameTableEntry<'a>)), // [u8; 31] bitfield :/ | ||
} | ||
|
||
pub struct SyntheticImportAddressTableEntry<'a> { | ||
pub rva: u64, | ||
pub name: &'a str, | ||
} | ||
|
||
pub type ImportLookupTable<'a> = Vec<SyntheticImportLookupTableEntry<'a>>; | ||
|
||
impl<'a> SyntheticImportLookupTableEntry<'a> { | ||
|
@@ -293,6 +298,32 @@ impl<'a> SyntheticImportDirectoryEntry<'a> { | |
import_address_table, | ||
}) | ||
} | ||
|
||
pub fn get_imports_rva<T: Bitfield<'a>>( | ||
&self, | ||
) -> error::Result<Vec<SyntheticImportAddressTableEntry<'a>>> { | ||
let mut out = Vec::<SyntheticImportAddressTableEntry>::new(); | ||
if let Some(import_lookup_table) = &(self.import_lookup_table) { | ||
for (i, lookup_entry) in import_lookup_table.iter().enumerate() { | ||
match lookup_entry { | ||
SyntheticImportLookupTableEntry::OrdinalNumber(_) => { | ||
continue; | ||
} | ||
SyntheticImportLookupTableEntry::HintNameTableRVA((_, v)) => { | ||
let import_rva = (self.import_directory_entry.import_address_table_rva | ||
as u64) | ||
+ ((i * std::mem::size_of::<T>()) as u64); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mentioned needing to know the size of the PE; this information is usually in the parsing context but I’m not sure if you have access to it here, haven’t looked at this code in a while. Or is the mem::size_of sufficient for this ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
out.push(SyntheticImportAddressTableEntry { | ||
rva: import_rva, | ||
name: v.name, | ||
}); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
Ok(out) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
|
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 don’t see any fallibility here, so I’d drop the error return. Also I would attempt to get rid of allocation via returning a vec and try
impl Iterator<Item = SyntheticImportAddressTableEntry<‘a>> + ‘a
(you may have to play with the lifetimes). Since it’s optional too you may have to do
self.import_table.unwrap_or(&[]).iter().enumerate().flatmap
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.
Got it will implement it as an iterator