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

Go to the source code of this file.

Macros

#define INSOP(n)   insn->detail->sysz.operands[n]
 

Functions

static void opex (RzStrBuf *buf, csh handle, cs_insn *insn)
 
static int analop (RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
 
static char * get_reg_profile (RzAnalysis *analysis)
 
static int archinfo (RzAnalysis *analysis, int q)
 

Variables

RzAnalysisPlugin rz_analysis_plugin_sysz
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ INSOP

#define INSOP (   n)    insn->detail->sysz.operands[n]

Definition at line 14 of file analysis_sysz.c.

Function Documentation

◆ analop()

static int analop ( RzAnalysis a,
RzAnalysisOp op,
ut64  addr,
const ut8 buf,
int  len,
RzAnalysisOpMask  mask 
)
static

Definition at line 58 of file analysis_sysz.c.

58  {
59  csh handle;
60  cs_insn *insn;
62  int ret = cs_open(CS_ARCH_SYSZ, mode, &handle);
63  if (ret == CS_ERR_OK) {
65  // capstone-next
66  int n = cs_disasm(handle, (const ut8 *)buf, len, addr, 1, &insn);
67  if (n < 1) {
69  } else {
71  opex(&op->opex, handle, insn);
72  }
73  op->size = insn->size;
74  switch (insn->id) {
75  case SYSZ_INS_BRCL:
76  case SYSZ_INS_BRASL:
78  break;
79  case SYSZ_INS_BR:
81  break;
82  case SYSZ_INS_BRC:
83  case SYSZ_INS_BER:
84  case SYSZ_INS_BHR:
85  case SYSZ_INS_BHER:
86  case SYSZ_INS_BLR:
87  case SYSZ_INS_BLER:
88  case SYSZ_INS_BLHR:
89  case SYSZ_INS_BNER:
90  case SYSZ_INS_BNHR:
91  case SYSZ_INS_BNHER:
92  case SYSZ_INS_BNLR:
93  case SYSZ_INS_BNLER:
94  case SYSZ_INS_BNLHR:
95  case SYSZ_INS_BNOR:
96  case SYSZ_INS_BOR:
97  case SYSZ_INS_BASR:
98  case SYSZ_INS_BRAS:
99  case SYSZ_INS_BRCT:
100  case SYSZ_INS_BRCTG:
102  break;
103  case SYSZ_INS_JE:
104  case SYSZ_INS_JGE:
105  case SYSZ_INS_JHE:
106  case SYSZ_INS_JGHE:
107  case SYSZ_INS_JH:
108  case SYSZ_INS_JGH:
109  case SYSZ_INS_JLE:
110  case SYSZ_INS_JGLE:
111  case SYSZ_INS_JLH:
112  case SYSZ_INS_JGLH:
113  case SYSZ_INS_JL:
114  case SYSZ_INS_JGL:
115  case SYSZ_INS_JNE:
116  case SYSZ_INS_JGNE:
117  case SYSZ_INS_JNHE:
118  case SYSZ_INS_JGNHE:
119  case SYSZ_INS_JNH:
120  case SYSZ_INS_JGNH:
121  case SYSZ_INS_JNLE:
122  case SYSZ_INS_JGNLE:
123  case SYSZ_INS_JNLH:
124  case SYSZ_INS_JGNLH:
125  case SYSZ_INS_JNL:
126  case SYSZ_INS_JGNL:
127  case SYSZ_INS_JNO:
128  case SYSZ_INS_JGNO:
129  case SYSZ_INS_JO:
130  case SYSZ_INS_JGO:
131  case SYSZ_INS_JG:
133  op->jump = INSOP(0).imm;
134  op->fail = addr + op->size;
135  break;
136  case SYSZ_INS_J:
137  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
138  op->jump = INSOP(0).imm;
139  op->fail = UT64_MAX;
140  break;
141  }
142  }
143  cs_free(insn, n);
144  cs_close(&handle);
145  }
146  return op->size;
147 }
size_t len
Definition: 6502dis.c:15
#define mask()
#define INSOP(n)
Definition: analysis_sysz.c:14
static void opex(RzStrBuf *buf, csh handle, cs_insn *insn)
Definition: analysis_sysz.c:16
static mcore_handle handle
Definition: asm_mcore.c:8
@ 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_ON
Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
Definition: capstone.h:183
@ SYSZ_INS_JGNL
Definition: systemz.h:377
@ SYSZ_INS_JGLH
Definition: systemz.h:311
@ SYSZ_INS_BNLR
Definition: systemz.h:357
@ SYSZ_INS_BRASL
Definition: systemz.h:407
@ SYSZ_INS_JGNO
Definition: systemz.h:386
@ SYSZ_INS_BR
Definition: systemz.h:405
@ SYSZ_INS_JGL
Definition: systemz.h:319
@ SYSZ_INS_JNH
Definition: systemz.h:349
@ SYSZ_INS_JH
Definition: systemz.h:195
@ SYSZ_INS_BLR
Definition: systemz.h:299
@ SYSZ_INS_BHR
Definition: systemz.h:185
@ SYSZ_INS_JGNLE
Definition: systemz.h:360
@ SYSZ_INS_JGNE
Definition: systemz.h:332
@ SYSZ_INS_JGNHE
Definition: systemz.h:342
@ SYSZ_INS_J
Definition: systemz.h:408
@ SYSZ_INS_JNO
Definition: systemz.h:385
@ SYSZ_INS_JNL
Definition: systemz.h:376
@ SYSZ_INS_JGH
Definition: systemz.h:196
@ SYSZ_INS_BNLHR
Definition: systemz.h:367
@ SYSZ_INS_BER
Definition: systemz.h:176
@ SYSZ_INS_JNLE
Definition: systemz.h:359
@ SYSZ_INS_BNER
Definition: systemz.h:330
@ SYSZ_INS_BRC
Definition: systemz.h:166
@ SYSZ_INS_BRCTG
Definition: systemz.h:411
@ SYSZ_INS_JGE
Definition: systemz.h:178
@ SYSZ_INS_BRAS
Definition: systemz.h:406
@ SYSZ_INS_JHE
Definition: systemz.h:187
@ SYSZ_INS_BASR
Definition: systemz.h:404
@ SYSZ_INS_JNLH
Definition: systemz.h:368
@ SYSZ_INS_BLHR
Definition: systemz.h:309
@ SYSZ_INS_BLER
Definition: systemz.h:300
@ SYSZ_INS_BNOR
Definition: systemz.h:384
@ SYSZ_INS_BOR
Definition: systemz.h:393
@ SYSZ_INS_JGO
Definition: systemz.h:395
@ SYSZ_INS_BNHR
Definition: systemz.h:339
@ SYSZ_INS_JGNH
Definition: systemz.h:350
@ SYSZ_INS_BRCT
Definition: systemz.h:410
@ SYSZ_INS_BRCL
Definition: systemz.h:167
@ SYSZ_INS_JO
Definition: systemz.h:394
@ SYSZ_INS_BNLER
Definition: systemz.h:358
@ SYSZ_INS_BHER
Definition: systemz.h:186
@ SYSZ_INS_JLE
Definition: systemz.h:301
@ SYSZ_INS_JGHE
Definition: systemz.h:188
@ SYSZ_INS_JGNLH
Definition: systemz.h:369
@ SYSZ_INS_BNHER
Definition: systemz.h:340
@ SYSZ_INS_JL
Definition: systemz.h:318
@ SYSZ_INS_JGLE
Definition: systemz.h:302
@ SYSZ_INS_JNE
Definition: systemz.h:331
@ SYSZ_INS_JLH
Definition: systemz.h:310
@ SYSZ_INS_JNHE
Definition: systemz.h:341
@ SYSZ_INS_JG
Definition: systemz.h:409
@ SYSZ_INS_JE
Definition: systemz.h:177
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
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 CS_ERR_OK
Definition: __init__.py:235
@ RZ_ANALYSIS_OP_MASK_OPEX
Definition: rz_analysis.h:444
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_ILL
Definition: rz_analysis.h:387
#define UT64_MAX
Definition: rz_types_base.h:86
Definition: dis.c:32
static int addr
Definition: z80asm.c:58

