| 370 | } |
| 371 | |
| 372 | static void test() |
| 373 | { |
| 374 | #define X86_CODE64 "\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_CODE16 "\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_CODE32 "\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 platform platforms[] = { |
| 379 | { |
| 380 | CS_ARCH_X86, |
| 381 | CS_MODE_16, |
| 382 | (unsigned char *)X86_CODE16, |
| 383 | sizeof(X86_CODE16) - 1, |
| 384 | "X86 16bit (Intel syntax)" |
| 385 | }, |
| 386 | { |
| 387 | CS_ARCH_X86, |
| 388 | CS_MODE_32, |
| 389 | (unsigned char *)X86_CODE32, |
| 390 | sizeof(X86_CODE32) - 1, |
| 391 | "X86 32 (AT&T syntax)", |
| 392 | CS_OPT_SYNTAX, |
| 393 | CS_OPT_SYNTAX_ATT, |
| 394 | }, |
| 395 | { |
| 396 | CS_ARCH_X86, |
| 397 | CS_MODE_32, |
| 398 | (unsigned char *)X86_CODE32, |
| 399 | sizeof(X86_CODE32) - 1, |
| 400 | "X86 32 (Intel syntax)" |
| 401 | }, |
| 402 | { |
| 403 | CS_ARCH_X86, |
| 404 | CS_MODE_64, |
| 405 | (unsigned char *)X86_CODE64, |
| 406 | sizeof(X86_CODE64) - 1, |
| 407 | "X86 64 (Intel syntax)" |
| 408 | }, |
| 409 | }; |
| 410 | |
| 411 | uint64_t address = 0x1000; |
| 412 | cs_insn *insn; |
| 413 | int i; |
| 414 | size_t count; |
| 415 | |
| 416 | for (i = 0; i < sizeof(platforms)/sizeof(platforms[0]); i++) { |
| 417 | cs_err err = cs_open(platforms[i].arch, platforms[i].mode, &handle); |
| 418 | if (err) { |
| 419 | printf("Failed on cs_open() with error returned: %u\n", err); |
| 420 | abort(); |
| 421 | } |
| 422 | |
| 423 | if (platforms[i].opt_type) |
| 424 | cs_option(handle, platforms[i].opt_type, platforms[i].opt_value); |
| 425 | |
| 426 | cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON); |
| 427 | |
| 428 | count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn); |
| 429 | if (count) { |
no test coverage detected
searching dependent graphs…