Rizin
unix-like reverse engineering framework and cli tools
asm_sysz.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 bool the_end (void *p)
 
static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
 

Variables

static csh cd = 0
 
RzAsmPlugin rz_asm_plugin_sysz
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ disassemble()

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

Definition at line 20 of file asm_sysz.c.

20  {
21  static int omode = 0;
22  int mode, n, ret;
23  ut64 off = a->pc;
24  cs_insn *insn = NULL;
26  if (cd && mode != omode) {
27  cs_close(&cd);
28  cd = 0;
29  }
30  op->size = 0;
31  omode = mode;
32  if (cd == 0) {
33  ret = cs_open(CS_ARCH_SYSZ, mode, &cd);
34  if (ret) {
35  return 0;
36  }
38  }
39  n = cs_disasm(cd, (const ut8 *)buf, len, off, 1, &insn);
40  if (n > 0) {
41  if (insn->size > 0) {
42  op->size = insn->size;
43  char *buf_asm = sdb_fmt("%s%s%s",
44  insn->mnemonic, insn->op_str[0] ? " " : "",
45  insn->op_str);
46  char *ptrstr = strstr(buf_asm, "ptr ");
47  if (ptrstr) {
48  memmove(ptrstr, ptrstr + 4, strlen(ptrstr + 4) + 1);
49  }
50  rz_asm_op_set_asm(op, buf_asm);
51  }
52  cs_free(insn, n);
53  }
54  return op->size;
55 }
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_sysz.c:10
@ CS_ARCH_SYSZ
SystemZ architecture.
Definition: capstone.h:81
@ CS_MODE_BIG_ENDIAN
big-endian mode
Definition: capstone.h:123
@ 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
#define NULL
Definition: cris-opc.c:27
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
int n
Definition: mipsasm.c:19
int off
Definition: pal.c:13
#define a(i)
Definition: sha256.c:41
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References a, cd, CS_ARCH_SYSZ, cs_close(), cs_disasm(), cs_free(), CS_MODE_BIG_ENDIAN, cs_open(), CS_OPT_DETAIL, CS_OPT_OFF, cs_option(), len, n, NULL, off, rz_asm_op_set_asm(), sdb_fmt(), and ut64().

◆ the_end()

static bool the_end ( void *  p)
static

Definition at line 12 of file asm_sysz.c.

12  {
13  if (cd) {
14  cs_close(&cd);
15  cd = 0;
16  }
17  return true;
18 }

References cd, and cs_close().

Variable Documentation

◆ cd

csh cd = 0
static

Definition at line 10 of file asm_sysz.c.

Referenced by disassemble(), and the_end().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_sysz
Definition: asm_sysz.c:57
@ 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 69 of file asm_sysz.c.

◆ rz_asm_plugin_sysz

RzAsmPlugin rz_asm_plugin_sysz
Initial value:
= {
.name = "sysz",
.desc = "SystemZ CPU disassembler",
.license = "BSD",
.arch = "sysz",
.bits = 32 | 64,
.endian = RZ_SYS_ENDIAN_BIG,
.fini = the_end,
.disassemble = &disassemble,
}
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_sysz.c:20
static bool the_end(void *p)
Definition: asm_sysz.c:12
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527

Definition at line 57 of file asm_sysz.c.