capstone/cstool/cstool_systemz.c

86 lines
2.4 KiB
C
Raw Permalink Normal View History

/* Capstone Disassembler Engine */
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
#include <stdio.h>
2016-10-21 09:03:27 +00:00
#include <capstone/capstone.h>
#include "cstool.h"
2024-09-14 08:57:54 +00:00
void print_insn_detail_systemz(csh handle, cs_insn *ins)
{
2024-09-14 08:57:54 +00:00
cs_systemz *systemz;
2016-10-21 08:42:47 +00:00
int i;
// detail can be NULL on "data" instruction if SKIPDATA option is turned ON
if (ins->detail == NULL)
return;
2024-09-14 08:57:54 +00:00
systemz = &(ins->detail->systemz);
if (systemz->op_count)
printf("\top_count: %u\n", systemz->op_count);
2016-10-21 08:42:47 +00:00
2024-09-14 08:57:54 +00:00
for (i = 0; i < systemz->op_count; i++) {
cs_systemz_op *op = &(systemz->operands[i]);
2016-10-21 08:42:47 +00:00
switch((int)op->type) {
default:
break;
2024-09-14 08:57:54 +00:00
case SYSTEMZ_OP_REG:
2016-10-21 08:42:47 +00:00
printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
break;
2024-09-14 08:57:54 +00:00
case SYSTEMZ_OP_IMM:
2016-10-21 08:42:47 +00:00
printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
break;
2024-09-14 08:57:54 +00:00
case SYSTEMZ_OP_MEM:
2016-10-21 08:42:47 +00:00
printf("\t\toperands[%u].type: MEM\n", i);
2024-09-14 08:57:54 +00:00
if (op->mem.base != SYSTEMZ_REG_INVALID)
2016-10-21 08:42:47 +00:00
printf("\t\t\toperands[%u].mem.base: REG = %s\n",
i, cs_reg_name(handle, op->mem.base));
2024-09-14 08:57:54 +00:00
if (op->mem.index != SYSTEMZ_REG_INVALID)
2016-10-21 08:42:47 +00:00
printf("\t\t\toperands[%u].mem.index: REG = %s\n",
i, cs_reg_name(handle, op->mem.index));
2024-09-14 08:57:54 +00:00
if (op->mem.length != 0) {
Coverity defects (#2469) * Fix CID 508418 - Uninitialized struct * Fix CID 509089 - Fix OOB read and write * Fix CID 509088 - OOB. Also adds tests and to ensure no OOB access. * Fix CID 509085 - Resource leak. * Fix CID 508414 and companions - Using undefined values. * Fix CID 508405 - Use of uninitialized value * Remove unnecessary and badly implemented dev fuzz code. * Fix CID 508396 - Uninitialzied variable. * Fix CID 508393, 508365 -- OOB read. * Fix CID 432207 - OVerlapping memory access. * Remove unused functions * Fix CID 432170 - Overlapping memory access. * Fix CID 166022 - Check for negative index * Let strncat not depend n src operand. * Fix 509083 and 509084 - NULL dereference * Remove duplicated code. * Initialize sysop * Fix resource leak * Remove unreachable code. * Remove duplicate code. * Add assert to check return value of cmoack * Fixed: d should be a signed value, since it is checked against < 0 * Add missing break. * Add NULL check * Fix signs of binary search comparisons. * Add explicit cast of or result * Fix correct scope of case. * Handle invalid integer type. * Return UINT_MAX instead of implicitly casted -1 * Remove dead code * Fix type of im * Fix type of d * Remove duplicated code. * Add returns after CS_ASSERTS * Check for len == 0 case. * Ensure shift operates on uint64 * Replace strcpy with strncpy. * Handle edge cases for 32bit rotate * Fix some out of enum warnings * Replace a strcpy with strncpy. * Fix increment of address * Skip some linting * Fix: set instruction id * Remove unused enum * Replace the last usages of strcpy with SStream functions. * Increase number of allowed AArch64 operands. * Check safety of incrementing t the next operand. * Fix naming of operand * Update python constants * Fix option setup of CS_OPT_DETAIL_REAL * Document DETAIL_REAL has to be used with CS_OPT_ON. * Run Coverity scan every Monday. * Remove dead code * Fix OOB read * Rename macro to reflect it is only used with sstreams * Fix rebase issues
2024-09-18 13:19:42 +00:00
printf("\t\t\toperands[%u].mem.length: 0x%" PRIx64 "\n", i, op->mem.length);
2024-09-14 08:57:54 +00:00
}
printf("\t\t\toperands[%u].mem.disp: 0x%" PRIx64 "\n", i, op->mem.disp);
switch(op->mem.am) {
default:
printf("\t\t\toperands[%u].mem.am: UNHANDLED\n", i);
break;
case SYSTEMZ_AM_BD:
printf("\t\t\toperands[%u].mem.am: SYSTEMZ_AM_BD\n", i);
break;
case SYSTEMZ_AM_BDX:
printf("\t\t\toperands[%u].mem.am: SYSTEMZ_AM_BDX\n", i);
break;
case SYSTEMZ_AM_BDL:
printf("\t\t\toperands[%u].mem.am: SYSTEMZ_AM_BDL\n", i);
break;
case SYSTEMZ_AM_BDR:
printf("\t\t\toperands[%u].mem.am: SYSTEMZ_AM_BDR\n", i);
break;
case SYSTEMZ_AM_BDV:
printf("\t\t\toperands[%u].mem.am: SYSTEMZ_AM_BDV\n", i);
break;
}
2016-10-21 08:42:47 +00:00
break;
}
2024-09-14 08:57:54 +00:00
switch(op->access) {
default:
break;
case CS_AC_READ:
printf("\t\toperands[%u].access: READ\n", i);
break;
case CS_AC_WRITE:
printf("\t\toperands[%u].access: WRITE\n", i);
break;
case CS_AC_READ | CS_AC_WRITE:
printf("\t\toperands[%u].access: READ | WRITE\n", i);
break;
}
2016-10-21 08:42:47 +00:00
}
2024-09-14 08:57:54 +00:00
if (systemz->cc != SYSTEMZ_CC_INVALID)
printf("\tCode condition: %u\n", systemz->cc);
}