References addr, CS_ARCH_SYSZ, cs_close(), cs_disasm(), capstone::CS_ERR_OK, cs_free(), CS_MODE_BIG_ENDIAN, cs_open(), CS_OPT_DETAIL, CS_OPT_ON, cs_option(), handle, INSOP, len, mask, n, opex(), RZ_ANALYSIS_OP_MASK_OPEX, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_ILL, RZ_ANALYSIS_OP_TYPE_JMP, SYSZ_INS_BASR, SYSZ_INS_BER, SYSZ_INS_BHER, SYSZ_INS_BHR, SYSZ_INS_BLER, SYSZ_INS_BLHR, SYSZ_INS_BLR, SYSZ_INS_BNER, SYSZ_INS_BNHER, SYSZ_INS_BNHR, SYSZ_INS_BNLER, SYSZ_INS_BNLHR, SYSZ_INS_BNLR, SYSZ_INS_BNOR, SYSZ_INS_BOR, SYSZ_INS_BR, SYSZ_INS_BRAS, SYSZ_INS_BRASL, SYSZ_INS_BRC, SYSZ_INS_BRCL, SYSZ_INS_BRCT, SYSZ_INS_BRCTG, SYSZ_INS_J, SYSZ_INS_JE, SYSZ_INS_JG, SYSZ_INS_JGE, SYSZ_INS_JGH, SYSZ_INS_JGHE, SYSZ_INS_JGL, SYSZ_INS_JGLE, SYSZ_INS_JGLH, SYSZ_INS_JGNE, SYSZ_INS_JGNH, SYSZ_INS_JGNHE, SYSZ_INS_JGNL, SYSZ_INS_JGNLE, SYSZ_INS_JGNLH, SYSZ_INS_JGNO, SYSZ_INS_JGO, SYSZ_INS_JH, SYSZ_INS_JHE, SYSZ_INS_JL, SYSZ_INS_JLE, SYSZ_INS_JLH, SYSZ_INS_JNE, SYSZ_INS_JNH, SYSZ_INS_JNHE, SYSZ_INS_JNL, SYSZ_INS_JNLE, SYSZ_INS_JNLH, SYSZ_INS_JNO, SYSZ_INS_JO, and UT64_MAX.

