Rizin
unix-like reverse engineering framework and cli tools
asm_sysz.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2013-2015 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 // instruction set : http://www.tachyonsoft.com/inst390m.htm
5 
6 #include <rz_asm.h>
7 #include <rz_lib.h>
8 #include <capstone/capstone.h>
9 
10 static csh cd = 0;
11 
12 static bool the_end(void *p) {
13  if (cd) {
14  cs_close(&cd);
15  cd = 0;
16  }
17  return true;
18 }
19 
20 static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
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 }
56 
58  .name = "sysz",
59  .desc = "SystemZ CPU disassembler",
60  .license = "BSD",
61  .arch = "sysz",
62  .bits = 32 | 64,
63  .endian = RZ_SYS_ENDIAN_BIG,
64  .fini = the_end,
65  .disassemble = &disassemble,
66 };
67 
68 #ifndef RZ_PLUGIN_INCORE
71  .data = &rz_asm_plugin_sysz,
73 };
74 #endif
size_t len
Definition: 6502dis.c:15
RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str)
Definition: aop.c:53
RZ_API RzLibStruct rizin_plugin
Definition: asm_sysz.c:69
static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_sysz.c:20
RzAsmPlugin rz_asm_plugin_sysz
Definition: asm_sysz.c:57
static csh cd
Definition: asm_sysz.c:10
static bool the_end(void *p)
Definition: asm_sysz.c:12
@ 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
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
#define RZ_API
#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
void * p
Definition: libc.cpp:67
int n
Definition: mipsasm.c:19
int off
Definition: pal.c:13
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_SYS_ENDIAN_BIG
Definition: rz_types.h:527
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()