File: cstool_wasm.c

package info (click to toggle)
rust-capstone-sys 0.17.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,524 kB
  • sloc: ansic: 70,376; cs: 18,890; pascal: 14,893; java: 14,778; ml: 13,672; python: 6,145; makefile: 1,172; sh: 532; cpp: 285
file content (51 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>

#include <capstone/capstone.h>

void print_insn_detail_wasm(csh handle, cs_insn *ins);

void print_insn_detail_wasm(csh handle, cs_insn *ins)
{
	cs_wasm *wasm;

	// detail can be NULL on "data" instruction if SKIPDATA option is turned ON
	if (ins->detail == NULL)
		return;

	wasm = &(ins->detail->wasm);
	if (wasm->op_count > 0) {
		unsigned int i;

		printf("\tOperand count: %d\n", wasm->op_count);

		for (i = 0; i < wasm->op_count; i++) {
			switch (wasm->operands[i].type) {
				default:
					break;
				case WASM_OP_INT7:
					printf("\t\tOperand[%u] type: int7\n", i);
					printf("\t\tOperand[%u] value: %d\n", i, wasm->operands[i].int7);
					break;
				case WASM_OP_UINT32:
					printf("\t\tOperand[%u] type: uint32\n", i);
					printf("\t\tOperand[%u] value: 0x%x\n", i, wasm->operands[i].uint32);
					break;
				case WASM_OP_UINT64:
					printf("\t\tOperand[%u] type: uint64\n", i);
					printf("\t\tOperand[%u] value: 0x%" PRIx64 "\n", i, wasm->operands[i].uint64);
					break;
				case WASM_OP_VARUINT32:
					printf("\t\tOperand[%u] type: varuint32\n", i);
					printf("\t\tOperand[%u] value: 0x%x\n", i, wasm->operands[i].varuint32);
					break;
				case WASM_OP_VARUINT64:
					printf("\t\tOperand[%u] type: varuint64\n", i);
					printf("\t\tOperand[%u] value: 0x%" PRIx64 "\n", i, wasm->operands[i].varuint64);
					break;
			}

			printf("\t\tOperand[%u] size: %u\n", i, wasm->operands[i].size);
		}
	}
}