| 17 | static FILE *outfile = NULL; |
| 18 | |
| 19 | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
| 20 | csh handle; |
| 21 | cs_insn *all_insn; |
| 22 | cs_detail *detail; |
| 23 | cs_err err; |
| 24 | unsigned int i; |
| 25 | |
| 26 | if (Size < 1) { |
| 27 | // 1 byte for arch choice |
| 28 | return 0; |
| 29 | } else if (Size > 0x1000) { |
| 30 | //limit input to 4kb |
| 31 | Size = 0x1000; |
| 32 | } |
| 33 | |
| 34 | if (outfile == NULL) { |
| 35 | // we compute the output |
| 36 | outfile = fopen("/dev/null", "w"); |
| 37 | if (outfile == NULL) { |
| 38 | return 0; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | i = get_platform_entry((uint8_t)Data[0]); |
| 43 | |
| 44 | err = cs_open(platforms[i].arch, platforms[i].mode, &handle); |
| 45 | if (err) { |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON); |
| 50 | if (Data[0]&0x80) { |
| 51 | //hack |
| 52 | cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT); |
| 53 | } |
| 54 | |
| 55 | uint64_t address = 0x1000; |
| 56 | size_t count = cs_disasm(handle, Data+1, Size-1, address, 0, &all_insn); |
| 57 | |
| 58 | if (count) { |
| 59 | size_t j; |
| 60 | unsigned int n; |
| 61 | |
| 62 | for (j = 0; j < count; j++) { |
| 63 | cs_insn *i = &(all_insn[j]); |
| 64 | fprintf(outfile, "0x%"PRIx64":\t%s\t\t%s // insn-ID: %u, insn-mnem: %s\n", |
| 65 | i->address, i->mnemonic, i->op_str, |
| 66 | i->id, cs_insn_name(handle, i->id)); |
| 67 | |
| 68 | detail = i->detail; |
| 69 | |
| 70 | if (detail->regs_read_count > 0) { |
| 71 | fprintf(outfile, "\tImplicit registers read: "); |
| 72 | for (n = 0; n < detail->regs_read_count; n++) { |
| 73 | fprintf(outfile, "%s ", cs_reg_name(handle, detail->regs_read[n])); |
| 74 | } |
| 75 | } |
| 76 |
nothing calls this directly
no test coverage detected
searching dependent graphs…