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

Go to the source code of this file.

Functions

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

Variables

static csh cd = 0
 
RzAsmPlugin rz_asm_plugin_sparc_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 10 of file asm_sparc_cs.c.

10  {
11  cs_insn *insn;
12  int n = -1, ret = -1;
14  if (a->cpu && *a->cpu) {
15  if (!strcmp(a->cpu, "v9")) {
16  mode |= CS_MODE_V9;
17  }
18  }
19  if (op) {
20  memset(op, 0, sizeof(RzAsmOp));
21  op->size = 4;
22  }
23  if (cd != 0) {
24  cs_close(&cd);
25  }
26  ret = cs_open(CS_ARCH_SPARC, mode, &cd);
27  if (ret) {
28  goto fin;
29  }
31  if (!op) {
32  return 0;
33  }
34  if (a->big_endian) {
35  n = cs_disasm(cd, buf, len, a->pc, 1, &insn);
36  }
37  if (n < 1) {
38  rz_asm_op_set_asm(op, "invalid");
39  op->size = 4;
40  ret = -1;
41  goto beach;
42  } else {
43  ret = 4;
44  }
45  if (insn->size < 1) {
46  goto beach;
47  }
48  op->size = insn->size;
49  char *buf_asm = sdb_fmt("%s%s%s",
50  insn->mnemonic, insn->op_str[0] ? " " : "",
51  insn->op_str);
52  rz_str_replace_char(buf_asm, '%', 0);
53  rz_asm_op_set_asm(op, buf_asm);
54  // TODO: remove the '$'<registername> in the string
55  cs_free(insn, n);
56 beach:
57 // cs_close (&cd);
58 fin:
59  return ret;
60 }
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 csh cd
Definition: asm_sparc_cs.c:7
@ CS_ARCH_SPARC
Sparc architecture.
Definition: capstone.h:80
@ CS_MODE_BIG_ENDIAN
big-endian mode
Definition: capstone.h:123
@ CS_MODE_V9
SparcV9 mode (Sparc)
Definition: capstone.h:115
@ CS_OPT_DETAIL
Break down instruction structure into details.
Definition: capstone.h:171
@ 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
return memset(p, 0, total)
int n
Definition: mipsasm.c:19
RZ_API int rz_str_replace_char(char *s, int a, int b)
Definition: str.c:169
#define a(i)
Definition: sha256.c:41
Definition: dis.c:32

References a, cd, CS_ARCH_SPARC, cs_close(), cs_disasm(), cs_free(), CS_MODE_BIG_ENDIAN, CS_MODE_V9, cs_open(), CS_OPT_DETAIL, CS_OPT_OFF, cs_option(), len, memset(), n, rz_asm_op_set_asm(), rz_str_replace_char(), and sdb_fmt().

Variable Documentation

◆ cd

csh cd = 0
static

Definition at line 7 of file asm_sparc_cs.c.

Referenced by disassemble().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_sparc_cs
Definition: asm_sparc_cs.c:62
@ 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 75 of file asm_sparc_cs.c.

◆ rz_asm_plugin_sparc_cs

RzAsmPlugin rz_asm_plugin_sparc_cs
Initial value:
= {
.name = "sparc",
.desc = "Capstone SPARC disassembler",
.license = "BSD",
.arch = "sparc",
.cpus = "v9",
.bits = 32 | 64,
.disassemble = &disassemble,
.mnemonics = mnemonics
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_sparc_cs.c:10
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526
static const char * mnemonics[]
Definition: z80asm.c:43

Definition at line 62 of file asm_sparc_cs.c.