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

Go to the source code of this file.

Functions

static int chip8_anop (RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
 

Variables

RzAnalysisPlugin rz_analysis_plugin_chip8
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ chip8_anop()

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

Definition at line 10 of file analysis_chip8.c.

10  {
11  ut16 opcode = rz_read_be16(data);
12  // uint8_t x = (opcode >> 8) & 0x0F;
13  // uint8_t y = (opcode >> 4) & 0x0F;
14  uint8_t nibble = opcode & 0x0F;
15  uint16_t nnn = opcode & 0x0FFF;
16  uint8_t kk = opcode & 0xFF;
17  op->size = 2;
18  op->addr = addr;
20  switch (opcode & 0xF000) {
21  case 0x0000:
22  if (opcode == 0x00EE) {
24  }
25  break;
26  case 0x1000:
28  op->jump = nnn;
29  break;
30  case 0x2000:
32  op->jump = nnn;
33  break;
34  case 0x3000:
36  op->jump = addr + op->size * 2;
37  op->fail = addr + op->size;
38  break;
39  case 0x4000:
41  op->jump = addr + op->size * 2;
42  op->fail = addr + op->size;
43  break;
44  case 0x5000:
46  op->jump = addr + op->size * 2;
47  op->fail = addr + op->size;
48  break;
49  case 0x6000:
51  break;
52  case 0x7000:
54  break;
55  case 0x8000: {
56  switch (nibble) {
57  case 0x0:
59  break;
60  case 0x1:
61  op->type = RZ_ANALYSIS_OP_TYPE_OR;
62  break;
63  case 0x2:
65  break;
66  case 0x3:
68  break;
69  case 0x4:
71  break;
72  case 0x5:
74  break;
75  case 0x6:
77  break;
78  case 0x7:
80  break;
81  case 0xE:
83  break;
84  }
85  } break;
86  case 0x9000:
87  if (nibble == 0) {
89  op->jump = addr + op->size * 2;
90  op->fail = addr + op->size;
91  }
92  break;
93  case 0xA000:
95  break;
96  case 0xB000:
98  /* FIXME: this is wrong as op->jump depends on register V0 */
99  op->jump = nnn;
100  break;
101  case 0xE000:
102  if (kk == 0x9E || kk == 0xA1) {
103  rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, addr, "KEYPAD");
105  op->jump = addr + op->size * 2;
106  op->fail = addr + op->size;
107  }
108  break;
109  case 0xF000: {
110  switch (kk) {
111  case 0x07:
112  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
113  break;
114  case 0x0A:
115  rz_meta_set_string(analysis, RZ_META_TYPE_COMMENT, addr, "KEYPAD");
116  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
117  break;
118  case 0x15:
119  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
120  break;
121  case 0x18:
122  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
123  break;
124  case 0x1E:
125  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
126  break;
127  case 0x29:
129  break;
130  case 0x30:
132  break;
133  case 0x33:
135  break;
136  case 0x55:
138  break;
139  case 0x65:
141  break;
142  case 0x75:
144  break;
145  case 0x85:
147  break;
148  }
149  } break;
150  }
151  return op->size;
152 }
uint16_t ut16
RZ_API bool rz_meta_set_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr, const char *s)
Definition: meta.c:141
@ RZ_META_TYPE_COMMENT
Definition: rz_analysis.h:295
@ RZ_ANALYSIS_OP_TYPE_SUB
Definition: rz_analysis.h:402
@ RZ_ANALYSIS_OP_TYPE_LOAD
Definition: rz_analysis.h:416
@ RZ_ANALYSIS_OP_TYPE_UNK
Definition: rz_analysis.h:388
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_AND
Definition: rz_analysis.h:411
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_OR
Definition: rz_analysis.h:410
@ RZ_ANALYSIS_OP_TYPE_STORE
Definition: rz_analysis.h:415
@ RZ_ANALYSIS_OP_TYPE_SHR
Definition: rz_analysis.h:406
@ RZ_ANALYSIS_OP_TYPE_RJMP
Definition: rz_analysis.h:370
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ 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
static ut16 rz_read_be16(const void *src)
Definition: rz_endian.h:50
unsigned short uint16_t
Definition: sftypes.h:30
unsigned char uint8_t
Definition: sftypes.h:31
Definition: dis.c:32
static int addr
Definition: z80asm.c:58

References addr, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_AND, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_LOAD, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_OR, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_RJMP, RZ_ANALYSIS_OP_TYPE_SHL, RZ_ANALYSIS_OP_TYPE_SHR, RZ_ANALYSIS_OP_TYPE_STORE, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_UNK, RZ_ANALYSIS_OP_TYPE_XOR, rz_meta_set_string(), RZ_META_TYPE_COMMENT, and rz_read_be16().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
}
RzAnalysisPlugin rz_analysis_plugin_chip8
@ 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 164 of file analysis_chip8.c.

◆ rz_analysis_plugin_chip8

RzAnalysisPlugin rz_analysis_plugin_chip8
Initial value:
= {
.name = "chip8",
.desc = "CHIP8 analysis plugin",
.license = "LGPL3",
.arch = "chip8",
.bits = 32,
.op = &chip8_anop,
}
static int chip8_anop(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)

Definition at line 154 of file analysis_chip8.c.