◆ archinfo()

static int archinfo ( RzAnalysis analysis,
int  q 
)
static

Definition at line 187 of file analysis_sysz.c.

187  {
188  switch (q) {
190  return 2;
192  return 4;
194  return 2;
195  }
196  return 2;
197 }
#define RZ_ANALYSIS_ARCHINFO_ALIGN
Definition: rz_analysis.h:100
#define RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE
Definition: rz_analysis.h:99
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
Definition: rz_analysis.h:98

References RZ_ANALYSIS_ARCHINFO_ALIGN, RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE, and RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE.

◆ get_reg_profile()

static char* get_reg_profile ( RzAnalysis analysis)
static

Definition at line 149 of file analysis_sysz.c.

149  {
150  const char *p =
151  "=PC r15\n"
152  "=LR r14\n"
153  "=SP r13\n"
154  "=BP r12\n"
155  "=A0 r0\n"
156  "=A1 r1\n"
157  "=A2 r2\n"
158  "=A3 r3\n"
159  "=SN r0\n"
160  "gpr sb .32 36 0\n" // r9
161  "gpr sl .32 40 0\n" // rl0
162  "gpr fp .32 44 0\n" // r11
163  "gpr ip .32 48 0\n" // r12
164  "gpr sp .32 52 0\n" // r13
165  "gpr lr .32 56 0\n" // r14
166  "gpr pc .32 60 0\n" // r15
167 
168  "gpr r0 .32 0 0\n"
169  "gpr r1 .32 4 0\n"
170  "gpr r2 .32 8 0\n"
171  "gpr r3 .32 12 0\n"
172  "gpr r4 .32 16 0\n"
173  "gpr r5 .32 20 0\n"
174  "gpr r6 .32 24 0\n"
175  "gpr r7 .32 28 0\n"
176  "gpr r8 .32 32 0\n"
177  "gpr r9 .32 36 0\n"
178  "gpr r10 .32 40 0\n"
179  "gpr r11 .32 44 0\n"
180  "gpr r12 .32 48 0\n"
181  "gpr r13 .32 52 0\n"
182  "gpr r14 .32 56 0\n"
183  "gpr r15 .32 60 0\n";
184  return strdup(p);
185 }
void * p
Definition: libc.cpp:67
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")

