pe_inspect: parse and validate x64 pdata exception directory table (OLD-7796) #698

Open
github-bot wants to merge 3 commits from github-bot/gh-698 into main AGit
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 12:17 UTC · original
abnalstlll-byte:feat/exe-pdata-table → main · +484 −5 · 2 files · 3 commits · open

Related issues: #14, #18 (restoring old upstream PR 7796).

What and why

Restores original pull request OLD-7796 authored by @⁠abnalstlll-byte:

  • Extends \ ools/pe_inspect.py\ with full support for parsing the x64 .pdata\ runtime function exception directory table (\IMAGE_RUNTIME_FUNCTION_ENTRY).
  • Decodes BeginAddress, EndAddress, and UnwindInfoAddress RVAs, asserting monotonicity and valid section containment.
  • Parses \UNWIND_INFO\ structures (version, flags, prolog size, unwind code count, frame register and offset).
  • Comprehensive unit test coverage in \ ests/test_pe_inspect.py.

Tested

  • Windows 11 x64, Python 3.14 / 3.12:
    • \python -I tests/test_pe_inspect.py: 69/69 PASS.
    • \python -I scripts/check_no_game_data.py\ on changed files: PASS.
  • Clean merge against \ubi/main\ (0 conflicts).

Checklist

  • No proprietary payloads, game-derived files, keys, or protection workarounds.
  • Standard library only (\python -I).
  • Preserves author attribution and original PR commit provenance.
**@⁠abnalstlll-byte** on GitHub · 2026-11-24 12:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/698) `abnalstlll-byte:feat/exe-pdata-table` → `main` · +484 −5 · 2 files · 3 commits · open Related issues: #14, #18 (restoring old upstream PR 7796). ### What and why Restores original pull request **OLD-7796** authored by @⁠abnalstlll-byte: - Extends \ ools/pe_inspect.py\ with full support for parsing the x64 \.pdata\ runtime function exception directory table (\IMAGE_RUNTIME_FUNCTION_ENTRY\). - Decodes BeginAddress, EndAddress, and UnwindInfoAddress RVAs, asserting monotonicity and valid section containment. - Parses \UNWIND_INFO\ structures (version, flags, prolog size, unwind code count, frame register and offset). - Comprehensive unit test coverage in \ ests/test_pe_inspect.py\. ### Tested - Windows 11 x64, Python 3.14 / 3.12: - \python -I tests/test_pe_inspect.py\: 69/69 PASS. - \python -I scripts/check_no_game_data.py\ on changed files: PASS. - Clean merge against \ubi/main\ (0 conflicts). ### Checklist - [x] No proprietary payloads, game-derived files, keys, or protection workarounds. - [x] Standard library only (\python -I\). - [x] Preserves author attribution and original PR commit provenance.
In docs/design.md the runtime loader contract specifies that each mapped
image's .pdata table is checked before being handed to RtlAddFunctionTable
(in bounds, sorted, non-overlapping, with zero-length entries permitted,
as in symcryptk.dll).

Previously, pe_inspect.py only computed a flat integer division:
pdata_functions = pdata_size // 12.

Implement structured _inspect_pdata(img) using struct.iter_unpack for O(N)
performance on large function tables:
- Check bounds (BeginAddress, EndAddress, and UnwindInfoAddress <= size_of_image).
- Check strict non-decreasing ordering by BeginAddress.
- Detect overlapping function intervals (excluding adjacent and boundary zero-length entries).
- Track zero-length entries (BeginAddress == EndAddress).
- Check truncation, alignment, and unmapped directories.
- Return structured 'pdata' dictionary with summary metrics and sample_errors capped at 5.
- Keep 'pdata_functions' integer backward-compatible.
- Add 9 clean-room synthetic PE32+ unit tests in tests/test_pe_inspect.py covering all failure modes.

No game files. AI-assisted (Gemini).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:16:57 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 21:34 UTC · original

Rebased cleanly onto latest \main\ (\e34ff17e9), clearing stale base CI failures. Verified: all 74 tests in \ est_pe_inspect.py\ pass.

AI-assisted (Claude Code)

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 21:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/698#issuecomment-7175253271) Rebased cleanly onto latest \main\ (\e34ff17e9\), clearing stale base CI failures. Verified: all 74 tests in \ est_pe_inspect.py\ pass. AI-assisted (Claude Code)
This pull request has changes conflicting with the target branch.
  • tests/test_pe_inspect.py
  • tools/pe_inspect.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/698/head:github-bot/gh-698'
git switch 'github-bot/gh-698'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-698'
git switch 'github-bot/gh-698'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-698'
git switch 'github-bot/gh-698'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-698'
git switch 'main'
git merge --squash 'github-bot/gh-698'
git switch 'main'
git merge --ff-only 'github-bot/gh-698'
git switch 'main'
git merge 'github-bot/gh-698'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.