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

Add DebugDirectory directory entry type #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -13,4 +13,3 @@ bitflags = "0.4" # MIT/Apache-2.0
[dev-dependencies]
lazy_static = "0.1" # MIT
itertools = "0.4" # MIT/Apache-2.0

1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -85,6 +85,7 @@ macro_rules! directory_entry(

directory_entry!(ExportTable = RVA<ExportDirectory>);
directory_entry!(BaseRelocationTable = RVA<RelocationBlock>);
directory_entry!(Debug = RVA<DebugDirectory>);
Copy link
Owner

Choose a reason for hiding this comment

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

I think RVA<[DebugDirectory]> would be more appropriate. Can you also add pub fn get_debug_directories(&self) -> Result<&'data [DebugDirectory]> to impl Pe?

Copy link
Author

Choose a reason for hiding this comment

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

Could you clarify on RVA<[DebugDirectory]>, [DebugDirectory] is not RefSafe so wouldn't be able to implement the Directory trait.

Copy link
Owner

@jethrogb jethrogb Jun 12, 2017

Choose a reason for hiding this comment

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

I think that's actually too strict a limitation and the RefSafe bound can be moved to Directory::Type


pub struct Exports<'pe,'data: 'pe> {
pe: &'pe Pe<'data>,
Expand Down
29 changes: 29 additions & 0 deletions src/tests.rs
Expand Up @@ -42,6 +42,35 @@ fn list_sections() {
itertools::assert_equal(SQLITE_X86_PE.get_sections().iter().map(|section|section.name.as_os_str()),sqlite_x86_sections.iter().cloned());
}

#[test]
fn rsds_debug_directory() {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you check add tests for the 64-bit image as well?

let debug_dir = SQLITE_X86_PE.get_directory::<DebugDirectory>().unwrap();

let start_address: utility::RVA<types::DebugDirectory> = debug_dir.virtual_address;
let size = debug_dir.size;

let num_debug_directories = size / 28;
assert_eq!(num_debug_directories, 2);

let rsds_offset: RVA<DebugDirectory> = start_address;
let rsds_debug_entry: &DebugDirectory = SQLITE_X86_PE.ref_at(rsds_offset).unwrap();
assert_eq!(rsds_debug_entry.debug_type, 2);
Copy link
Owner

Choose a reason for hiding this comment

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

What does 2 mean?


let signature_rva: RVA<u32> = RVA::new(rsds_debug_entry.address_of_raw_data.get());
let signature: &u32 = SQLITE_X86_PE.ref_at(signature_rva).unwrap();
assert_eq!(signature, &0x53445352); // "RSDS"

let path_rva: RVA<[CChar]> = signature_rva.offset(24);
let path: &[CChar] = SQLITE_X86_PE.ref_cstr_at(path_rva).unwrap();
assert_eq!(path.as_os_str(), "C:\\dev\\sqlite\\core\\sqlite3.pdb");

let guid_bytes: RVA<[u8]> = signature_rva.offset(4);
let guid_bytes: &[u8] = SQLITE_X86_PE.ref_slice_at(guid_bytes, 16).unwrap();

// {39152019-C388-4D2A-AA1D-E640BF5EE86A}
assert_eq!(guid_bytes, &[25, 32, 21, 57, 136, 195, 42, 77, 170, 29, 230, 64, 191, 94, 232, 106]);
}

#[test]
fn export_name() {
let name="sqlite3.dll";
Expand Down
14 changes: 14 additions & 0 deletions src/types.rs
Expand Up @@ -327,6 +327,20 @@ pub struct ExportDirectory {
}
unsafe impl RefSafe for ExportDirectory {}

#[repr(packed)]
#[derive(Clone, Debug)]
pub struct DebugDirectory {
pub characteristics: u32,
pub time_date_stamp: u32,
pub major_version: u16,
pub minor_version: u16,
pub debug_type: u32,
pub size_of_data: u32,
pub address_of_raw_data: RVA<()>,
pub pointer_to_raw_data: FP<()>,
}
unsafe impl RefSafe for DebugDirectory {}

#[repr(packed)]
#[derive(Clone, Debug)]
pub struct RawExportAddress(pub RVA<()>);
Expand Down