Home | History | Annotate | Download | only in cstool
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #include <capstone.h>
      5 
      6 void print_string_hex(char *comment, unsigned char *str, size_t len);
      7 
      8 void print_insn_detail_arm(csh handle, cs_insn *ins)
      9 {
     10 	cs_arm *arm;
     11 	int i;
     12 
     13 	// detail can be NULL on "data" instruction if SKIPDATA option is turned ON
     14 	if (ins->detail == NULL)
     15 		return;
     16 
     17 	arm = &(ins->detail->arm);
     18 
     19 	if (arm->op_count)
     20 		printf("\top_count: %u\n", arm->op_count);
     21 
     22 	for (i = 0; i < arm->op_count; i++) {
     23 		cs_arm_op *op = &(arm->operands[i]);
     24 		switch((int)op->type) {
     25 			default:
     26 				break;
     27 			case ARM_OP_REG:
     28 				printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
     29 				break;
     30 			case ARM_OP_IMM:
     31 				printf("\t\toperands[%u].type: IMM = 0x%x\n", i, op->imm);
     32 				break;
     33 			case ARM_OP_FP:
     34 #if defined(_KERNEL_MODE)
     35 				// Issue #681: Windows kernel does not support formatting float point
     36 				printf("\t\toperands[%u].type: FP = <float_point_unsupported>\n", i);
     37 #else
     38 				printf("\t\toperands[%u].type: FP = %f\n", i, op->fp);
     39 #endif
     40 				break;
     41 			case ARM_OP_MEM:
     42 				printf("\t\toperands[%u].type: MEM\n", i);
     43 				if (op->mem.base != X86_REG_INVALID)
     44 					printf("\t\t\toperands[%u].mem.base: REG = %s\n",
     45 							i, cs_reg_name(handle, op->mem.base));
     46 				if (op->mem.index != X86_REG_INVALID)
     47 					printf("\t\t\toperands[%u].mem.index: REG = %s\n",
     48 							i, cs_reg_name(handle, op->mem.index));
     49 				if (op->mem.scale != 1)
     50 					printf("\t\t\toperands[%u].mem.scale: %u\n", i, op->mem.scale);
     51 				if (op->mem.disp != 0)
     52 					printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
     53 
     54 				break;
     55 			case ARM_OP_PIMM:
     56 				printf("\t\toperands[%u].type: P-IMM = %u\n", i, op->imm);
     57 				break;
     58 			case ARM_OP_CIMM:
     59 				printf("\t\toperands[%u].type: C-IMM = %u\n", i, op->imm);
     60 				break;
     61 			case ARM_OP_SETEND:
     62 				printf("\t\toperands[%u].type: SETEND = %s\n", i, op->setend == ARM_SETEND_BE? "be" : "le");
     63 				break;
     64 			case ARM_OP_SYSREG:
     65 				printf("\t\toperands[%u].type: SYSREG = %u\n", i, op->reg);
     66 				break;
     67 		}
     68 
     69 		if (op->shift.type != ARM_SFT_INVALID && op->shift.value) {
     70 			if (op->shift.type < ARM_SFT_ASR_REG)
     71 				// shift with constant value
     72 				printf("\t\t\tShift: %u = %u\n", op->shift.type, op->shift.value);
     73 			else
     74 				// shift with register
     75 				printf("\t\t\tShift: %u = %s\n", op->shift.type,
     76 						cs_reg_name(handle, op->shift.value));
     77 		}
     78 
     79 		if (op->vector_index != -1) {
     80 			printf("\t\toperands[%u].vector_index = %u\n", i, op->vector_index);
     81 		}
     82 
     83 		if (op->subtracted)
     84 			printf("\t\tSubtracted: True\n");
     85 	}
     86 
     87 	if (arm->cc != ARM_CC_AL && arm->cc != ARM_CC_INVALID)
     88 		printf("\tCode condition: %u\n", arm->cc);
     89 
     90 	if (arm->update_flags)
     91 		printf("\tUpdate-flags: True\n");
     92 
     93 	if (arm->writeback)
     94 		printf("\tWrite-back: True\n");
     95 
     96 	if (arm->cps_mode)
     97 		printf("\tCPSI-mode: %u\n", arm->cps_mode);
     98 
     99 	if (arm->cps_flag)
    100 		printf("\tCPSI-flag: %u\n", arm->cps_flag);
    101 
    102 	if (arm->vector_data)
    103 		printf("\tVector-data: %u\n", arm->vector_data);
    104 
    105 	if (arm->vector_size)
    106 		printf("\tVector-size: %u\n", arm->vector_size);
    107 
    108 	if (arm->usermode)
    109 		printf("\tUser-mode: True\n");
    110 
    111 	if (arm->mem_barrier)
    112 		printf("\tMemory-barrier: %u\n", arm->mem_barrier);
    113 }
    114