Debian Codegraph @

cstool/cstool_bpf.c

raw symbols SCIP
1 #cxx . . $ `<file>/cstool/cstool_bpf.c`/include <stdio.h>
2
3 #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/
4 #include <capstone/platform.h>cxx . . $ `<file>/include/capstone/platform.h`/
5 #include "cstool.h"cxx . . $ `<file>/cstool/cstool.h`/
6
7 static const char * ext_namecxx . . $ ext_name.[] = {
8 [BPF_EXT_LENcxx . . $ BPF_EXT_LEN.] = "#len",
9 };
10
11 void print_insn_detail_bpfcxx . . $ print_insn_detail_bpf(2888c3e5b0984e8d).(cshcxx . . $ csh# handle, cs_insncxx . . $ cs_insn# *ins)
12 {
13 unsigned i;
14 cs_bpfcxx . . $ cs_bpf# *bpf;
15 cs_regscxx . . $ cs_regs# regs_read, regs_write;
16 uint8_tcxx . . $ uint8_t# regs_read_count, regs_write_count;
17
18 // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
19 if (ins->detailcxx . . $ cs_insn#detail. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!)
20 return;
21
22 bpf = &(ins->detailcxx . . $ cs_insn#detail.->bpfcxx . . $ cs_detail#$anonymous_type_0#bpf.);
23
24 printfcxx . . $ printf(581fddd72a8db8fc).("\tOperand count: %u\n", bpf->op_countcxx . . $ cs_bpf#op_count.);
25
26 for (i = 0; i < bpf->op_countcxx . . $ cs_bpf#op_count.; i++) {
27 cs_bpf_opcxx . . $ cs_bpf_op# *op = &(bpf->operandscxx . . $ cs_bpf#operands.[i]);
28 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: ", i);
29 switch (op->typecxx . . $ cs_bpf_op#type.) {
30 case BPF_OP_INVALIDcxx . . $ BPF_OP_INVALID.:
31 printfcxx . . $ printf(581fddd72a8db8fc).("INVALID\n");
32 break;
33 case BPF_OP_REGcxx . . $ BPF_OP_REG.:
34 printfcxx . . $ printf(581fddd72a8db8fc).("REG = %s\n", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->regcxx . . $ cs_bpf_op#$anonymous_type_0#reg.));
35 break;
36 case BPF_OP_IMMcxx . . $ BPF_OP_IMM.:
37 printfcxx . . $ printf(581fddd72a8db8fc).("IMM = 0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! "\n", op->immcxx . . $ cs_bpf_op#$anonymous_type_0#imm.);
38 break;
39 case BPF_OP_OFFcxx . . $ BPF_OP_OFF.:
40 printfcxx . . $ printf(581fddd72a8db8fc).("OFF = +0x%x\n", op->offcxx . . $ cs_bpf_op#$anonymous_type_0#off.);
41 break;
42 case BPF_OP_MEMcxx . . $ BPF_OP_MEM.:
43 printfcxx . . $ printf(581fddd72a8db8fc).("MEM\n");
44 if (op->memcxx . . $ cs_bpf_op#$anonymous_type_0#mem..basecxx . . $ bpf_op_mem#base. != BPF_REG_INVALIDcxx . . $ BPF_REG_INVALID.)
45 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.base: REG = %s\n",
46 i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->memcxx . . $ cs_bpf_op#$anonymous_type_0#mem..basecxx . . $ bpf_op_mem#base.));
47 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->memcxx . . $ cs_bpf_op#$anonymous_type_0#mem..dispcxx . . $ bpf_op_mem#disp.);
48 break;
49 case BPF_OP_MMEMcxx . . $ BPF_OP_MMEM.:
50 printfcxx . . $ printf(581fddd72a8db8fc).("MMEM = M[0x%x]\n", op->mmemcxx . . $ cs_bpf_op#$anonymous_type_0#mmem.);
51 break;
52 case BPF_OP_MSHcxx . . $ BPF_OP_MSH.:
53 printfcxx . . $ printf(581fddd72a8db8fc).("MSH = 4*([0x%x]&0xf)\n", op->mshcxx . . $ cs_bpf_op#$anonymous_type_0#msh.);
54 break;
55 case BPF_OP_EXTcxx . . $ BPF_OP_EXT.:
56 printfcxx . . $ printf(581fddd72a8db8fc).("EXT = %s\n", ext_namecxx . . $ ext_name.[op->extcxx . . $ cs_bpf_op#$anonymous_type_0#ext.]);
57 break;
58 }
59 }
60
61 /* print all registers that are involved in this instruction */
62 if (!cs_regs_accesscxx . . $ cs_regs_access(4779ec53ff278361).(handle, ins,
63 regs_read, &regs_read_count,
64 regs_write, &regs_write_count)) {
65 if (regs_read_count) {
66 printfcxx . . $ printf(581fddd72a8db8fc).("\tRegisters read:");
67 for(i = 0; i < regs_read_count; i++)
68 printfcxx . . $ printf(581fddd72a8db8fc).(" %s", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, regs_read[i]));
69 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
70 }
71
72 if (regs_write_count) {
73 printfcxx . . $ printf(581fddd72a8db8fc).("\tRegisters modified:");
74 for(i = 0; i < regs_write_count; i++)
75 printfcxx . . $ printf(581fddd72a8db8fc).(" %s", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, regs_write[i]));
76 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
77 }
78 }
79 }