From 02aa51a6f54235cf18e627dbbfe21f21e502eb0b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 13:36:32 -0300 Subject: context: disassembly, telescopes and names in every stop; strings as one table For a viewer to show what pwndbg's context shows, the debugger records it while the memory is there: each register and the top of the stack followed as pointers three deep (--telescope), every code address met named, eight instructions from the pc disassembled by capstone (built from source for x86, into the command only; pinned as in 03-codenomicom). zt.telescope reads a chain back with the kind of memory each link points into, and ztrace show prints the context, coloured on a terminal as pwndbg colours. The thirty thousand strings of a small run showed that a string map in each keyframe costs 700 bytes of tree a string: strings are now one table for the recording, appended a batch and read whole at open. fib(12) by instruction with everything on: 9 MB, 71 000 moments/s. --- src/cli/disasm.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/cli/disasm.c (limited to 'src/cli/disasm.c') diff --git a/src/cli/disasm.c b/src/cli/disasm.c new file mode 100644 index 0000000..db19059 --- /dev/null +++ b/src/cli/disasm.c @@ -0,0 +1,20 @@ +// The one thing asked of capstone, in C so that its structs stay its own. +#include +#include + +static csh handle; + +// The instruction at `code`, which is at `addr`: its text into `text`, its +// length returned. 0 where there is no instruction. +size_t zt_disasm(const uint8_t *code, size_t len, uint64_t addr, char *text, size_t cap) { + if (!handle) { + if (cs_open(CS_ARCH_X86, CS_MODE_64, &handle) != CS_ERR_OK) return 0; + cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_INTEL); + } + cs_insn *insn; + if (cs_disasm(handle, code, len, addr, 1, &insn) != 1) return 0; + size_t size = insn->size; + snprintf(text, cap, insn->op_str[0] ? "%s %s" : "%s", insn->mnemonic, insn->op_str); + cs_free(insn, 1); + return size; +} -- cgit v1.3