MCPcopy Create free account
hub / github.com/capstone-engine/capstone / test

Function test

tests/test_bpf.c:112–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112static void test()
113{
114#define CBPF_CODE "\x94\x09\x00\x00\x37\x13\x03\x00" \
115 "\x87\x00\x00\x00\x00\x00\x00\x00" \
116 "\x07\x00\x00\x00\x00\x00\x00\x00" \
117 "\x16\x00\x00\x00\x00\x00\x00\x00" \
118 "\x80\x00\x00\x00\x00\x00\x00\x00"
119
120#define EBPF_CODE "\x97\x09\x00\x00\x37\x13\x03\x00" \
121 "\xdc\x02\x00\x00\x20\x00\x00\x00" \
122 "\x30\x00\x00\x00\x00\x00\x00\x00" \
123 "\xdb\x3a\x00\x01\x00\x00\x00\x00" \
124 "\x84\x02\x00\x00\x00\x00\x00\x00" \
125 "\x6d\x33\x17\x02\x00\x00\x00\x00"
126 struct platform platforms[] = {
127 {
128 CS_ARCH_BPF,
129 CS_MODE_LITTLE_ENDIAN | CS_MODE_BPF_CLASSIC,
130 (unsigned char *)CBPF_CODE,
131 sizeof(CBPF_CODE) - 1,
132 "cBPF Le"
133 },
134 {
135 CS_ARCH_BPF,
136 CS_MODE_LITTLE_ENDIAN | CS_MODE_BPF_EXTENDED,
137 (unsigned char *)EBPF_CODE,
138 sizeof(EBPF_CODE) - 1,
139 "eBPF Le"
140 },
141 };
142 uint64_t address = 0x0;
143 cs_insn *insn;
144 int i;
145 size_t count;
146
147 for (i = 0; i < sizeof(platforms)/sizeof(platforms[0]); i++) {
148 cs_err err = cs_open(platforms[i].arch, platforms[i].mode, &handle);
149 if (err) {
150 printf("Failed on cs_open() with error returned: %u\n", err);
151 abort();
152 }
153
154 cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON);
155
156 count = cs_disasm(handle, platforms[i].code, platforms[i].size, address, 0, &insn);
157 if (count) {
158 size_t j;
159 printf("****************\n");
160 printf("Platform: %s\n", platforms[i].comment);
161 print_string_hex("Code:", platforms[i].code, platforms[i].size);
162 printf("Disasm:\n");
163
164 for (j = 0; j < count; j++) {
165 printf("0x%" PRIx64 ":\t%s\t%s\n", insn[j].address, insn[j].mnemonic, insn[j].op_str);
166 print_insn_detail(handle, &insn[j]);
167 }
168
169 // free memory allocated by cs_disasm()

Callers 1

mainFunction · 0.70

Calls 8

cs_openFunction · 0.85
cs_optionFunction · 0.85
cs_disasmFunction · 0.85
cs_freeFunction · 0.85
cs_closeFunction · 0.85
printfFunction · 0.70
print_string_hexFunction · 0.70
print_insn_detailFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…