diff options
Diffstat (limited to 'src/cli/disasm.c')
| -rw-r--r-- | src/cli/disasm.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cli/disasm.c b/src/cli/disasm.c index 82fd0bb..9b15e0c 100644 --- a/src/cli/disasm.c +++ b/src/cli/disasm.c @@ -76,7 +76,8 @@ static int slot(x86_reg reg) { // The instruction at `code`, which is at `addr`: its text into `text`, its // length returned; 0 where there is no instruction. With `regs` (the // thread's, about to run it), the memory it touches into `touches`, at -// most `*count` of them, and how many into `*count`. +// most `*count` of them, and how many into `*count`. A branch is told +// without them too, its target where the instruction alone says it. size_t zt_disasm(const uint8_t *code, size_t len, uint64_t addr, char *text, size_t cap, const uint64_t *regs, struct zt_touch *touches, size_t *count, struct zt_branch *branch) { if (!handle) { if (cs_open(CS_ARCH_X86, CS_MODE_64, &handle) != CS_ERR_OK) return 0; @@ -89,17 +90,17 @@ size_t zt_disasm(const uint8_t *code, size_t len, uint64_t addr, char *text, siz 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); - if (regs && branch && insn->detail) { + if (branch && insn->detail) { const cs_x86 *x = &insn->detail->x86; branch->kind = cs_insn_group(handle, insn, CS_GRP_RET) ? 3 : cs_insn_group(handle, insn, CS_GRP_CALL) ? 1 : cs_insn_group(handle, insn, CS_GRP_JUMP) ? 2 : 0; - branch->taken = holds(insn->id, regs[18], regs[11]); + branch->taken = regs ? holds(insn->id, regs[18], regs[11]) : 1; branch->indirect = 0; branch->target = 0; if (branch->kind == 1 || branch->kind == 2) { const cs_x86_op *op = &x->operands[0]; if (x->op_count < 1) branch->kind = 0; else if (op->type == X86_OP_IMM) branch->target = (uint64_t)op->imm; - else if (op->type == X86_OP_REG && slot(op->reg) >= 0) branch->target = regs[slot(op->reg)]; + else if (op->type == X86_OP_REG && slot(op->reg) >= 0) branch->target = regs ? regs[slot(op->reg)] : 0; else if (op->type == X86_OP_MEM) { // Its address is the first touch below: the target is what is there. branch->indirect = 1; |
