diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 13:36:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 14:12:08 -0300 |
| commit | 02aa51a6f54235cf18e627dbbfe21f21e502eb0b (patch) | |
| tree | a53416bdf0e5bb0ce80da63176fe13393c502a2c /src/cli/disasm.c | |
| parent | 16895292becf82f493aaced2b10f889bad436156 (diff) | |
| download | computeranim-02aa51a6f54235cf18e627dbbfe21f21e502eb0b.tar.gz computeranim-02aa51a6f54235cf18e627dbbfe21f21e502eb0b.zip | |
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.
Diffstat (limited to 'src/cli/disasm.c')
| -rw-r--r-- | src/cli/disasm.c | 20 |
1 files changed, 20 insertions, 0 deletions
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 <capstone/capstone.h> +#include <stdio.h> + +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; +} |
