Rizin
unix-like reverse engineering framework and cli tools
asm_xcore_cs.c File Reference
#include <rz_asm.h>
#include <rz_lib.h>
#include <capstone/capstone.h>

Go to the source code of this file.

Functions

static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
 

Variables

RzAsmPlugin rz_asm_plugin_xcore_cs
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ disassemble()

static int disassemble ( RzAsm a,
RzAsmOp op,
const ut8 buf,
int  len 
)
static

Definition at line 8 of file asm_xcore_cs.c.

8  {
9  csh handle;
10  cs_insn *insn;
11  int mode, n, ret = -1;
13  memset(op, 0, sizeof(RzAsmOp));
14  op->size = 4;
15  ret = cs_open(CS_ARCH_XCORE, mode, &handle);
16  if (ret) {
17  goto fin;
18  }
20  n = cs_disasm(handle, (ut8 *)buf, len, a->pc, 1, &insn);
21  if (n < 1) {
22  rz_asm_op_set_asm(op, "invalid");
23  op->size = 4;
24  ret = -1;
25  goto beach;
26  }
27  ret = 4;
28  if (insn->size < 1) {
29  goto beach;
30  }
31  op->size = insn->size;
32  rz_asm_op_set_asm(op, sdb_fmt("%s%s%s", insn->mnemonic, insn->op_str[0] ? " " : "", insn->op_str));
33 // TODO: remove the '$'<registername> in the string
34 beach:
35  cs_free(insn, n);
36  cs_close(&handle);
37 fin:
38  return ret;
39 }
size_t len
Definition: 6502dis.c:15
RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str)
Definition: aop.c:53
static mcore_handle handle
Definition: asm_mcore.c:8
@ CS_ARCH_XCORE
XCore architecture.
Definition: capstone.h:82
@ CS_MODE_BIG_ENDIAN
big-endian mode
Definition: capstone.h:123
@ CS_MODE_LITTLE_ENDIAN
little-endian mode (default mode)
Definition: capstone.h:103
@ CS_OPT_DETAIL
Break down instruction structure into details.
Definition: capstone.h:171
size_t csh
Definition: capstone.h:71
@ CS_OPT_OFF
Turn OFF an option - default for CS_OPT_DETAIL, CS_OPT_SKIPDATA, CS_OPT_UNSIGNED.
Definition: capstone.h:182
CAPSTONE_EXPORT size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
Definition: cs.c:798
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: cs.c:453
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
Definition: cs.c:1017
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
Definition: cs.c:501
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
Definition: cs.c:646
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
int n
Definition: mipsasm.c:19
#define a(i)
Definition: sha256.c:41
Definition: dis.c:32

References a, CS_ARCH_XCORE, cs_close(), cs_disasm(), cs_free(), CS_MODE_BIG_ENDIAN, CS_MODE_LITTLE_ENDIAN, cs_open(), CS_OPT_DETAIL, CS_OPT_OFF, cs_option(), handle, len, memset(), n, rz_asm_op_set_asm(), and sdb_fmt().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_xcore_cs
Definition: asm_xcore_cs.c:41
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_asm.h:133

Definition at line 53 of file asm_xcore_cs.c.

◆ rz_asm_plugin_xcore_cs

RzAsmPlugin rz_asm_plugin_xcore_cs
Initial value:
= {
.name = "xcore",
.desc = "Capstone XCore disassembler",
.license = "BSD",
.author = "pancake",
.arch = "xcore",
.bits = 32,
.disassemble = &disassemble,
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_xcore_cs.c:8
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526

Definition at line 41 of file asm_xcore_cs.c.