References p, and strdup().

◆ opex()

static void opex ( RzStrBuf buf,
csh  handle,
cs_insn *  insn 
)
static

Definition at line 16 of file analysis_sysz.c.

16  {
17  int i;
18  PJ *pj = pj_new();
19  if (!pj) {
20  return;
21  }
22  pj_o(pj);
23  pj_ka(pj, "operands");
24  cs_sysz *x = &insn->detail->sysz;
25  for (i = 0; i < x->op_count; i++) {
26  cs_sysz_op *op = x->operands + i;
27  pj_o(pj);
28  switch (op->type) {
29  case SYSZ_OP_REG:
30  pj_ks(pj, "type", "reg");
31  pj_ks(pj, "value", cs_reg_name(handle, op->reg));
32  break;
33  case SYSZ_OP_IMM:
34  pj_ks(pj, "type", "imm");
35  pj_kN(pj, "value", op->imm);
36  break;
37  case SYSZ_OP_MEM:
38  pj_ks(pj, "type", "mem");
39  if (op->mem.base != SYSZ_REG_INVALID) {
40  pj_ks(pj, "base", cs_reg_name(handle, op->mem.base));
41  }
42  pj_kN(pj, "disp", op->mem.disp);
43  break;
44  default:
45  pj_ks(pj, "type", "invalid");
46  break;
47  }
48  pj_end(pj); /* o operand */
49  }
50  pj_end(pj); /* a operands */
51  pj_end(pj);
52 
55  pj_free(pj);
56 }
lzma_index ** i
Definition: index.h:629
@ SYSZ_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: systemz.h:42
@ SYSZ_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: systemz.h:41
@ SYSZ_OP_REG
= CS_OP_REG (Register operand).
Definition: systemz.h:40
@ SYSZ_REG_INVALID
Definition: systemz.h:48
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1154
int x
Definition: mipsasm.c:20
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kN(PJ *j, const char *k, st64 n)
Definition: pj.c:128
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
Instruction operand.
Definition: systemz.h:101
Definition: rz_pj.h:12

References cs_reg_name(), handle, i, pj_end(), pj_free(), pj_ka(), pj_kN(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_strbuf_append(), rz_strbuf_init(), SYSZ_OP_IMM, SYSZ_OP_MEM, SYSZ_OP_REG, SYSZ_REG_INVALID, and x.

Referenced by analop().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
}
RzAnalysisPlugin rz_analysis_plugin_sysz
@ RZ_LIB_TYPE_ANALYSIS
Definition: rz_lib.h:73
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_analysis.h:1239

Definition at line 212 of file analysis_sysz.c.

◆ rz_analysis_plugin_sysz

RzAnalysisPlugin rz_analysis_plugin_sysz
Initial value:
= {
.name = "sysz",
.desc = "Capstone SystemZ microanalysis",
.esil = false,
.license = "BSD",
.arch = "sysz",
.bits = 32 | 64,
.op = &analop,
.archinfo = archinfo,
.get_reg_profile = &get_reg_profile,
}
static char * get_reg_profile(RzAnalysis *analysis)
static int analop(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
Definition: analysis_sysz.c:58
static int archinfo(RzAnalysis *analysis, int q)

Definition at line 199 of file analysis_sysz.c.