microsoft / SizeBench

SizeBench is a binary size investigation tool for Windows
MIT License
103 stars 14 forks source link

Fix some issues with PDATA, fix binary locator, and address a couple warnings #28

Closed Austin-Lamb closed 9 months ago

Austin-Lamb commented 9 months ago

Why is this change being made?

A customer reported issues with some of their binaries thinking they had chained PDATA records (very uncommon for x64, so SizeBench doesn't support that yet). As I investigated, it turned out that there were two problems:

  1. Some UNWIND_INFO structures have a version 0 and flags 0, so they can be skipped.
  2. The PDATA doesn't always live in its own section, nor is it required to take up a full section. SizeBench was assuming that and that's wrong - instead we should look at the "Exception" directory of the PE optional header which has the exact location and length of the PDATA array. Because SizeBench was reading this wrong in some edge cases, we'd get garbage/misaligned data in the PDATA and think we were trying to parse chained PDATA when in fact that wasn't the case.  

    Briefly summarize what changed

    • Fix PDATA RVA range to be correct, and correspondingly update the tests.
    • If we find an UNWIND_INFO with version == 0 and flags == 0, just skip it.

While I was doing this, I also did a little cleanup:

How was the change tested?

PR Checklist