A single-step x86-32 instruction walker for 32-bit Windows PE executables, written in Zig, with a native GTK4 + libadwaita dockable-workspace GUI.
It is not a debugger with breakpoints/run-to-cursor, and it is not a static-analysis/decompilation tool -- it only ever moves one instruction at a time, either forward or backward, either statically (Browsing) or by driving a real CPU core (Executing).
Two explicit, independent modes coexist in one window (the Execute toggle in the action bar and the Execution menu):
- Browsing (default): Step/Step Back only move a view cursor through the file's statically-decoded instruction stream -- no CPU/register/flag state anywhere, nothing is actually executing.
- Executing: Step/Step Back drive a real x86-32 CPU core (vendored from a separate project, see "Execution mode" below), actually mutating EIP, registers, flags, and memory. Turning Execute on snaps the view cursor to wherever real execution actually is.
Requires Zig 0.15.2, and the following system libraries:
- GTK4 (
libgtk-4-dev, for the window and native widgets -- text rendering comes from Pango/GTK directly, not a bundled font) - libadwaita 1.8+ (
libadwaita-1-dev-- forAdw.StyleManagertheming and the nativeAdwActionRow/AdwToggleGroup/AdwShortcutsDialogwidgets behind the Options and Keyboard Shortcuts dialogs) - capstone 5.0.7 (
libcapstone5-- the plain runtime package is enough;capstone.zighand-binds the small C API subset it needs, so no-dev/header package is required)
The x86-32 CPU core (vendor/tew-cpu/) needs no separate system dependency
at all -- it's vendored Zig source, compiled directly as part of this build.
zig build
build.zig links libcapstone.so.5 by direct path and forces the build
target to x86_64-linux-gnu, since a 32-bit Zig toolchain's "native" target
otherwise resolves to i386 even on a 64-bit host. GTK4 and libadwaita both
resolve normally via pkg-config. See the comments in build.zig if building
on a system where capstone's runtime lib lives somewhere other than
/usr/lib/x86_64-linux-gnu.
zig build run -- <path-to-pe-file> # graphical walker (Execute available)
zig build run -- --repl <path-to-pe-file> # text-mode REPL
zig build run -- --no-emulate <path-to-pe-file> # disables the Execute toggle entirely
or directly:
./zig-out/bin/pe-walker <path-to-pe-file>
A real Emulator (and therefore the Execute toggle) is built by default --
--no-emulate is opt-out, for a file you don't want executed at all.
zig build test
Covers PE header/section parsing (including the Import Directory), the
capstone FFI bindings, Walker navigation (step/step-back/jump), single-step
execution (memory_image.zig/emulator.zig), dockable-panel float/dock
mechanics (dock.zig), and the GUI's step/step-back/jump/section-click/
Execute-toggle logic in both Browsing and Executing modes -- all against a
small synthetic PE32 image built in src/test_support.zig, so nothing
depends on any real .exe being present on disk. Also runs the vendored
tew_cpu module's own test suite as a separate step.
Unlike the CPU/register-free design above, this genuinely is a limitation: the GUI tests need a real X11/Wayland display to run (GTK4 has no headless/dummy backend on this system -- confirmed by hand, see DEVELOPING.md). They'll pass in a normal desktop session but fail in a display-less CI environment.
See DEVELOPING.md for notes on adding new test files and on manually verifying GUI changes against a real window.
Only 32-bit (IMAGE_FILE_MACHINE_I386) PE32 executables are accepted.
Space/Down-- step (Browsing: moves the view cursor only; Executing: drives the real CPU)Up/Backspace-- step back (Executing: a real, bounded undo -- see "Execution mode" below)g-- focus the jump-to-address field (or just click it)Enterin the jump field, or theJumpbutton -- jump to the typed hex addressCtrl+F, or the sidebar search field -- filter the Sections list- Clicking a row in the Sections sidebar -- jump to that section's start
(fails the same way the hex-address
Jumpfield does for a non-executable section) - The Execute toggle (action bar or Execution menu, checkable) --
switch Browsing ↔ Executing; disabled entirely if launched with
--no-emulate Ctrl+=/Ctrl+-, or Program menu → Options… → Font Size -- change the code font size (10-18px, continuous)Ctrl+T, or Program menu → Options… → Theme -- toggle light/dark viaAdw.StyleManager- Each dockable panel's own
⤢/⇱header button, or the Windows menu -- float/dock the Sections & Imports, Registers & Stack, or Log panel ?, or Help menu → Keyboard Shortcuts -- open the native shortcuts overlay listing all of the aboveEscape, or theQuitbutton, or closing the window -- quit
- Program -- Open…/Save/Export…/Print… (not yet implemented -- this is a read-only walker), Options…, About Program, Quit
- Execution -- Execute (checkable), Step, Step Back
- Windows -- Float/Dock toggle for Sections & Imports, Registers & Stack, and Log (mirrors each panel's own header glyph)
- Search -- Find Address… (focuses the go-to field), Find Symbol… (focuses the sidebar search field)
- Help -- Keyboard Shortcuts
s (or blank line) = step, b = step back, g <hex> = jump,
c = show current instruction, q = quit. The REPL only ever drives the
static Walker (Browsing) -- there's no --execute-equivalent in text mode.
A dockable workspace, not one monolithic stacked window: a classic
per-application menu bar sits below the GtkHeaderBar (native minimize/
maximize/close), then an action bar, then the main body as nested
GtkPaneds:
- Sections & Imports sidebar (dockable) -- a Sections/Imports tab pill.
Sections: one row per PE section (colored swatch, name, R/W/X permission
string, VA, human-readable size, a short description for well-known
names, and a "no file data · uninitialized" note for any section with no
bytes backing it in the file, not just ones literally named
.bss). Imports: real DLL/function names and IAT thunk addresses parsed from the PE Import Directory (pe.zig'sparseImportTable) -- the function currently being called by the exec-pointer instruction is highlighted. - Listing (center, never floats) -- the operand column is syntax-colored
per token (registers, hex/decimal numbers, size keywords like
dword/ptr), computed directly from capstone's own operand text. Two independent cursor indicators: a light▸outline for the view cursor, a solid▶for the real execution pointer (which may coincide, or not, depending on mode). No cross-reference/function-label annotations -- pe-walker has no analysis to back those honestly. - Registers & Stack (dockable) -- a bare instrument-style register grid with a BROWSING/EXECUTING mode badge, and a Stack & Locals panel that stays an honest flat dword dump (real addresses/values, ESP/EBP rows tagged) rather than a fabricated typed struct tree -- pe-walker has no symbol/type information to draw one honestly.
- Log (dockable) -- every status message shown so far (colored
INFO/WARNprefixes), since the one-line status banner above the action bar only ever shows the latest message. - A slim status bar strip at the very bottom: a health indicator, the real
cursor address, its containing section, and a
FUN_<hex>label (a generic addressing convention, not a claim that the address is a function entry point).
See design/ for the mockup this layout was built to match, and
design/README.md for exactly which parts were adopted, adapted, or
deliberately left out.
"Stepping" only ever moves a cursor through addresses already present in the file:
- Forward stepping is a pure linear walk (decode the current instruction,
advance by its length). It does not follow
jmp/calltargets. - Step-back pops a small history stack of previously-visited cursor positions -- it is not a call/return stack.
- Jump-to-address moves the cursor directly to any address inside a mapped, executable section.
Branch targets (jmp, call, jcc) are visible as plain text in an
instruction's operand string (capstone renders them as absolute addresses),
so you can jump to one manually. Automatic branch-following is not
implemented.
By default (unless launched with --no-emulate), pe-walker builds a real,
flat memory image of the PE file (sections copied to their real virtual
addresses, plus a 1MiB stack) and starts a real x86-32 CPU core with EIP at
the entry point and ESP at the top of that stack -- this is what the
Execute toggle switches to. Each Step/Step Back while Executing runs (or
reverses) exactly one real instruction and shows the resulting state in two
real-widget panels:
- Registers/Flags -- EIP/EFLAGS/EAX-EDI in a grid, plus CF/PF/ZF/SF/DF/OF as small badges. Values that changed since the previous step are highlighted (standard debugger convention, matching x64dbg/OllyDbg/WinDbg), using GTK4's real theme colors so it adapts to light/dark/high-contrast.
- Stack & Locals -- 16 real dwords starting at ESP, read directly from the memory image (address + value, ESP/EBP rows tagged). No type or symbol inference -- pe-walker has no debug information to draw a typed stack frame honestly, so this is deliberately just real bytes at real addresses.
The static listing's view cursor follows the real EIP after every step while
Executing (so the solid ▶ always shows where execution actually is), but
turning Execute off leaves the view cursor free to browse anywhere without
touching real CPU state -- clicking a listing row, in either mode, only ever
moves the view cursor.
Step Back while Executing is a real, bounded undo, not a rewind trick:
Gui keeps a capped (64-deep) ring of full register+memory snapshots taken
before every real step (exec_history in src/ui/layout.zig), since the
underlying CPU core has no reverse-execution primitive of its own and the
existing fault-recovery Emulator.snapshot()/restore() never covers
memory writes. Once the ring is empty, Step Back is a no-op with a status
message rather than silently doing nothing.
What this does not do, on purpose:
- No Win32/CRT/DLL API emulation at all. The CPU core has zero OS awareness -- it's pure instruction execution against the flat memory image. Real Windows binaries call an imported kernel32/msvcrt/etc. function almost immediately during CRT startup, and since nothing meaningful is mapped at that address, execution will cleanly fault there (the Registers panel explains this in-app rather than showing a bare "faulted" message, and rewinds to the pre-step state so you're never left stuck looking at a dead end). Executing mode is for inspecting CRT startup/early init code with real register state, not for running a whole program.
- No free-running "Run" mode, no breakpoints, no watchpoints/logpoints.
The underlying CPU core supports all of these (
cpu_runcan execute many instructions at once and has built-in breakpoint/watchpoint/logpoint support), but pe-walker only ever calls it one instruction at a time via a singlestep(). Wiring up a real "run until X" mode is sensible future work, not part of this pass.
The CPU core itself is vendored from a separate project -- see "Third-party code" below.
| File | Purpose |
|---|---|
src/pe.zig |
PE header/section parsing, RVA<->file-offset mapping, R/W/X flags, Import Directory parsing |
src/capstone.zig |
Hand-written capstone FFI bindings (x86-32 only) |
src/walker.zig |
Instruction cursor + back-navigation history (no CPU state) |
src/memory_image.zig |
Builds a real, flat, zero-filled memory buffer (+ stack) for the Emulator |
src/emulator.zig |
Thin Zig wrapper around the vendored CPU core; single-step only |
src/ui/gtk.zig |
Thin cImport wrapper around GTK4 + libadwaita's C API, plus a g_signal_connect helper |
src/ui/layout.zig |
Builds the GTK4 widget tree (menu bar, action bar, nested dockable panes, Registers/Stack, Log, status bar) and wires it to the Walker and (optionally) the Emulator; the Browsing/Executing Mode and exec_history undo ring live here |
src/ui/dock.zig |
DockablePanel -- shared float/dock state machine for the three dockable panels |
src/ui/options_dialog.zig |
The Options dialog (Theme/Font/Font Size) |
src/ui/shortcuts_dialog.zig |
The native AdwShortcutsDialog-based Keyboard Shortcuts window |
src/main.zig |
CLI parsing and wiring |
vendor/tew-cpu/ |
Vendored x86-32 CPU core (LGPL-3.0-or-later; see below) |
design/ |
Reference mockup the GUI's visual design was built to match |
vendor/tew-cpu/ is vendored (copied, not a submodule) from
git@github.com:drazisil/tew.git's cpu/ subdirectory, a from-scratch
x86-32 CPU core with no Windows/Win32 awareness of its own. That project is
GPL-3.0 overall, but cpu/ was relicensed LGPL-3.0-or-later by its sole
author specifically for reuse here, so pe-walker's own licensing (currently
undecided) isn't constrained by it. See vendor/tew-cpu/LICENSE and
vendor/tew-cpu/PROVENANCE.md for the exact commit this was copied from.
- Automatic jmp/call-following or a call/return navigation stack (static walker).
- x86-64 support.
- Any Win32/CRT/DLL API emulation while Executing -- see "Execution mode" above.
- A free-running "Run" mode, breakpoints, watchpoints, and logpoints -- the underlying CPU core supports all of these, but pe-walker only calls it one instruction at a time for now. See "Execution mode" above.
- A typed Stack & Locals tree (struct/field names,
LDR_DATA_TABLE_ENTRY- style expansion) -- pe-walker has no symbol/debug-info parser, and fabricating type names for real memory bytes would violate this project's mock-data-honesty rule (seeDEVELOPING.md). Stack & Locals stays a flat, real dword dump. Seedesign/README.md. - String cross-references (static walker).