Debian Codegraph @

suite/fuzz/fuzz_disasm.c

raw symbols SCIP
1 // the following must precede stdio (woo, thanks msft)cxx . . $ `<file>/suite/fuzz/fuzz_disasm.c`/
2 #if defined(_MSC_VER) && _MSC_VER < 1900
3 #define _CRT_SECURE_NO_WARNINGS
4 #endif
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <inttypes.h>
9
10 #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/
11
12 #include "platform.h"cxx . . $ `<file>/suite/fuzz/platform.h`/
13
14 int LLVMFuzzerTestOneInputcxx . . $ LLVMFuzzerTestOneInput(22502bda773498f8).(const uint8_tcxx . . $ uint8_t# *Data, size_tcxx . . $ size_t# Size);
15
16
17 static FILEcxx . . $ FILE# *outfilecxx . . $ outfile. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
18
19 int LLVMFuzzerTestOneInputcxx . . $ LLVMFuzzerTestOneInput(22502bda773498f8).(const uint8_tcxx . . $ uint8_t# *Data, size_tcxx . . $ size_t# Size) {
20 cshcxx . . $ csh# handle;
21 cs_insncxx . . $ cs_insn# *all_insn;
22 cs_detailcxx . . $ cs_detail# *detail;
23 cs_errcxx . . $ 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 (outfilecxx . . $ outfile. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
35 // we compute the output
36 outfilecxx . . $ outfile. = fopencxx . . $ fopen(82ec0787cd37e0a3).("/dev/null", "w");
37 if (outfilecxx . . $ outfile. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
38 return 0;
39 }
40 }
41
42 i = get_platform_entrycxx . . $ get_platform_entry(ded9d4c05c7b1550).((uint8_tcxx . . $ uint8_t#)Data[0]);
43
44 err = cs_opencxx . . $ cs_open(b2cb849d8ee082cd).(platformscxx . . $ platforms.[i].archcxx . . $ platform#arch., platformscxx . . $ platforms.[i].modecxx . . $ platform#mode., &handle);
45 if (err) {
46 return 0;
47 }
48
49 cs_optioncxx . . $ cs_option(a321a010700ba3d2).(handle, CS_OPT_DETAILcxx . . $ CS_OPT_DETAIL., CS_OPT_ONcxx . . $ CS_OPT_ON.);
50 if (Data[0]&0x80) {
51 //hack
52 cs_optioncxx . . $ cs_option(a321a010700ba3d2).(handle, CS_OPT_SYNTAXcxx . . $ CS_OPT_SYNTAX., CS_OPT_SYNTAX_ATTcxx . . $ CS_OPT_SYNTAX_ATT.);
53 }
54
55 uint64_tcxx . . $ uint64_t# address = 0x1000;
56 size_tcxx . . $ size_t# count = cs_disasmcxx . . $ cs_disasm(d552efbd9b22be5).(handle, Data+1, Size-1, address, 0, &all_insn);
57
58 if (count) {
59 size_tcxx . . $ size_t# j;
60 unsigned int n;
61
62 for (j = 0; j < count; j++) {
63 cs_insncxx . . $ cs_insn# *i = &(all_insn[j]);
64 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(outfilecxx . . $ outfile., "0x%"PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`!":\t%s\t\t%s // insn-ID: %u, insn-mnem: %s\n",
65 i->addresscxx . . $ cs_insn#address., i->mnemoniccxx . . $ cs_insn#mnemonic., i->op_strcxx . . $ cs_insn#op_str.,
66 i->idcxx . . $ cs_insn#id., cs_insn_namecxx . . $ cs_insn_name(efd1348d9ae5172e).(handle, i->idcxx . . $ cs_insn#id.));
67
68 detail = i->detailcxx . . $ cs_insn#detail.;
69
70 if (detail->regs_read_countcxx . . $ cs_detail#regs_read_count. > 0) {
71 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(outfilecxx . . $ outfile., "\tImplicit registers read: ");
72 for (n = 0; n < detail->regs_read_countcxx . . $ cs_detail#regs_read_count.; n++) {
73 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(outfilecxx . . $ outfile., "%s ", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, detail->regs_readcxx . . $ cs_detail#regs_read.[n]));
74 }
75 }
76
77 if (detail->regs_write_countcxx . . $ cs_detail#regs_write_count. > 0) {
78 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(outfilecxx . . $ outfile., "\tImplicit registers modified: ");
79 for (n = 0; n < detail->regs_write_countcxx . . $ cs_detail#regs_write_count.; n++) {
80 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(outfilecxx . . $ outfile., "%s ", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, detail->regs_writecxx . . $ cs_detail#regs_write.[n]));
81 }
82 }
83
84 if (detail->groups_countcxx . . $ cs_detail#groups_count. > 0) {
85 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(outfilecxx . . $ outfile., "\tThis instruction belongs to groups: ");
86 for (n = 0; n < detail->groups_countcxx . . $ cs_detail#groups_count.; n++) {
87 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(outfilecxx . . $ outfile., "%s ", cs_group_namecxx . . $ cs_group_name(efd1348d9ae5172e).(handle, detail->groupscxx . . $ cs_detail#groups.[n]));
88 }
89 }
90 }
91
92 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(outfilecxx . . $ outfile., "0x%"PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`!":\n", all_insn[j-1].addresscxx . . $ cs_insn#address. + all_insn[j-1].sizecxx . . $ cs_insn#size.);
93 cs_freecxx . . $ cs_free(d0ae7023b33cf0c8).(all_insn, count);
94 }
95
96 cs_closecxx . . $ cs_close(b9ab39fbab147149).(&handle);
97
98 return 0;
99 }