Skip to content

fix the Windows TEB/PEB/LDR structures, and Emulator(plat=...) - #6

Merged
williballenthin merged 1 commit into
masterfrom
fix-windows-structures
Nov 10, 2026
Merged

williballenthin merged 1 commit into
masterfrom
fix-windows-structures

Conversation

@williballenthin

Copy link
Copy Markdown
Owner

Fixes #3, fixes #4, fixes #5, and one more bug the new test ran into.

Testing

tests/test_plat_win.py builds the structures for two DLLs, on x86 and x64. It then walks InLoadOrderModuleList from the TEB, the way shellcode does, reading each BaseDllName and SizeOfImage at the documented offsets rather than through ucutils' own parsers.

  • Before the fixes, both tests fail.
  • With only the Emulator fix, the x86 test fails without the win32.py fix, and the x64 test fails without the win.py fix.
  • With all the fixes, the whole suite passes (23 tests).
  • black and isort are clean. ruff and mypy report the same findings as on master, none from these changes.

Generated by Claude Code

- x64: UNICODE_STRING.Buffer is at +0x8, after padding, not +0x4: use the
  pointer size, so the names in x64 LDR_DATA_TABLE_ENTRYs point at the
  strings (#3).
- x86: append_ldr_data_entry linked entries into lists at PEB_LDR_DATA
  +0x8/+0x10/+0x18, while the heads are at +0xC/+0x14/+0x1C, so the module
  lists stayed empty (#4).
- x86: write LDR_DATA_TABLE_ENTRY.SizeOfImage, at +0x20, and drop the print
  in parse_teb (#5).
- Emulator(..., plat=...) raised TypeError with unicorn 2.1, whose
  ucsubclass replaces __new__ with one that takes only (arch, mode), so
  scripts/scemu.py couldn't start. wrap it to accept the other arguments.

tests/test_plat_win.py builds the structures for two DLLs, on x86 and x64,
and walks InLoadOrderModuleList from the TEB, the way shellcode does,
reading each module's BaseDllName and SizeOfImage at the documented offsets.

Fixes #3, fixes #4, fixes #5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qxz5p5MiB2cdYjen8srqac
@williballenthin
williballenthin merged commit 74b5732 into master Nov 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants