Debian Codegraph @

tests/test_systemz.c

raw symbols SCIP
1 /* Capstone Disassembler Engine */cxx . . $ `<file>/tests/test_systemz.c`/
2 /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */
3
4 #include <stdio.h>
5
6 #include <capstone/platform.h>cxx . . $ `<file>/include/capstone/platform.h`/
7 #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/
8
9 struct platformcxx . . $ platform# {
10 cs_archcxx . . $ cs_arch# archcxx . . $ platform#arch.;
11 cs_modecxx . . $ cs_mode# modecxx . . $ platform#mode.;
12 unsigned char *codecxx . . $ platform#code.;
13 size_t sizecxx . . $ platform#size.;
14 const char *commentcxx . . $ platform#comment.;
15 };
16
17 static cshcxx . . $ csh# handlecxx . . $ handle.;
18
19 static void print_string_hexcxx . . $ print_string_hex(24a4beb24605093f).(const char *comment, unsigned char *str, size_t len)
20 {
21 unsigned char *c;
22
23 printfcxx . . $ printf(581fddd72a8db8fc).("%s", comment);
24 for (c = str; c < str + len; c++) {
25 printfcxx . . $ printf(581fddd72a8db8fc).("0x%02x ", *c & 0xff);
26 }
27
28 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
29 }
30
31 static void print_insn_detailcxx . . $ print_insn_detail(ecef60df25d96a55).(cs_insncxx . . $ cs_insn# *ins)
32 {
33 cs_syszcxx . . $ cs_sysz# *sysz;
34 int i;
35
36 // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
37 if (ins->detailcxx . . $ cs_insn#detail. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!)
38 return;
39
40 sysz = &(ins->detailcxx . . $ cs_insn#detail.->syszcxx . . $ cs_detail#$anonymous_type_0#sysz.);
41 if (sysz->op_countcxx . . $ cs_sysz#op_count.)
42 printfcxx . . $ printf(581fddd72a8db8fc).("\top_count: %u\n", sysz->op_countcxx . . $ cs_sysz#op_count.);
43
44 for (i = 0; i < sysz->op_countcxx . . $ cs_sysz#op_count.; i++) {
45 cs_sysz_opcxx . . $ cs_sysz_op# *op = &(sysz->operandscxx . . $ cs_sysz#operands.[i]);
46 switch((int)op->typecxx . . $ cs_sysz_op#type.) {
47 default:
48 break;
49 case SYSZ_OP_REGcxx . . $ SYSZ_OP_REG.:
50 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: REG = %s\n", i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->regcxx . . $ cs_sysz_op#$anonymous_type_0#reg.));
51 break;
52 case SYSZ_OP_ACREGcxx . . $ SYSZ_OP_ACREG.:
53 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: ACREG = %u\n", i, op->regcxx . . $ cs_sysz_op#$anonymous_type_0#reg.);
54 break;
55 case SYSZ_OP_IMMcxx . . $ SYSZ_OP_IMM.:
56 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: IMM = 0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! "\n", i, op->immcxx . . $ cs_sysz_op#$anonymous_type_0#imm.);
57 break;
58 case SYSZ_OP_MEMcxx . . $ SYSZ_OP_MEM.:
59 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: MEM\n", i);
60 if (op->memcxx . . $ cs_sysz_op#$anonymous_type_0#mem..basecxx . . $ sysz_op_mem#base. != SYSZ_REG_INVALIDcxx . . $ SYSZ_REG_INVALID.)
61 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.base: REG = %s\n",
62 i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->memcxx . . $ cs_sysz_op#$anonymous_type_0#mem..basecxx . . $ sysz_op_mem#base.));
63 if (op->memcxx . . $ cs_sysz_op#$anonymous_type_0#mem..indexcxx . . $ sysz_op_mem#index. != SYSZ_REG_INVALIDcxx . . $ SYSZ_REG_INVALID.)
64 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.index: REG = %s\n",
65 i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->memcxx . . $ cs_sysz_op#$anonymous_type_0#mem..indexcxx . . $ sysz_op_mem#index.));
66 if (op->memcxx . . $ cs_sysz_op#$anonymous_type_0#mem..lengthcxx . . $ sysz_op_mem#length. != 0)
67 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.length: 0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! "\n", i, op->memcxx . . $ cs_sysz_op#$anonymous_type_0#mem..lengthcxx . . $ sysz_op_mem#length.);
68 if (op->memcxx . . $ cs_sysz_op#$anonymous_type_0#mem..dispcxx . . $ sysz_op_mem#disp. != 0)
69 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.disp: 0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! "\n", i, op->memcxx . . $ cs_sysz_op#$anonymous_type_0#mem..dispcxx . . $ sysz_op_mem#disp.);
70
71 break;
72 }
73 }
74
75 if (sysz->cccxx . . $ cs_sysz#cc. != 0)
76 printfcxx . . $ printf(581fddd72a8db8fc).("\tCode condition: %u\n", sysz->cccxx . . $ cs_sysz#cc.);
77
78 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
79 }
80
81 static void testcxx . . $ test(d878ad36e69247c7).()
82 {
83 #define SYSZ_CODEcxx . . $ `tests/test_systemz.c:83:9`! "\xed\x00\x00\x00\x00\x1a\x5a\x0f\x1f\xff\xc2\x09\x80\x00\x00\x00\x07\xf7\xeb\x2a\xff\xff\x7f\x57\xe3\x01\xff\xff\x7f\x57\xeb\x00\xf0\x00\x00\x24\xb2\x4f\x00\x78\xec\x18\x00\x00\xc1\x7f"
84
85 struct platformcxx . . $ platform# platforms[] = {
86 {
87 CS_ARCH_SYSZcxx . . $ CS_ARCH_SYSZ.,
88 CS_MODE_BIG_ENDIANcxx . . $ CS_MODE_BIG_ENDIAN.,
89 (unsigned char*)SYSZ_CODEcxx . . $ `tests/test_systemz.c:83:9`!,
90 sizeof(SYSZ_CODEcxx . . $ `tests/test_systemz.c:83:9`!) - 1,
91 "SystemZ",
92 },
93 };
94
95 uint64_tcxx . . $ uint64_t# address = 0x1000;
96 cs_insncxx . . $ cs_insn# *insn;
97 int i;
98 size_t count;
99
100 for (i = 0; i < sizeof(platforms)/sizeof(platforms[0]); i++) {
101 cs_errcxx . . $ cs_err# err = cs_opencxx . . $ cs_open(b2cb849d8ee082cd).(platforms[i].archcxx . . $ platform#arch., platforms[i].modecxx . . $ platform#mode., &handlecxx . . $ handle.);
102 if (err) {
103 printfcxx . . $ printf(581fddd72a8db8fc).("Failed on cs_open() with error returned: %u\n", err);
104 abortcxx . . $ abort(8df32a62017fbbf6).();
105 }
106
107 cs_optioncxx . . $ cs_option(a321a010700ba3d2).(handlecxx . . $ handle., CS_OPT_DETAILcxx . . $ CS_OPT_DETAIL., CS_OPT_ONcxx . . $ CS_OPT_ON.);
108
109 count = cs_disasmcxx . . $ cs_disasm(d552efbd9b22be5).(handlecxx . . $ handle., platforms[i].codecxx . . $ platform#code., platforms[i].sizecxx . . $ platform#size., address, 0, &insn);
110 if (count) {
111 size_t j;
112
113 printfcxx . . $ printf(581fddd72a8db8fc).("****************\n");
114 printfcxx . . $ printf(581fddd72a8db8fc).("Platform: %s\n", platforms[i].commentcxx . . $ platform#comment.);
115 print_string_hexcxx . . $ print_string_hex(24a4beb24605093f).("Code:", platforms[i].codecxx . . $ platform#code., platforms[i].sizecxx . . $ platform#size.);
116 printfcxx . . $ printf(581fddd72a8db8fc).("Disasm:\n");
117
118 for (j = 0; j < count; j++) {
119 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.);
120 print_insn_detailcxx . . $ print_insn_detail(ecef60df25d96a55).(&insn[j]);
121 }
122 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.);
123
124 // free memory allocated by cs_disasm()
125 cs_freecxx . . $ cs_free(d0ae7023b33cf0c8).(insn, count);
126 } else {
127 printfcxx . . $ printf(581fddd72a8db8fc).("****************\n");
128 printfcxx . . $ printf(581fddd72a8db8fc).("Platform: %s\n", platforms[i].commentcxx . . $ platform#comment.);
129 print_string_hexcxx . . $ print_string_hex(24a4beb24605093f).("Code:", platforms[i].codecxx . . $ platform#code., platforms[i].sizecxx . . $ platform#size.);
130 printfcxx . . $ printf(581fddd72a8db8fc).("ERROR: Failed to disasm given code!\n");
131 abortcxx . . $ abort(8df32a62017fbbf6).();
132 }
133
134 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
135
136 cs_closecxx . . $ cs_close(b9ab39fbab147149).(&handlecxx . . $ handle.);
137 }
138 }
139
140 int maincxx . . $ main(d1b40a211a1a4e4c).()
141 {
142 testcxx . . $ test(d878ad36e69247c7).();
143
144 return 0;
145 }