| 150 | } |
| 151 | |
| 152 | static void test() |
| 153 | { |
| 154 | #define M68K_CODE "\xf0\x10\xf0\x00\x48\xaf\xff\xff\x7f\xff\x11\xb0\x01\x37\x7f\xff\xff\xff\x12\x34\x56\x78\x01\x33\x10\x10\x10\x10\x32\x32\x32\x32\x4C\x00\x54\x04\x48\xe7\xe0\x30\x4C\xDF\x0C\x07\xd4\x40\x87\x5a\x4e\x71\x02\xb4\xc0\xde\xc0\xde\x5c\x00\x1d\x80\x71\x12\x01\x23\xf2\x3c\x44\x22\x40\x49\x0e\x56\x54\xc5\xf2\x3c\x44\x00\x44\x7a\x00\x00\xf2\x00\x0a\x28\x4E\xB9\x00\x00\x00\x12\x4E\x75" |
| 155 | struct platform platforms[] = { |
| 156 | { |
| 157 | CS_ARCH_M68K, |
| 158 | (cs_mode)(CS_MODE_BIG_ENDIAN | CS_MODE_M68K_040), |
| 159 | (unsigned char*)M68K_CODE, |
| 160 | sizeof(M68K_CODE) - 1, |
| 161 | "M68K", |
| 162 | }, |
| 163 | }; |
| 164 | |
| 165 | uint64_t address = 0x01000; |
| 166 | cs_insn *insn; |
| 167 | int i; |
| 168 | size_t count; |
| 169 | |
| 170 | for (i = 0; i < sizeof(platforms)/sizeof(platforms[0]); i++) { |
| 171 | cs_err err = cs_open(platforms[i].arch, platforms[i].mode, &handle); |
| 172 | if (err) { |
| 173 | printf("Failed on cs_open() with error returned: %u\n", err); |
| 174 | abort(); |
| 175 | } |
| 176 | |
| 177 | cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON); |
| 178 | |
| 179 | count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn); |
| 180 | if (count) { |
| 181 | size_t j; |
| 182 | |
| 183 | printf("****************\n"); |
| 184 | printf("Platform: %s\n", platforms[i].comment); |
| 185 | print_string_hex("Code: ", platforms[i].code, platforms[i].size); |
| 186 | printf("Disasm:\n"); |
| 187 | |
| 188 | for (j = 0; j < count; j++) { |
| 189 | assert(address == insn[j].address && "this means the size of the previous instruction was incorrect"); |
| 190 | address += insn[j].size; |
| 191 | printf("0x%" PRIx64 ":\t%s\t%s\n", insn[j].address, insn[j].mnemonic, insn[j].op_str); |
| 192 | print_insn_detail(&insn[j]); |
| 193 | } |
| 194 | printf("0x%" PRIx64 ":\n", insn[j-1].address + insn[j-1].size); |
| 195 | |
| 196 | // free memory allocated by cs_disasm() |
| 197 | cs_free(insn, count); |
| 198 | } else { |
| 199 | printf("****************\n"); |
| 200 | printf("Platform: %s\n", platforms[i].comment); |
| 201 | print_string_hex("Code:", platforms[i].code, platforms[i].size); |
| 202 | printf("ERROR: Failed to disasm given code!\n"); |
| 203 | abort(); |
| 204 | } |
| 205 | |
| 206 | printf("\n"); |
| 207 | |
| 208 | cs_close(&handle); |
| 209 | } |
no test coverage detected
searching dependent graphs…