diff --git a/cstool/cstool.c b/cstool/cstool.c index 83abba1d6..6d7f19965 100644 --- a/cstool/cstool.c +++ b/cstool/cstool.c @@ -371,6 +371,18 @@ int main(int argc, char **argv) if (arch == CS_ARCH_XCORE) { print_insn_detail_xcore(handle, &insn[i]); } + + if (insn[i].detail->groups_count) { + int j; + + printf("\tGroups: "); + for(j = 0; j < insn[i].detail->groups_count; j++) { + printf("%s ", cs_group_name(handle, insn[i].detail->groups[j])); + } + printf("\n"); + } + + printf("\n"); } } cs_free(insn, count); diff --git a/cstool/cstool_arm.c b/cstool/cstool_arm.c index 5453fa696..987c6d274 100644 --- a/cstool/cstool_arm.c +++ b/cstool/cstool_arm.c @@ -110,6 +110,4 @@ void print_insn_detail_arm(csh handle, cs_insn *ins) if (arm->mem_barrier) printf("\tMemory-barrier: %u\n", arm->mem_barrier); - - printf("\n"); } diff --git a/cstool/cstool_arm64.c b/cstool/cstool_arm64.c index 25a402f8a..da456f0c4 100644 --- a/cstool/cstool_arm64.c +++ b/cstool/cstool_arm64.c @@ -99,6 +99,4 @@ void print_insn_detail_arm64(csh handle, cs_insn *ins) if (arm64->cc) printf("\tCode-condition: %u\n", arm64->cc); - - printf("\n"); } diff --git a/cstool/cstool_m68k.c b/cstool/cstool_m68k.c new file mode 100644 index 000000000..9a0fc7f30 --- /dev/null +++ b/cstool/cstool_m68k.c @@ -0,0 +1,121 @@ +// +// cstool_m68k.c +// +// +// Created by YUHANG TANG on 26/10/16. +// +// + +#include +#include + +void print_string_hex(char *comment, unsigned char *str, size_t len); + +static const char* s_addressing_modes[] = { + "", + + "Register Direct - Data", + "Register Direct - Address", + + "Register Indirect - Address", + "Register Indirect - Address with Postincrement", + "Register Indirect - Address with Predecrement", + "Register Indirect - Address with Displacement", + + "Address Register Indirect With Index - 8-bit displacement", + "Address Register Indirect With Index - Base displacement", + + "Memory indirect - Postindex", + "Memory indirect - Preindex", + + "Program Counter Indirect - with Displacement", + + "Program Counter Indirect with Index - with 8-Bit Displacement", + "Program Counter Indirect with Index - with Base Displacement", + + "Program Counter Memory Indirect - Postindexed", + "Program Counter Memory Indirect - Preindexed", + + "Absolute Data Addressing - Short", + "Absolute Data Addressing - Long", + "Immediate value", +}; + +static void print_read_write_regs(cs_detail* detail, csh handle) +{ + int i; + + for (i = 0; i < detail->regs_read_count; ++i) { + uint16_t reg_id = detail->regs_read[i]; + const char* reg_name = cs_reg_name(handle, reg_id); + printf("\treading from reg: %s\n", reg_name); + } + + for (i = 0; i < detail->regs_write_count; ++i) { + uint16_t reg_id = detail->regs_write[i]; + const char* reg_name = cs_reg_name(handle, reg_id); + printf("\twriting to reg: %s\n", reg_name); + } +} + +void print_insn_detail_m68k(csh handle, cs_insn *ins) +{ + cs_m68k* m68k; + cs_detail* detail; + int i; + + // detail can be NULL on "data" instruction if SKIPDATA option is turned ON + if (ins->detail == NULL) + return; + + detail = ins->detail; + m68k = &detail->m68k; + if (m68k->op_count) + printf("\top_count: %u\n", m68k->op_count); + + print_read_write_regs(detail, handle); + + printf("\tgroups_count: %u\n", detail->groups_count); + + for (i = 0; i < m68k->op_count; i++) { + cs_m68k_op* op = &(m68k->operands[i]); + + switch((int)op->type) { + default: + break; + case M68K_OP_REG: + printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg)); + break; + case M68K_OP_IMM: + printf("\t\toperands[%u].type: IMM = 0x%x\n", i, (int)op->imm); + break; + case M68K_OP_MEM: + printf("\t\toperands[%u].type: MEM\n", i); + if (op->mem.base_reg != M68K_REG_INVALID) + printf("\t\t\toperands[%u].mem.base: REG = %s\n", + i, cs_reg_name(handle, op->mem.base_reg)); + if (op->mem.index_reg != M68K_REG_INVALID) { + printf("\t\t\toperands[%u].mem.index: REG = %s\n", + i, cs_reg_name(handle, op->mem.index_reg)); + printf("\t\t\toperands[%u].mem.index: size = %c\n", + i, op->mem.index_size ? 'l' : 'w'); + } + if (op->mem.disp != 0) + printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp); + if (op->mem.scale != 0) + printf("\t\t\toperands[%u].mem.scale: %d\n", i, op->mem.scale); + + printf("\t\taddress mode: %s\n", s_addressing_modes[op->address_mode]); + break; + case M68K_OP_FP_SINGLE: + printf("\t\toperands[%u].type: FP_SINGLE\n", i); + printf("\t\t\toperands[%u].simm: %f\n", i, op->simm); + break; + case M68K_OP_FP_DOUBLE: + printf("\t\toperands[%u].type: FP_DOUBLE\n", i); + printf("\t\t\toperands[%u].dimm: %lf\n", i, op->dimm); + break; + } + } +} + diff --git a/cstool/cstool_mips.c b/cstool/cstool_mips.c index 45faba7b8..3beb7b323 100644 --- a/cstool/cstool_mips.c +++ b/cstool/cstool_mips.c @@ -44,6 +44,4 @@ void print_insn_detail_mips(csh handle, cs_insn *ins) } } - - printf("\n"); } diff --git a/cstool/cstool_ppc.c b/cstool/cstool_ppc.c index 771d88e71..a56fa40e7 100644 --- a/cstool/cstool_ppc.c +++ b/cstool/cstool_ppc.c @@ -86,6 +86,4 @@ void print_insn_detail_ppc(csh handle, cs_insn *ins) if (ppc->update_cr0) printf("\tUpdate-CR0: True\n"); - - printf("\n"); } diff --git a/cstool/cstool_sparc.c b/cstool/cstool_sparc.c index 34bd9ca7d..8e53230a2 100644 --- a/cstool/cstool_sparc.c +++ b/cstool/cstool_sparc.c @@ -51,6 +51,4 @@ void print_insn_detail_sparc(csh handle, cs_insn *ins) if (sparc->hint != 0) printf("\tHint code: %u\n", sparc->hint); - - printf("\n"); } diff --git a/cstool/cstool_systemz.c b/cstool/cstool_systemz.c index f35d6f836..eb5e2bc6c 100644 --- a/cstool/cstool_systemz.c +++ b/cstool/cstool_systemz.c @@ -53,6 +53,4 @@ void print_insn_detail_sysz(csh handle, cs_insn *ins) if (sysz->cc != 0) printf("\tCode condition: %u\n", sysz->cc); - - printf("\n"); } diff --git a/cstool/cstool_x86.c b/cstool/cstool_x86.c index 0b091af04..cc47a8b07 100644 --- a/cstool/cstool_x86.c +++ b/cstool/cstool_x86.c @@ -108,6 +108,4 @@ void print_insn_detail_x86(csh ud, cs_mode mode, cs_insn *ins) printf("\t\toperands[%u].size: %u\n", i, op->size); } - - printf("\n"); }