Rizin
unix-like reverse engineering framework and cli tools
analysis_cr16.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2012-2013 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2014 Fedor Sakharov <fedor.sakharov@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <string.h>
6 #include <rz_types.h>
7 #include <rz_lib.h>
8 #include <rz_asm.h>
9 #include <rz_analysis.h>
10 #include <rz_util.h>
11 
12 #include <cr16_disas.h>
13 
14 static int cr16_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr,
15  const ut8 *buf, int len, RzAnalysisOpMask mask) {
16  int ret;
17  struct cr16_cmd cmd;
18 
19  memset(&cmd, 0, sizeof(cmd));
20 
21  ret = op->size = cr16_decode_command(buf, &cmd, len);
22 
23  if (ret <= 0) {
24  return ret;
25  }
26 
27  op->addr = addr;
28 
29  switch (cmd.type) {
30  case CR16_TYPE_MOV:
32  break;
33  case CR16_TYPE_ADD:
35  break;
36  case CR16_TYPE_MUL:
38  break;
39  case CR16_TYPE_SUB:
41  break;
42  case CR16_TYPE_CMP:
44  break;
45  case CR16_TYPE_BE:
46  case CR16_TYPE_BNE:
48  break;
49  case CR16_TYPE_AND:
51  break;
52  case CR16_TYPE_OR:
53  op->type = RZ_ANALYSIS_OP_TYPE_OR;
54  break;
55  case CR16_TYPE_SCOND:
56  break;
57  case CR16_TYPE_XOR:
59  break;
60  case CR16_TYPE_SHIFT:
62  break;
63  case CR16_TYPE_BIT:
65  break;
66  case CR16_TYPE_SLPR:
68  break;
69  case CR16_TYPE_BCOND:
70  if (cmd.reladdr) {
71  op->jump = addr + cmd.reladdr;
72  op->fail = addr + 2;
73  }
75  break;
76  case CR16_TYPE_BR:
77  case CR16_TYPE_BAL:
79  break;
80  case CR16_TYPE_EXCP:
82  break;
83  case CR16_TYPE_JCOND:
84  case CR16_TYPE_JAL:
85  case CR16_TYPE_JUMP:
86  case CR16_TYPE_JUMP_UNK:
87  if (cmd.reladdr) {
88  op->jump = addr + cmd.reladdr;
89  op->fail = addr + 2;
90  }
92  break;
93  case CR16_TYPE_RETX:
95  break;
96  case CR16_TYPE_PUSH:
98  break;
99  case CR16_TYPE_POP:
100  op->type = RZ_ANALYSIS_OP_TYPE_POP;
101  break;
102  case CR16_TYPE_LOAD:
103  case CR16_TYPE_DI:
104  case CR16_TYPE_EI:
105  case CR16_TYPE_STOR:
106  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
107  break;
108  case CR16_TYPE_NOP:
109  op->type = RZ_ANALYSIS_OP_TYPE_NOP;
110  break;
111  case CR16_TYPE_WAIT:
112  case CR16_TYPE_EWAIT:
113  op->type = RZ_ANALYSIS_OP_TYPE_SWI;
114  break;
115  default:
116  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
117  }
118 
119  return ret;
120 }
121 
123  .name = "cr16",
124  .desc = "CR16 code analysis plugin",
125  .license = "LGPL3",
126  .arch = "cr16",
127  .bits = 16,
128  .op = cr16_op,
129 };
130 
131 #ifndef RZ_PLUGIN_INCORE
134  .data = &rz_analysis_plugin_cr16,
136 };
137 #endif
size_t len
Definition: 6502dis.c:15
RzAnalysisPlugin rz_analysis_plugin_cr16
static int cr16_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
Definition: analysis_cr16.c:14
RZ_API RzLibStruct rizin_plugin
#define mask()
#define RZ_API
int cr16_decode_command(const ut8 *instr, struct cr16_cmd *cmd, int len)
Definition: cr16_disas.c:1184
@ CR16_TYPE_EI
Definition: cr16_disas.h:39
@ CR16_TYPE_DI
Definition: cr16_disas.h:38
@ CR16_TYPE_JAL
Definition: cr16_disas.h:30
@ CR16_TYPE_BE
Definition: cr16_disas.h:16
@ CR16_TYPE_EXCP
Definition: cr16_disas.h:28
@ CR16_TYPE_BNE
Definition: cr16_disas.h:17
@ CR16_TYPE_JUMP
Definition: cr16_disas.h:31
@ CR16_TYPE_STOR
Definition: cr16_disas.h:37
@ CR16_TYPE_BIT
Definition: cr16_disas.h:23
@ CR16_TYPE_RETX
Definition: cr16_disas.h:33
@ CR16_TYPE_BR
Definition: cr16_disas.h:27
@ CR16_TYPE_MOV
Definition: cr16_disas.h:11
@ CR16_TYPE_SLPR
Definition: cr16_disas.h:24
@ CR16_TYPE_MUL
Definition: cr16_disas.h:13
@ CR16_TYPE_SUB
Definition: cr16_disas.h:14
@ CR16_TYPE_PUSH
Definition: cr16_disas.h:34
@ CR16_TYPE_WAIT
Definition: cr16_disas.h:41
@ CR16_TYPE_POP
Definition: cr16_disas.h:35
@ CR16_TYPE_BAL
Definition: cr16_disas.h:26
@ CR16_TYPE_JUMP_UNK
Definition: cr16_disas.h:32
@ CR16_TYPE_SCOND
Definition: cr16_disas.h:20
@ CR16_TYPE_LOAD
Definition: cr16_disas.h:36
@ CR16_TYPE_OR
Definition: cr16_disas.h:19
@ CR16_TYPE_XOR
Definition: cr16_disas.h:21
@ CR16_TYPE_SHIFT
Definition: cr16_disas.h:22
@ CR16_TYPE_ADD
Definition: cr16_disas.h:12
@ CR16_TYPE_CMP
Definition: cr16_disas.h:15
@ CR16_TYPE_NOP
Definition: cr16_disas.h:40
@ CR16_TYPE_EWAIT
Definition: cr16_disas.h:42
@ CR16_TYPE_BCOND
Definition: cr16_disas.h:25
@ CR16_TYPE_AND
Definition: cr16_disas.h:18
@ CR16_TYPE_JCOND
Definition: cr16_disas.h:29
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
RzAnalysisOpMask
Definition: rz_analysis.h:439
@ RZ_ANALYSIS_OP_TYPE_CMP
Definition: rz_analysis.h:399
@ RZ_ANALYSIS_OP_TYPE_SUB
Definition: rz_analysis.h:402
@ RZ_ANALYSIS_OP_TYPE_UNK
Definition: rz_analysis.h:388
@ RZ_ANALYSIS_OP_TYPE_MUL
Definition: rz_analysis.h:404
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_AND
Definition: rz_analysis.h:411
@ RZ_ANALYSIS_OP_TYPE_UJMP
Definition: rz_analysis.h:369
@ RZ_ANALYSIS_OP_TYPE_SWI
Definition: rz_analysis.h:393
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_OR
Definition: rz_analysis.h:410
@ RZ_ANALYSIS_OP_TYPE_PUSH
Definition: rz_analysis.h:397
@ RZ_ANALYSIS_OP_TYPE_SHR
Definition: rz_analysis.h:406
@ RZ_ANALYSIS_OP_TYPE_POP
Definition: rz_analysis.h:398
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_NOP
Definition: rz_analysis.h:389
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412
@ 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: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58