diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-11 20:08:00 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 20:08:07 -0300 |
| commit | 0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594 (patch) | |
| tree | bb820b7e39994177b6abc503ab5b980603d34513 /src/cli/show.zig | |
| parent | cc2059e39047cafe1886dc17084855ddd0c52b01 (diff) | |
| download | computeranim-0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594.tar.gz computeranim-0ec2376cae2fdfc50e90d930ebc86c7a5b7f5594.zip | |
trace: what push, call and ret touch; names for data; the stack's roles, sharper
For a disassembly that points at the stack word it touched. The stack's
own instructions have touches (push, call and enter write at rsp-8; pop
and ret read at rsp; leave at rbp), and a rep string instruction its
whole range. An address a global or static object holds is named
(head+0, libc.so.6!main_arena+96). The saved rbp has its role at the
push that makes it; every local in a shared word is given; the stack
protector's copy is found by seeing its store; ztrace show labels each
stack word. Six bytes a moment and 3% slower on the list by instruction.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'src/cli/show.zig')
| -rw-r--r-- | src/cli/show.zig | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/cli/show.zig b/src/cli/show.zig index 032538f..e7c552c 100644 --- a/src/cli/show.zig +++ b/src/cli/show.zig @@ -10,7 +10,9 @@ pub const usage = \\With one (negative counts from the end), the context as of that moment, \\pwndbg's way: each thread's registers, every one followed as far as it \\points (a name for code, a string where there is one), the instructions - \\at the pc, the top of the stack followed likewise, the source line and + \\at the pc, the top of the stack followed likewise, each word with what + \\it is where the recording says (saved rbp, return address, a local by + \\name, the canary's copy, argv[1]), the source line and \\the open calls; then glibc's heap when it was recorded (record --heap: \\its chunks, the tcache and the bins, each chunk on a list followed by its \\link as stored, in brackets, where safe-linking changed it), the live @@ -82,6 +84,34 @@ fn telescope(m: zt.store.Moment, w: *std.Io.Writer, value: u64, colour: bool) !v } } +/// What a stack word is (`zt.telescope.slots`), after its chain: `saved +/// rbp`, `return address`, a local by name (`buf+8` a word into it, `i[0..4], +/// n[4..8]` where it fills part of the word), `argv[1]`; nothing where the +/// recording does not say. `word` is what it holds: 0 ends argv and envp. +fn role(w: *std.Io.Writer, slot: zt.telescope.Slot, word: u64, colour: bool) !void { + if (slot.role == .none) return; + try w.writeAll(if (colour) " \x1b[2m" else " "); + switch (slot.role) { + .none => {}, + .saved => |reg| try w.print("saved {s}", .{reg}), + .return_address => try w.writeAll("return address"), + .local => |first| for ([_]?zt.telescope.Local{first} ++ slot.also, 0..) |each, i| { + const l = each orelse break; + if (i > 0) try w.writeAll(", "); + try w.writeAll(l.name); + if (l.offset > 0) try w.print("+{x}", .{l.offset}); + const from: i64 = @max(0, -l.offset); + const to: i64 = if (l.size == 0) 8 else @min(8, @as(i64, l.size) - l.offset); + if (from > 0 or to < 8) try w.print("[{d}..{d}]", .{ from, to }); + }, + .argc => try w.writeAll("argc"), + .argv => |i| if (word == 0) try w.writeAll("argv end") else try w.print("argv[{d}]", .{i}), + .envp => |i| if (word == 0) try w.writeAll("envp end") else try w.print("envp[{d}]", .{i}), + .auxv => |i| try w.print("auxv[{d}]", .{i}), + } + if (colour) try w.writeAll("\x1b[0m"); +} + pub fn state(arena: std.mem.Allocator, trace: *zt.Trace, index: u64, w: *std.Io.Writer, colour: bool) !void { const m = try trace.moment(index); try w.print("moment {d} of {d}, {d} events so far\n", .{ index, trace.len, try m.count() }); @@ -114,16 +144,18 @@ pub fn state(arena: std.mem.Allocator, trace: *zt.Trace, index: u64, w: *std.Io. if (pc >= regs.rip) below += 1; pc += insn.len; } - // The top of the stack, a word a row. + // The top of the stack, a word a row, and what each word is. var words: [8]u64 = undefined; var known: [64]bool = undefined; try m.read(regs.rsp, std.mem.sliceAsBytes(&words), &known); + var slots: [8]zt.telescope.Slot = undefined; + _ = try zt.telescope.slots(m, ®s, regs.rsp, &slots); if (known[0]) try w.writeAll("\n"); - for (words, 0..) |word, i| { + for (words, slots, 0..) |word, slot, i| { if (!known[i * 8]) break; try w.print(" {x:0>2}:{x:0>4}│ {s} ", .{ i, i * 8, if (i == 0) "rsp" else " " }); try telescope(m, w, regs.rsp + i * 8, colour); - _ = word; + try role(w, slot, word, colour); try w.writeAll("\n"); } } |
