| 1 | /* Capstone Disassembler Engine */cxx . . $ `<file>/tests/test_x86.c`/ |
| 2 | /* By Nguyen Anh Quynh <[email protected]>, 2013 */ |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | |
| 7 | #include <capstone/platform.h>cxx . . $ `<file>/include/capstone/platform.h`/ |
| 8 | #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/ |
| 9 | |
| 10 | static cshcxx . . $ csh# handlecxx . . $ handle.; |
| 11 | |
| 12 | struct platformcxx . . $ platform# { |
| 13 | cs_archcxx . . $ cs_arch# archcxx . . $ platform#arch.; |
| 14 | cs_modecxx . . $ cs_mode# modecxx . . $ platform#mode.; |
| 15 | unsigned char *codecxx . . $ platform#code.; |
| 16 | size_t sizecxx . . $ platform#size.; |
| 17 | const char *commentcxx . . $ platform#comment.; |
| 18 | cs_opt_typecxx . . $ cs_opt_type# opt_typecxx . . $ platform#opt_type.; |
| 19 | cs_opt_valuecxx . . $ cs_opt_value# opt_valuecxx . . $ platform#opt_value.; |
| 20 | }; |
| 21 | |
| 22 | static void print_string_hexcxx . . $ print_string_hex(24a4beb24605093f).(const char *comment, unsigned char *str, size_t len) |
| 23 | { |
| 24 | unsigned char *c; |
| 25 | |
| 26 | printfcxx . . $ printf(581fddd72a8db8fc).("%s", comment); |
| 27 | for (c = str; c < str + len; c++) { |
| 28 | printfcxx . . $ printf(581fddd72a8db8fc).("0x%02x ", *c & 0xff); |
| 29 | } |
| 30 | |
| 31 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 32 | } |
| 33 | |
| 34 | static const char *get_eflag_namecxx . . $ get_eflag_name(30dde979ed96a187).(uint64_tcxx . . $ uint64_t# flag) |
| 35 | { |
| 36 | switch(flag) { |
| 37 | default: |
| 38 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 39 | case X86_EFLAGS_UNDEFINED_OFcxx . . $ `include/capstone/x86.h:116:9`!: |
| 40 | return "UNDEF_OF"; |
| 41 | case X86_EFLAGS_UNDEFINED_SFcxx . . $ `include/capstone/x86.h:117:9`!: |
| 42 | return "UNDEF_SF"; |
| 43 | case X86_EFLAGS_UNDEFINED_ZFcxx . . $ `include/capstone/x86.h:118:9`!: |
| 44 | return "UNDEF_ZF"; |
| 45 | case X86_EFLAGS_MODIFY_AFcxx . . $ `include/capstone/x86.h:76:9`!: |
| 46 | return "MOD_AF"; |
| 47 | case X86_EFLAGS_UNDEFINED_PFcxx . . $ `include/capstone/x86.h:119:9`!: |
| 48 | return "UNDEF_PF"; |
| 49 | case X86_EFLAGS_MODIFY_CFcxx . . $ `include/capstone/x86.h:77:9`!: |
| 50 | return "MOD_CF"; |
| 51 | case X86_EFLAGS_MODIFY_SFcxx . . $ `include/capstone/x86.h:78:9`!: |
| 52 | return "MOD_SF"; |
| 53 | case X86_EFLAGS_MODIFY_ZFcxx . . $ `include/capstone/x86.h:79:9`!: |
| 54 | return "MOD_ZF"; |
| 55 | case X86_EFLAGS_UNDEFINED_AFcxx . . $ `include/capstone/x86.h:120:9`!: |
| 56 | return "UNDEF_AF"; |
| 57 | case X86_EFLAGS_MODIFY_PFcxx . . $ `include/capstone/x86.h:80:9`!: |
| 58 | return "MOD_PF"; |
| 59 | case X86_EFLAGS_UNDEFINED_CFcxx . . $ `include/capstone/x86.h:121:9`!: |
| 60 | return "UNDEF_CF"; |
| 61 | case X86_EFLAGS_MODIFY_OFcxx . . $ `include/capstone/x86.h:81:9`!: |
| 62 | return "MOD_OF"; |
| 63 | case X86_EFLAGS_RESET_OFcxx . . $ `include/capstone/x86.h:97:9`!: |
| 64 | return "RESET_OF"; |
| 65 | case X86_EFLAGS_RESET_CFcxx . . $ `include/capstone/x86.h:98:9`!: |
| 66 | return "RESET_CF"; |
| 67 | case X86_EFLAGS_RESET_DFcxx . . $ `include/capstone/x86.h:99:9`!: |
| 68 | return "RESET_DF"; |
| 69 | case X86_EFLAGS_RESET_IFcxx . . $ `include/capstone/x86.h:100:9`!: |
| 70 | return "RESET_IF"; |
| 71 | case X86_EFLAGS_TEST_OFcxx . . $ `include/capstone/x86.h:109:9`!: |
| 72 | return "TEST_OF"; |
| 73 | case X86_EFLAGS_TEST_SFcxx . . $ `include/capstone/x86.h:110:9`!: |
| 74 | return "TEST_SF"; |
| 75 | case X86_EFLAGS_TEST_ZFcxx . . $ `include/capstone/x86.h:111:9`!: |
| 76 | return "TEST_ZF"; |
| 77 | case X86_EFLAGS_TEST_PFcxx . . $ `include/capstone/x86.h:112:9`!: |
| 78 | return "TEST_PF"; |
| 79 | case X86_EFLAGS_TEST_CFcxx . . $ `include/capstone/x86.h:113:9`!: |
| 80 | return "TEST_CF"; |
| 81 | case X86_EFLAGS_RESET_SFcxx . . $ `include/capstone/x86.h:101:9`!: |
| 82 | return "RESET_SF"; |
| 83 | case X86_EFLAGS_RESET_AFcxx . . $ `include/capstone/x86.h:102:9`!: |
| 84 | return "RESET_AF"; |
| 85 | case X86_EFLAGS_RESET_TFcxx . . $ `include/capstone/x86.h:103:9`!: |
| 86 | return "RESET_TF"; |
| 87 | case X86_EFLAGS_RESET_NTcxx . . $ `include/capstone/x86.h:104:9`!: |
| 88 | return "RESET_NT"; |
| 89 | case X86_EFLAGS_PRIOR_OFcxx . . $ `include/capstone/x86.h:87:9`!: |
| 90 | return "PRIOR_OF"; |
| 91 | case X86_EFLAGS_PRIOR_SFcxx . . $ `include/capstone/x86.h:88:9`!: |
| 92 | return "PRIOR_SF"; |
| 93 | case X86_EFLAGS_PRIOR_ZFcxx . . $ `include/capstone/x86.h:89:9`!: |
| 94 | return "PRIOR_ZF"; |
| 95 | case X86_EFLAGS_PRIOR_AFcxx . . $ `include/capstone/x86.h:90:9`!: |
| 96 | return "PRIOR_AF"; |
| 97 | case X86_EFLAGS_PRIOR_PFcxx . . $ `include/capstone/x86.h:91:9`!: |
| 98 | return "PRIOR_PF"; |
| 99 | case X86_EFLAGS_PRIOR_CFcxx . . $ `include/capstone/x86.h:92:9`!: |
| 100 | return "PRIOR_CF"; |
| 101 | case X86_EFLAGS_PRIOR_TFcxx . . $ `include/capstone/x86.h:93:9`!: |
| 102 | return "PRIOR_TF"; |
| 103 | case X86_EFLAGS_PRIOR_IFcxx . . $ `include/capstone/x86.h:94:9`!: |
| 104 | return "PRIOR_IF"; |
| 105 | case X86_EFLAGS_PRIOR_DFcxx . . $ `include/capstone/x86.h:95:9`!: |
| 106 | return "PRIOR_DF"; |
| 107 | case X86_EFLAGS_TEST_NTcxx . . $ `include/capstone/x86.h:114:9`!: |
| 108 | return "TEST_NT"; |
| 109 | case X86_EFLAGS_TEST_DFcxx . . $ `include/capstone/x86.h:115:9`!: |
| 110 | return "TEST_DF"; |
| 111 | case X86_EFLAGS_RESET_PFcxx . . $ `include/capstone/x86.h:105:9`!: |
| 112 | return "RESET_PF"; |
| 113 | case X86_EFLAGS_PRIOR_NTcxx . . $ `include/capstone/x86.h:96:9`!: |
| 114 | return "PRIOR_NT"; |
| 115 | case X86_EFLAGS_MODIFY_TFcxx . . $ `include/capstone/x86.h:82:9`!: |
| 116 | return "MOD_TF"; |
| 117 | case X86_EFLAGS_MODIFY_IFcxx . . $ `include/capstone/x86.h:83:9`!: |
| 118 | return "MOD_IF"; |
| 119 | case X86_EFLAGS_MODIFY_DFcxx . . $ `include/capstone/x86.h:84:9`!: |
| 120 | return "MOD_DF"; |
| 121 | case X86_EFLAGS_MODIFY_NTcxx . . $ `include/capstone/x86.h:85:9`!: |
| 122 | return "MOD_NT"; |
| 123 | case X86_EFLAGS_MODIFY_RFcxx . . $ `include/capstone/x86.h:86:9`!: |
| 124 | return "MOD_RF"; |
| 125 | case X86_EFLAGS_SET_CFcxx . . $ `include/capstone/x86.h:106:9`!: |
| 126 | return "SET_CF"; |
| 127 | case X86_EFLAGS_SET_DFcxx . . $ `include/capstone/x86.h:107:9`!: |
| 128 | return "SET_DF"; |
| 129 | case X86_EFLAGS_SET_IFcxx . . $ `include/capstone/x86.h:108:9`!: |
| 130 | return "SET_IF"; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | static const char *get_fpu_flag_namecxx . . $ get_fpu_flag_name(30dde979ed96a187).(uint64_tcxx . . $ uint64_t# flag) |
| 135 | { |
| 136 | switch (flag) { |
| 137 | default: |
| 138 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 139 | case X86_FPU_FLAGS_MODIFY_C0cxx . . $ `include/capstone/x86.h:136:9`!: |
| 140 | return "MOD_C0"; |
| 141 | case X86_FPU_FLAGS_MODIFY_C1cxx . . $ `include/capstone/x86.h:137:9`!: |
| 142 | return "MOD_C1"; |
| 143 | case X86_FPU_FLAGS_MODIFY_C2cxx . . $ `include/capstone/x86.h:138:9`!: |
| 144 | return "MOD_C2"; |
| 145 | case X86_FPU_FLAGS_MODIFY_C3cxx . . $ `include/capstone/x86.h:139:9`!: |
| 146 | return "MOD_C3"; |
| 147 | case X86_FPU_FLAGS_RESET_C0cxx . . $ `include/capstone/x86.h:140:9`!: |
| 148 | return "RESET_C0"; |
| 149 | case X86_FPU_FLAGS_RESET_C1cxx . . $ `include/capstone/x86.h:141:9`!: |
| 150 | return "RESET_C1"; |
| 151 | case X86_FPU_FLAGS_RESET_C2cxx . . $ `include/capstone/x86.h:142:9`!: |
| 152 | return "RESET_C2"; |
| 153 | case X86_FPU_FLAGS_RESET_C3cxx . . $ `include/capstone/x86.h:143:9`!: |
| 154 | return "RESET_C3"; |
| 155 | case X86_FPU_FLAGS_SET_C0cxx . . $ `include/capstone/x86.h:144:9`!: |
| 156 | return "SET_C0"; |
| 157 | case X86_FPU_FLAGS_SET_C1cxx . . $ `include/capstone/x86.h:145:9`!: |
| 158 | return "SET_C1"; |
| 159 | case X86_FPU_FLAGS_SET_C2cxx . . $ `include/capstone/x86.h:146:9`!: |
| 160 | return "SET_C2"; |
| 161 | case X86_FPU_FLAGS_SET_C3cxx . . $ `include/capstone/x86.h:147:9`!: |
| 162 | return "SET_C3"; |
| 163 | case X86_FPU_FLAGS_UNDEFINED_C0cxx . . $ `include/capstone/x86.h:148:9`!: |
| 164 | return "UNDEF_C0"; |
| 165 | case X86_FPU_FLAGS_UNDEFINED_C1cxx . . $ `include/capstone/x86.h:149:9`!: |
| 166 | return "UNDEF_C1"; |
| 167 | case X86_FPU_FLAGS_UNDEFINED_C2cxx . . $ `include/capstone/x86.h:150:9`!: |
| 168 | return "UNDEF_C2"; |
| 169 | case X86_FPU_FLAGS_UNDEFINED_C3cxx . . $ `include/capstone/x86.h:151:9`!: |
| 170 | return "UNDEF_C3"; |
| 171 | case X86_FPU_FLAGS_TEST_C0cxx . . $ `include/capstone/x86.h:152:9`!: |
| 172 | return "TEST_C0"; |
| 173 | case X86_FPU_FLAGS_TEST_C1cxx . . $ `include/capstone/x86.h:153:9`!: |
| 174 | return "TEST_C1"; |
| 175 | case X86_FPU_FLAGS_TEST_C2cxx . . $ `include/capstone/x86.h:154:9`!: |
| 176 | return "TEST_C2"; |
| 177 | case X86_FPU_FLAGS_TEST_C3cxx . . $ `include/capstone/x86.h:155:9`!: |
| 178 | return "TEST_C3"; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | static void print_insn_detailcxx . . $ print_insn_detail(cd3d2a1a07155122).(cshcxx . . $ csh# ud, cs_modecxx . . $ cs_mode# mode, cs_insncxx . . $ cs_insn# *ins) |
| 183 | { |
| 184 | int count, i; |
| 185 | cs_x86cxx . . $ cs_x86# *x86; |
| 186 | cs_regscxx . . $ cs_regs# regs_read, regs_write; |
| 187 | uint8_tcxx . . $ uint8_t# regs_read_count, regs_write_count; |
| 188 | |
| 189 | // detail can be NULL on "data" instruction if SKIPDATA option is turned ON |
| 190 | if (ins->detailcxx . . $ cs_insn#detail. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 191 | return; |
| 192 | |
| 193 | x86 = &(ins->detailcxx . . $ cs_insn#detail.->x86cxx . . $ cs_detail#$anonymous_type_0#x86.); |
| 194 | |
| 195 | print_string_hexcxx . . $ print_string_hex(24a4beb24605093f).("\tPrefix:", x86->prefixcxx . . $ cs_x86#prefix., 4); |
| 196 | |
| 197 | print_string_hexcxx . . $ print_string_hex(24a4beb24605093f).("\tOpcode:", x86->opcodecxx . . $ cs_x86#opcode., 4); |
| 198 | |
| 199 | printfcxx . . $ printf(581fddd72a8db8fc).("\trex: 0x%x\n", x86->rexcxx . . $ cs_x86#rex.); |
| 200 | |
| 201 | printfcxx . . $ printf(581fddd72a8db8fc).("\taddr_size: %u\n", x86->addr_sizecxx . . $ cs_x86#addr_size.); |
| 202 | printfcxx . . $ printf(581fddd72a8db8fc).("\tmodrm: 0x%x\n", x86->modrmcxx . . $ cs_x86#modrm.); |
| 203 | if (x86->encodingcxx . . $ cs_x86#encoding..modrm_offsetcxx . . $ cs_x86_encoding#modrm_offset. != 0) { |
| 204 | printfcxx . . $ printf(581fddd72a8db8fc).("\tmodrm_offset: 0x%x\n", x86->encodingcxx . . $ cs_x86#encoding..modrm_offsetcxx . . $ cs_x86_encoding#modrm_offset.); |
| 205 | } |
| 206 | |
| 207 | printfcxx . . $ printf(581fddd72a8db8fc).("\tdisp: 0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! "\n", x86->dispcxx . . $ cs_x86#disp.); |
| 208 | if (x86->encodingcxx . . $ cs_x86#encoding..disp_offsetcxx . . $ cs_x86_encoding#disp_offset. != 0) { |
| 209 | printfcxx . . $ printf(581fddd72a8db8fc).("\tdisp_offset: 0x%x\n", x86->encodingcxx . . $ cs_x86#encoding..disp_offsetcxx . . $ cs_x86_encoding#disp_offset.); |
| 210 | } |
| 211 | |
| 212 | if (x86->encodingcxx . . $ cs_x86#encoding..disp_sizecxx . . $ cs_x86_encoding#disp_size. != 0) { |
| 213 | printfcxx . . $ printf(581fddd72a8db8fc).("\tdisp_size: 0x%x\n", x86->encodingcxx . . $ cs_x86#encoding..disp_sizecxx . . $ cs_x86_encoding#disp_size.); |
| 214 | } |
| 215 | |
| 216 | // SIB is not available in 16-bit mode |
| 217 | if ((mode & CS_MODE_16cxx . . $ CS_MODE_16.) == 0) { |
| 218 | printfcxx . . $ printf(581fddd72a8db8fc).("\tsib: 0x%x\n", x86->sibcxx . . $ cs_x86#sib.); |
| 219 | if (x86->sib_basecxx . . $ cs_x86#sib_base. != X86_REG_INVALIDcxx . . $ X86_REG_INVALID.) |
| 220 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\tsib_base: %s\n", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., x86->sib_basecxx . . $ cs_x86#sib_base.)); |
| 221 | if (x86->sib_indexcxx . . $ cs_x86#sib_index. != X86_REG_INVALIDcxx . . $ X86_REG_INVALID.) |
| 222 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\tsib_index: %s\n", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., x86->sib_indexcxx . . $ cs_x86#sib_index.)); |
| 223 | if (x86->sib_scalecxx . . $ cs_x86#sib_scale. != 0) |
| 224 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\tsib_scale: %d\n", x86->sib_scalecxx . . $ cs_x86#sib_scale.); |
| 225 | } |
| 226 | |
| 227 | // XOP code condition |
| 228 | if (x86->xop_cccxx . . $ cs_x86#xop_cc. != X86_XOP_CC_INVALIDcxx . . $ X86_XOP_CC_INVALID.) { |
| 229 | printfcxx . . $ printf(581fddd72a8db8fc).("\txop_cc: %u\n", x86->xop_cccxx . . $ cs_x86#xop_cc.); |
| 230 | } |
| 231 | |
| 232 | // SSE code condition |
| 233 | if (x86->sse_cccxx . . $ cs_x86#sse_cc. != X86_SSE_CC_INVALIDcxx . . $ X86_SSE_CC_INVALID.) { |
| 234 | printfcxx . . $ printf(581fddd72a8db8fc).("\tsse_cc: %u\n", x86->sse_cccxx . . $ cs_x86#sse_cc.); |
| 235 | } |
| 236 | |
| 237 | // AVX code condition |
| 238 | if (x86->avx_cccxx . . $ cs_x86#avx_cc. != X86_AVX_CC_INVALIDcxx . . $ X86_AVX_CC_INVALID.) { |
| 239 | printfcxx . . $ printf(581fddd72a8db8fc).("\tavx_cc: %u\n", x86->avx_cccxx . . $ cs_x86#avx_cc.); |
| 240 | } |
| 241 | |
| 242 | // AVX Suppress All Exception |
| 243 | if (x86->avx_saecxx . . $ cs_x86#avx_sae.) { |
| 244 | printfcxx . . $ printf(581fddd72a8db8fc).("\tavx_sae: %u\n", x86->avx_saecxx . . $ cs_x86#avx_sae.); |
| 245 | } |
| 246 | |
| 247 | // AVX Rounding Mode |
| 248 | if (x86->avx_rmcxx . . $ cs_x86#avx_rm. != X86_AVX_RM_INVALIDcxx . . $ X86_AVX_RM_INVALID.) { |
| 249 | printfcxx . . $ printf(581fddd72a8db8fc).("\tavx_rm: %u\n", x86->avx_rmcxx . . $ cs_x86#avx_rm.); |
| 250 | } |
| 251 | |
| 252 | // Print out all immediate operands |
| 253 | count = cs_op_countcxx . . $ cs_op_count(2f5b4d866c2a3c8c).(ud, ins, X86_OP_IMMcxx . . $ X86_OP_IMM.); |
| 254 | if (count) { |
| 255 | printfcxx . . $ printf(581fddd72a8db8fc).("\timm_count: %u\n", count); |
| 256 | for (i = 1; i < count + 1; i++) { |
| 257 | int index = cs_op_indexcxx . . $ cs_op_index(d588ccf4d27e4ce9).(ud, ins, X86_OP_IMMcxx . . $ X86_OP_IMM., i); |
| 258 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\timms[%u]: 0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! "\n", i, x86->operandscxx . . $ cs_x86#operands.[index].immcxx . . $ cs_x86_op#$anonymous_type_0#imm.); |
| 259 | if (x86->encodingcxx . . $ cs_x86#encoding..imm_offsetcxx . . $ cs_x86_encoding#imm_offset. != 0) { |
| 260 | printfcxx . . $ printf(581fddd72a8db8fc).("\timm_offset: 0x%x\n", x86->encodingcxx . . $ cs_x86#encoding..imm_offsetcxx . . $ cs_x86_encoding#imm_offset.); |
| 261 | } |
| 262 | |
| 263 | if (x86->encodingcxx . . $ cs_x86#encoding..imm_sizecxx . . $ cs_x86_encoding#imm_size. != 0) { |
| 264 | printfcxx . . $ printf(581fddd72a8db8fc).("\timm_size: 0x%x\n", x86->encodingcxx . . $ cs_x86#encoding..imm_sizecxx . . $ cs_x86_encoding#imm_size.); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | if (x86->op_countcxx . . $ cs_x86#op_count.) |
| 270 | printfcxx . . $ printf(581fddd72a8db8fc).("\top_count: %u\n", x86->op_countcxx . . $ cs_x86#op_count.); |
| 271 | |
| 272 | // Print out all operands |
| 273 | for (i = 0; i < x86->op_countcxx . . $ cs_x86#op_count.; i++) { |
| 274 | cs_x86_opcxx . . $ cs_x86_op# *op = &(x86->operandscxx . . $ cs_x86#operands.[i]); |
| 275 | |
| 276 | switch((int)op->typecxx . . $ cs_x86_op#type.) { |
| 277 | case X86_OP_REGcxx . . $ X86_OP_REG.: |
| 278 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: REG = %s\n", i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->regcxx . . $ cs_x86_op#$anonymous_type_0#reg.)); |
| 279 | break; |
| 280 | case X86_OP_IMMcxx . . $ X86_OP_IMM.: |
| 281 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: IMM = 0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! "\n", i, op->immcxx . . $ cs_x86_op#$anonymous_type_0#imm.); |
| 282 | break; |
| 283 | case X86_OP_MEMcxx . . $ X86_OP_MEM.: |
| 284 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: MEM\n", i); |
| 285 | if (op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..segmentcxx . . $ x86_op_mem#segment. != X86_REG_INVALIDcxx . . $ X86_REG_INVALID.) |
| 286 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.segment: REG = %s\n", i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..segmentcxx . . $ x86_op_mem#segment.)); |
| 287 | if (op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..basecxx . . $ x86_op_mem#base. != X86_REG_INVALIDcxx . . $ X86_REG_INVALID.) |
| 288 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.base: REG = %s\n", i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..basecxx . . $ x86_op_mem#base.)); |
| 289 | if (op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..indexcxx . . $ x86_op_mem#index. != X86_REG_INVALIDcxx . . $ X86_REG_INVALID.) |
| 290 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.index: REG = %s\n", i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..indexcxx . . $ x86_op_mem#index.)); |
| 291 | if (op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..scalecxx . . $ x86_op_mem#scale. != 1) |
| 292 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.scale: %u\n", i, op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..scalecxx . . $ x86_op_mem#scale.); |
| 293 | if (op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..dispcxx . . $ x86_op_mem#disp. != 0) |
| 294 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.disp: 0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! "\n", i, op->memcxx . . $ cs_x86_op#$anonymous_type_0#mem..dispcxx . . $ x86_op_mem#disp.); |
| 295 | break; |
| 296 | default: |
| 297 | break; |
| 298 | } |
| 299 | |
| 300 | // AVX broadcast type |
| 301 | if (op->avx_bcastcxx . . $ cs_x86_op#avx_bcast. != X86_AVX_BCAST_INVALIDcxx . . $ X86_AVX_BCAST_INVALID.) |
| 302 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].avx_bcast: %u\n", i, op->avx_bcastcxx . . $ cs_x86_op#avx_bcast.); |
| 303 | |
| 304 | // AVX zero opmask {z} |
| 305 | if (op->avx_zero_opmaskcxx . . $ cs_x86_op#avx_zero_opmask. != falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!) |
| 306 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].avx_zero_opmask: TRUE\n", i); |
| 307 | |
| 308 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].size: %u\n", i, op->sizecxx . . $ cs_x86_op#size.); |
| 309 | |
| 310 | switch(op->accesscxx . . $ cs_x86_op#access.) { |
| 311 | default: |
| 312 | break; |
| 313 | case CS_AC_READcxx . . $ CS_AC_READ.: |
| 314 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].access: READ\n", i); |
| 315 | break; |
| 316 | case CS_AC_WRITEcxx . . $ CS_AC_WRITE.: |
| 317 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].access: WRITE\n", i); |
| 318 | break; |
| 319 | case CS_AC_READcxx . . $ CS_AC_READ. | CS_AC_WRITEcxx . . $ CS_AC_WRITE.: |
| 320 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].access: READ | WRITE\n", i); |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | // Print out all registers accessed by this instruction (either implicit or explicit) |
| 326 | if (!cs_regs_accesscxx . . $ cs_regs_access(4779ec53ff278361).(ud, ins, |
| 327 | regs_read, ®s_read_count, |
| 328 | regs_write, ®s_write_count)) { |
| 329 | if (regs_read_count) { |
| 330 | printfcxx . . $ printf(581fddd72a8db8fc).("\tRegisters read:"); |
| 331 | for(i = 0; i < regs_read_count; i++) { |
| 332 | printfcxx . . $ printf(581fddd72a8db8fc).(" %s", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., regs_read[i])); |
| 333 | } |
| 334 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 335 | } |
| 336 | |
| 337 | if (regs_write_count) { |
| 338 | printfcxx . . $ printf(581fddd72a8db8fc).("\tRegisters modified:"); |
| 339 | for(i = 0; i < regs_write_count; i++) { |
| 340 | printfcxx . . $ printf(581fddd72a8db8fc).(" %s", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., regs_write[i])); |
| 341 | } |
| 342 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | if (x86->eflagscxx . . $ cs_x86#$anonymous_type_1#eflags. || x86->fpu_flagscxx . . $ cs_x86#$anonymous_type_1#fpu_flags.) { |
| 347 | for(i = 0; i < ins->detailcxx . . $ cs_insn#detail.->groups_countcxx . . $ cs_detail#groups_count.; i++) { |
| 348 | if (ins->detailcxx . . $ cs_insn#detail.->groupscxx . . $ cs_detail#groups.[i] == X86_GRP_FPUcxx . . $ X86_GRP_FPU.) { |
| 349 | printfcxx . . $ printf(581fddd72a8db8fc).("\tFPU_FLAGS:"); |
| 350 | for(i = 0; i <= 63; i++) |
| 351 | if (x86->fpu_flagscxx . . $ cs_x86#$anonymous_type_1#fpu_flags. & ((uint64_tcxx . . $ uint64_t#)1 << i)) { |
| 352 | printfcxx . . $ printf(581fddd72a8db8fc).(" %s", get_fpu_flag_namecxx . . $ get_fpu_flag_name(30dde979ed96a187).((uint64_tcxx . . $ uint64_t#)1 << i)); |
| 353 | } |
| 354 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 355 | break; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if (i == ins->detailcxx . . $ cs_insn#detail.->groups_countcxx . . $ cs_detail#groups_count.) { |
| 360 | printfcxx . . $ printf(581fddd72a8db8fc).("\tEFLAGS:"); |
| 361 | for(i = 0; i <= 63; i++) |
| 362 | if (x86->eflagscxx . . $ cs_x86#$anonymous_type_1#eflags. & ((uint64_tcxx . . $ uint64_t#)1 << i)) { |
| 363 | printfcxx . . $ printf(581fddd72a8db8fc).(" %s", get_eflag_namecxx . . $ get_eflag_name(30dde979ed96a187).((uint64_tcxx . . $ uint64_t#)1 << i)); |
| 364 | } |
| 365 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 370 | } |
| 371 | |
| 372 | static void testcxx . . $ test(d878ad36e69247c7).() |
| 373 | { |
| 374 | #define X86_CODE64cxx . . $ `tests/test_x86.c:374:9`! "\x55\x48\x8b\x05\xb8\x13\x00\x00\xe9\xea\xbe\xad\xde\xff\x25\x23\x01\x00\x00\xe8\xdf\xbe\xad\xde\x74\xff" |
| 375 | #define X86_CODE16cxx . . $ `tests/test_x86.c:375:9`! "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00\x05\x23\x01\x00\x00\x36\x8b\x84\x91\x23\x01\x00\x00\x41\x8d\x84\x39\x89\x67\x00\x00\x8d\x87\x89\x67\x00\x00\xb4\xc6\x66\xe9\xb8\x00\x00\x00\x67\xff\xa0\x23\x01\x00\x00\x66\xe8\xcb\x00\x00\x00\x74\xfc" |
| 376 | #define X86_CODE32cxx . . $ `tests/test_x86.c:376:9`! "\x8d\x4c\x32\x08\x01\xd8\x81\xc6\x34\x12\x00\x00\x05\x23\x01\x00\x00\x36\x8b\x84\x91\x23\x01\x00\x00\x41\x8d\x84\x39\x89\x67\x00\x00\x8d\x87\x89\x67\x00\x00\xb4\xc6\xe9\xea\xbe\xad\xde\xff\xa0\x23\x01\x00\x00\xe8\xdf\xbe\xad\xde\x74\xff" |
| 377 | |
| 378 | struct platformcxx . . $ platform# platforms[] = { |
| 379 | { |
| 380 | CS_ARCH_X86cxx . . $ CS_ARCH_X86., |
| 381 | CS_MODE_16cxx . . $ CS_MODE_16., |
| 382 | (unsigned char *)X86_CODE16cxx . . $ `tests/test_x86.c:375:9`!, |
| 383 | sizeof(X86_CODE16cxx . . $ `tests/test_x86.c:375:9`!) - 1, |
| 384 | "X86 16bit (Intel syntax)" |
| 385 | }, |
| 386 | { |
| 387 | CS_ARCH_X86cxx . . $ CS_ARCH_X86., |
| 388 | CS_MODE_32cxx . . $ CS_MODE_32., |
| 389 | (unsigned char *)X86_CODE32cxx . . $ `tests/test_x86.c:376:9`!, |
| 390 | sizeof(X86_CODE32cxx . . $ `tests/test_x86.c:376:9`!) - 1, |
| 391 | "X86 32 (AT&T syntax)", |
| 392 | CS_OPT_SYNTAXcxx . . $ CS_OPT_SYNTAX., |
| 393 | CS_OPT_SYNTAX_ATTcxx . . $ CS_OPT_SYNTAX_ATT., |
| 394 | }, |
| 395 | { |
| 396 | CS_ARCH_X86cxx . . $ CS_ARCH_X86., |
| 397 | CS_MODE_32cxx . . $ CS_MODE_32., |
| 398 | (unsigned char *)X86_CODE32cxx . . $ `tests/test_x86.c:376:9`!, |
| 399 | sizeof(X86_CODE32cxx . . $ `tests/test_x86.c:376:9`!) - 1, |
| 400 | "X86 32 (Intel syntax)" |
| 401 | }, |
| 402 | { |
| 403 | CS_ARCH_X86cxx . . $ CS_ARCH_X86., |
| 404 | CS_MODE_64cxx . . $ CS_MODE_64., |
| 405 | (unsigned char *)X86_CODE64cxx . . $ `tests/test_x86.c:374:9`!, |
| 406 | sizeof(X86_CODE64cxx . . $ `tests/test_x86.c:374:9`!) - 1, |
| 407 | "X86 64 (Intel syntax)" |
| 408 | }, |
| 409 | }; |
| 410 | |
| 411 | uint64_tcxx . . $ uint64_t# address = 0x1000; |
| 412 | cs_insncxx . . $ cs_insn# *insn; |
| 413 | int i; |
| 414 | size_t count; |
| 415 | |
| 416 | for (i = 0; i < sizeof(platforms)/sizeof(platforms[0]); i++) { |
| 417 | cs_errcxx . . $ cs_err# err = cs_opencxx . . $ cs_open(b2cb849d8ee082cd).(platforms[i].archcxx . . $ platform#arch., platforms[i].modecxx . . $ platform#mode., &handlecxx . . $ handle.); |
| 418 | if (err) { |
| 419 | printfcxx . . $ printf(581fddd72a8db8fc).("Failed on cs_open() with error returned: %u\n", err); |
| 420 | abortcxx . . $ abort(8df32a62017fbbf6).(); |
| 421 | } |
| 422 | |
| 423 | if (platforms[i].opt_typecxx . . $ platform#opt_type.) |
| 424 | cs_optioncxx . . $ cs_option(a321a010700ba3d2).(handlecxx . . $ handle., platforms[i].opt_typecxx . . $ platform#opt_type., platforms[i].opt_valuecxx . . $ platform#opt_value.); |
| 425 | |
| 426 | cs_optioncxx . . $ cs_option(a321a010700ba3d2).(handlecxx . . $ handle., CS_OPT_DETAILcxx . . $ CS_OPT_DETAIL., CS_OPT_ONcxx . . $ CS_OPT_ON.); |
| 427 | |
| 428 | count = cs_disasmcxx . . $ cs_disasm(d552efbd9b22be5).(handlecxx . . $ handle., platforms[i].codecxx . . $ platform#code., platforms[i].sizecxx . . $ platform#size., address, 0, &insn); |
| 429 | if (count) { |
| 430 | size_t j; |
| 431 | |
| 432 | printfcxx . . $ printf(581fddd72a8db8fc).("****************\n"); |
| 433 | printfcxx . . $ printf(581fddd72a8db8fc).("Platform: %s\n", platforms[i].commentcxx . . $ platform#comment.); |
| 434 | print_string_hexcxx . . $ print_string_hex(24a4beb24605093f).("Code:", platforms[i].codecxx . . $ platform#code., platforms[i].sizecxx . . $ platform#size.); |
| 435 | printfcxx . . $ printf(581fddd72a8db8fc).("Disasm:\n"); |
| 436 | |
| 437 | for (j = 0; j < count; j++) { |
| 438 | printfcxx . . $ printf(581fddd72a8db8fc).("0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! ":\t%s\t%s\n", insn[j].addresscxx . . $ cs_insn#address., insn[j].mnemoniccxx . . $ cs_insn#mnemonic., insn[j].op_strcxx . . $ cs_insn#op_str.); |
| 439 | print_insn_detailcxx . . $ print_insn_detail(cd3d2a1a07155122).(handlecxx . . $ handle., platforms[i].modecxx . . $ platform#mode., &insn[j]); |
| 440 | } |
| 441 | printfcxx . . $ printf(581fddd72a8db8fc).("0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! ":\n", insn[j-1].addresscxx . . $ cs_insn#address. + insn[j-1].sizecxx . . $ cs_insn#size.); |
| 442 | |
| 443 | // free memory allocated by cs_disasm() |
| 444 | cs_freecxx . . $ cs_free(d0ae7023b33cf0c8).(insn, count); |
| 445 | } else { |
| 446 | printfcxx . . $ printf(581fddd72a8db8fc).("****************\n"); |
| 447 | printfcxx . . $ printf(581fddd72a8db8fc).("Platform: %s\n", platforms[i].commentcxx . . $ platform#comment.); |
| 448 | print_string_hexcxx . . $ print_string_hex(24a4beb24605093f).("Code:", platforms[i].codecxx . . $ platform#code., platforms[i].sizecxx . . $ platform#size.); |
| 449 | printfcxx . . $ printf(581fddd72a8db8fc).("ERROR: Failed to disasm given code!\n"); |
| 450 | abortcxx . . $ abort(8df32a62017fbbf6).(); |
| 451 | } |
| 452 | |
| 453 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 454 | |
| 455 | cs_closecxx . . $ cs_close(b9ab39fbab147149).(&handlecxx . . $ handle.); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | int maincxx . . $ main(d1b40a211a1a4e4c).() |
| 460 | { |
| 461 | testcxx . . $ test(d878ad36e69247c7).(); |
| 462 | |
| 463 | return 0; |
| 464 | } |