Skip to content

Commit

Permalink
Added a switch which either reads Codeview Debugdata from pointer or …
Browse files Browse the repository at this point in the history
…address depending if rva is enabled or not
  • Loading branch information
ko1N committed Oct 9, 2019
1 parent 5274419 commit e37cc81
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pe/debug.rs
Expand Up @@ -19,7 +19,7 @@ impl<'a> DebugData<'a> {

pub fn parse_with_opts(bytes: &'a [u8], dd: data_directories::DataDirectory, sections: &[section_table::SectionTable], file_alignment: u32, opts: &options::ParseOptions) -> error::Result<Self> {
let image_debug_directory = ImageDebugDirectory::parse_with_opts(bytes, dd, sections, file_alignment, opts)?;
let codeview_pdb70_debug_info = CodeviewPDB70DebugInfo::parse(bytes, &image_debug_directory)?;
let codeview_pdb70_debug_info = CodeviewPDB70DebugInfo::parse_with_opts(bytes, &image_debug_directory, opts)?;

Ok(DebugData{
image_debug_directory,
Expand Down Expand Up @@ -89,14 +89,21 @@ pub struct CodeviewPDB70DebugInfo<'a> {

impl<'a> CodeviewPDB70DebugInfo<'a> {
pub fn parse(bytes: &'a [u8], idd: &ImageDebugDirectory) -> error::Result<Option<Self>> {
Self::parse_with_opts(bytes, idd, &options::ParseOptions::default())
}

pub fn parse_with_opts(bytes: &'a [u8], idd: &ImageDebugDirectory, opts: &options::ParseOptions) -> error::Result<Option<Self>> {
if idd.data_type != IMAGE_DEBUG_TYPE_CODEVIEW {
// not a codeview debug directory
// that's not an error, but it's not a CodeviewPDB70DebugInfo either
return Ok(None);
}

// ImageDebugDirectory.pointer_to_raw_data stores a raw offset -- not a virtual offset -- which we can use directly
let mut offset: usize = idd.pointer_to_raw_data as usize;
let mut offset: usize = match opts.resolve_rva {
true => idd.pointer_to_raw_data as usize,
false => idd.address_of_raw_data as usize,
};

// calculate how long the eventual filename will be, which doubles as a check of the record size
let filename_length = idd.size_of_data as isize - 24;
Expand Down

0 comments on commit e37cc81

Please sign in to comment.