-
Notifications
You must be signed in to change notification settings - Fork 160
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
fix: Iterate all ImageDebugDirectory entries #319
base: master
Are you sure you want to change the base?
Conversation
Turns out, a PE file can have more than one ImageDebugDirectory. Thus far, goblin only looks at the very first one, trying to interpret it as a CV record. This code changes that logic to rather iterate over all the entries to find the one that is a CV record. We still only capture a single entry in the `DebugData` for backwards compatibility reasons. In the future we could as well capture all of them.
fb87790
to
ba65c43
Compare
fun fact: I wrote a detailed blog post about how I made this discovery: https://swatinem.de/blog/format-ossification/ |
looks like a CI failure? |
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.
Let's fix the CI failure then I'll do another pass at review, and thanks for this!
Ok(DebugData { | ||
image_debug_directory, | ||
codeview_pdb70_debug_info, | ||
image_debug_directory: entries.pop().unwrap(), |
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.
can this unwrap ever fail?
.collect::<Result<Vec<ImageDebugDirectory>, _>>()?; | ||
|
||
// find the debug directory that references the codeview record | ||
for (idx, idd) in entries.iter().enumerate() { |
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 know the original code just tries parsing CodeviewPDB70DebugInfo
directly, but you should additionally be able to look at the data_type
field to see if it is IMAGE_DEBUG_TYPE_CODEVIEW
per the MSDN docs.
Turns out, a PE file can have more than one ImageDebugDirectory.
Thus far, goblin only looks at the very first one, trying to interpret
it as a CV record.
This code changes that logic to rather iterate over all the entries to
find the one that is a CV record.
We still only capture a single entry in the
DebugData
for backwardscompatibility reasons. In the future we could as well capture all of
them.