Rizin
unix-like reverse engineering framework and cli tools
analysis_ebc.c File Reference
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include <rz_analysis.h>
#include <ebc_disas.h>

Go to the source code of this file.

Functions

static void ebc_analysis_jmp8 (RzAnalysisOp *op, ut64 addr, const ut8 *buf)
 
static void ebc_analysis_jmp (RzAnalysisOp *op, ut64 addr, const ut8 *buf)
 
static void ebc_analysis_call (RzAnalysisOp *op, ut64 addr, const ut8 *buf)
 
static int ebc_op (RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
 

Variables

RzAnalysisPlugin rz_analysis_plugin_ebc
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ ebc_analysis_call()

static void ebc_analysis_call ( RzAnalysisOp op,
ut64  addr,
const ut8 buf 
)
static

Definition at line 43 of file analysis_ebc.c.

43  {
44  int32_t addr_call;
45 
46  op->fail = addr + 6;
47  if ((buf[1] & 0x7) == 0 && TEST_BIT(buf[0], 6) == 0 && TEST_BIT(buf[0], 7)) {
48  addr_call = *(int32_t *)(buf + 2);
49 
50  if (TEST_BIT(buf[1], 4)) {
51  op->jump = (addr + 6 + addr_call);
52  } else {
53  op->jump = addr_call;
54  }
56  } else {
58  }
59 }
#define TEST_BIT(x, n)
Definition: ebc_disas.h:27
voidpf void * buf
Definition: ioapi.h:138
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_UCALL
Definition: rz_analysis.h:379
int int32_t
Definition: sftypes.h:33
Definition: dis.c:32
static int addr
Definition: z80asm.c:58

References addr, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_UCALL, and TEST_BIT.

Referenced by ebc_op().

◆ ebc_analysis_jmp()

static void ebc_analysis_jmp ( RzAnalysisOp op,
ut64  addr,
const ut8 buf 
)
static

Definition at line 26 of file analysis_ebc.c.

26  {
27  op->fail = addr + 6;
28  op->jump = (ut64) * (int32_t *)(buf + 2);
29  if (TEST_BIT(buf[1], 4)) {
30  op->jump += addr + 6;
31  }
32  if (buf[1] & 0x7) {
34  } else {
35  if (TEST_BIT(buf[1], 7)) {
37  } else {
39  }
40  }
41 }
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_UJMP
Definition: rz_analysis.h:369
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References addr, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_UJMP, TEST_BIT, and ut64().

Referenced by ebc_op().

◆ ebc_analysis_jmp8()

static void ebc_analysis_jmp8 ( RzAnalysisOp op,
ut64  addr,
const ut8 buf 
)
static

Definition at line 13 of file analysis_ebc.c.

13  {
14  int jmpadr = (int8_t)buf[1];
15  op->jump = addr + 2 + (jmpadr * 2);
16  op->addr = addr;
17  op->fail = addr + 2;
18 
19  if (TEST_BIT(buf[0], 7)) {
21  } else {
23  }
24 }
char int8_t
Definition: sftypes.h:35

References addr, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_JMP, and TEST_BIT.

Referenced by ebc_op().

◆ ebc_op()

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

Definition at line 61 of file analysis_ebc.c.

61  {
62  int ret;
64  ut8 opcode = buf[0] & EBC_OPCODE_MASK;
65 
66  if (!op) {
67  return 2;
68  }
69 
70  op->addr = addr;
71 
72  ret = op->size = ebc_decode_command(buf, &cmd);
73 
74  if (ret < 0) {
75  return ret;
76  }
77 
78  switch (opcode) {
79  case EBC_JMP8:
81  break;
82  case EBC_JMP:
84  break;
85  case EBC_MOVBW:
86  case EBC_MOVWW:
87  case EBC_MOVDW:
88  case EBC_MOVQW:
89  case EBC_MOVBD:
90  case EBC_MOVWD:
91  case EBC_MOVDD:
92  case EBC_MOVQD:
93  case EBC_MOVSNW:
94  case EBC_MOVSND:
95  case EBC_MOVQQ:
96  case EBC_MOVNW:
97  case EBC_MOVND:
98  case EBC_MOVI:
99  case EBC_MOVIN:
100  case EBC_MOVREL:
101  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
102  break;
103  case EBC_RET:
104  op->type = RZ_ANALYSIS_OP_TYPE_RET;
105  break;
106  case EBC_CMPEQ:
107  case EBC_CMPLTE:
108  case EBC_CMPGTE:
109  case EBC_CMPULTE:
110  case EBC_CMPUGTE:
111  case EBC_CMPIEQ:
112  case EBC_CMPILTE:
113  case EBC_CMPIGTE:
114  case EBC_CMPIULTE:
115  case EBC_CMPIUGTE:
116  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
117  break;
118  case EBC_SHR:
119  op->type = RZ_ANALYSIS_OP_TYPE_SHR;
120  break;
121  case EBC_SHL:
122  op->type = RZ_ANALYSIS_OP_TYPE_SHL;
123  break;
124  case EBC_OR:
125  op->type = RZ_ANALYSIS_OP_TYPE_OR;
126  break;
127  case EBC_XOR:
128  op->type = RZ_ANALYSIS_OP_TYPE_XOR;
129  break;
130  case EBC_MUL:
131  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
132  break;
133  case EBC_PUSH:
135  break;
136  case EBC_POP:
137  op->type = RZ_ANALYSIS_OP_TYPE_POP;
138  break;
139  case EBC_AND:
140  op->type = RZ_ANALYSIS_OP_TYPE_AND;
141  break;
142  case EBC_ADD:
143  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
144  break;
145  case EBC_SUB:
146  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
147  break;
148  case EBC_NEG:
149  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
150  break;
151  case EBC_CALL:
153  break;
154  case EBC_BREAK:
155  op->type = RZ_ANALYSIS_OP_TYPE_SWI;
156  break;
157  default:
158  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
159  break;
160  }
161 
162  return ret;
163 }
static void ebc_analysis_jmp8(RzAnalysisOp *op, ut64 addr, const ut8 *buf)
Definition: analysis_ebc.c:13
static void ebc_analysis_call(RzAnalysisOp *op, ut64 addr, const ut8 *buf)
Definition: analysis_ebc.c:43
static void ebc_analysis_jmp(RzAnalysisOp *op, ut64 addr, const ut8 *buf)
Definition: analysis_ebc.c:26
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
int ebc_decode_command(const ut8 *instr, ebc_command_t *cmd)
Definition: ebc_disas.c:986
#define EBC_OPCODE_MASK
Definition: ebc_disas.h:9
@ EBC_ADD
Definition: ebc_disas.h:42
@ EBC_PUSH
Definition: ebc_disas.h:73
@ EBC_SHL
Definition: ebc_disas.h:53
@ EBC_CMPIUGTE
Definition: ebc_disas.h:79
@ EBC_JMP8
Definition: ebc_disas.h:32
@ EBC_MOVDD
Definition: ebc_disas.h:65
@ EBC_MUL
Definition: ebc_disas.h:44
@ EBC_SUB
Definition: ebc_disas.h:43
@ EBC_CMPULTE
Definition: ebc_disas.h:38
@ EBC_POP
Definition: ebc_disas.h:74
@ EBC_MOVDW
Definition: ebc_disas.h:61
@ EBC_CMPLTE
Definition: ebc_disas.h:36
@ EBC_RET
Definition: ebc_disas.h:34
@ EBC_CALL
Definition: ebc_disas.h:33
@ EBC_MOVQQ
Definition: ebc_disas.h:70
@ EBC_MOVQW
Definition: ebc_disas.h:62
@ EBC_XOR
Definition: ebc_disas.h:52
@ EBC_MOVQD
Definition: ebc_disas.h:66
@ EBC_CMPEQ
Definition: ebc_disas.h:35
@ EBC_MOVI
Definition: ebc_disas.h:85
@ EBC_CMPIULTE
Definition: ebc_disas.h:78
@ EBC_CMPGTE
Definition: ebc_disas.h:37
@ EBC_MOVSNW
Definition: ebc_disas.h:67
@ EBC_CMPUGTE
Definition: ebc_disas.h:39
@ EBC_JMP
Definition: ebc_disas.h:31
@ EBC_MOVREL
Definition: ebc_disas.h:87
@ EBC_MOVWW
Definition: ebc_disas.h:60
@ EBC_NEG
Definition: ebc_disas.h:41
@ EBC_CMPILTE
Definition: ebc_disas.h:76
@ EBC_MOVBW
Definition: ebc_disas.h:59
@ EBC_MOVIN
Definition: ebc_disas.h:86
@ EBC_SHR
Definition: ebc_disas.h:54
@ EBC_BREAK
Definition: ebc_disas.h:30
@ EBC_MOVSND
Definition: ebc_disas.h:68
@ EBC_CMPIGTE
Definition: ebc_disas.h:77
@ EBC_AND
Definition: ebc_disas.h:50
@ EBC_MOVBD
Definition: ebc_disas.h:63
@ EBC_MOVWD
Definition: ebc_disas.h:64
@ EBC_CMPIEQ
Definition: ebc_disas.h:75
@ EBC_OR
Definition: ebc_disas.h:51
@ EBC_MOVNW
Definition: ebc_disas.h:80
@ EBC_MOVND
Definition: ebc_disas.h:81
uint8_t ut8
Definition: lh5801.h:11
@ 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_AND
Definition: rz_analysis.h:411
@ 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_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_SHL
Definition: rz_analysis.h:407
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412

References addr, cmd, EBC_ADD, ebc_analysis_call(), ebc_analysis_jmp(), ebc_analysis_jmp8(), EBC_AND, EBC_BREAK, EBC_CALL, EBC_CMPEQ, EBC_CMPGTE, EBC_CMPIEQ, EBC_CMPIGTE, EBC_CMPILTE, EBC_CMPIUGTE, EBC_CMPIULTE, EBC_CMPLTE, EBC_CMPUGTE, EBC_CMPULTE, ebc_decode_command(), EBC_JMP, EBC_JMP8, EBC_MOVBD, EBC_MOVBW, EBC_MOVDD, EBC_MOVDW, EBC_MOVI, EBC_MOVIN, EBC_MOVND, EBC_MOVNW, EBC_MOVQD, EBC_MOVQQ, EBC_MOVQW, EBC_MOVREL, EBC_MOVSND, EBC_MOVSNW, EBC_MOVWD, EBC_MOVWW, EBC_MUL, EBC_NEG, EBC_OPCODE_MASK, EBC_OR, EBC_POP, EBC_PUSH, EBC_RET, EBC_SHL, EBC_SHR, EBC_SUB, EBC_XOR, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_AND, RZ_ANALYSIS_OP_TYPE_CMP, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_MUL, RZ_ANALYSIS_OP_TYPE_OR, RZ_ANALYSIS_OP_TYPE_POP, RZ_ANALYSIS_OP_TYPE_PUSH, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_SHL, RZ_ANALYSIS_OP_TYPE_SHR, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_SWI, RZ_ANALYSIS_OP_TYPE_UNK, and RZ_ANALYSIS_OP_TYPE_XOR.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
}
RzAnalysisPlugin rz_analysis_plugin_ebc
Definition: analysis_ebc.c:165
@ 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 175 of file analysis_ebc.c.

◆ rz_analysis_plugin_ebc

RzAnalysisPlugin rz_analysis_plugin_ebc
Initial value:
= {
.name = "ebc",
.desc = "EBC code analysis plugin",
.license = "LGPL3",
.arch = "ebc",
.bits = 64,
.op = &ebc_op,
}
static int ebc_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
Definition: analysis_ebc.c:61

Definition at line 165 of file analysis_ebc.c.