Rizin
unix-like reverse engineering framework and cli tools
analysis_i8080.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2012 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 // This file is based on the Z80 analyser and modified for
5 // the Intel 8080 disassembler by Alexander Demin, 2012.
6 
7 #include <string.h>
8 #include <rz_types.h>
9 #include <rz_lib.h>
10 #include <rz_asm.h>
11 #include <rz_analysis.h>
12 // hack
13 #include "../../asm/arch/i8080/i8080dis.c"
14 
15 static int i8080_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask) {
16  char out[32];
17  int ilen = i8080_disasm(data, out, len);
18  op->addr = addr;
20  switch (data[0]) {
21  case 0x00:
23  break;
24  case 0x03:
25  case 0x04:
26  case 0x0c:
27  case 0x13:
28  case 0x14:
29  case 0x1c:
30  case 0x23:
31  case 0x24:
32  case 0x2c:
33  case 0x33:
34  case 0x34:
35  case 0x3c:
36  op->type = RZ_ANALYSIS_OP_TYPE_ADD; // INC
37  break;
38  case 0x09:
39  case 0x19:
40  case 0x29:
41  case 0x39:
42  case 0x80:
43  case 0x81:
44  case 0x82:
45  case 0x83:
46  case 0x84:
47  case 0x85:
48  case 0x86:
49  case 0x87:
50  case 0xc6:
52  break;
53  case 0x90:
54  case 0x91:
55  case 0x92:
56  case 0x93:
57  case 0x94:
58  case 0x95:
59  case 0x96:
60  case 0x97:
61  case 0xd6:
63  break;
64  case 0xc0:
65  case 0xc8:
66  case 0xd0:
67  case 0xd8:
68  case 0xe0:
69  case 0xe8:
70  case 0xf0:
71  case 0xf8:
73  break;
74  case 0xc9:
76  break;
77  case 0x05:
78  case 0x0b:
79  case 0x0d:
80  case 0x15:
81  case 0x1b:
82  case 0x1d:
83  case 0x25:
84  case 0x2b:
85  case 0x2d:
86  case 0x35:
87  case 0x3b:
88  case 0x3d:
89  // XXXX: DEC
91  break;
92  case 0xc5:
93  case 0xd5:
94  case 0xe5:
95  case 0xf5:
97  break;
98  case 0xc1:
99  case 0xd1:
100  case 0xe1:
101  case 0xf1:
102  op->type = RZ_ANALYSIS_OP_TYPE_POP;
103  break;
104  case 0x40:
105  case 0x49:
106  case 0x52:
107  case 0x5b:
108  case 0x64:
109  case 0x6d:
110  case 0x76:
111  case 0x7f:
112  op->type = RZ_ANALYSIS_OP_TYPE_TRAP; // HALT
113  break;
114  case 0x10:
115  case 0x18:
116  case 0x20:
117  case 0x28:
118  case 0x30:
119  case 0x38:
120  case 0xc2:
121  case 0xc3:
122  case 0xca:
123  case 0xd2:
124  case 0xda:
125  case 0xe2:
126  case 0xe9:
127  case 0xea:
128  case 0xf2:
129  case 0xfa:
130  op->type = RZ_ANALYSIS_OP_TYPE_JMP; // jmpz
131  break;
132 
133  case 0xc4:
134  case 0xcc:
135  case 0xcd:
136  case 0xd4:
137  case 0xdc:
138  case 0xdd:
139  case 0xe4:
140  case 0xec:
141  case 0xed:
142  case 0xf4:
143  case 0xfc:
144  case 0xfd:
146  break;
147  case 0xc7: // rst 0
148  op->jump = 0x00;
149  op->fail = addr + ilen;
150  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
151  break;
152  case 0xcf: // rst 8
153  op->jump = 0x08;
154  op->fail = addr + ilen;
155  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
156  break;
157  case 0xd7: // rst 16
158  op->jump = 0x10;
159  op->fail = addr + ilen;
160  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
161  break;
162  case 0xdf: // rst 24
163  op->jump = 0x18;
164  op->fail = addr + ilen;
165  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
166  break;
167  case 0xe7: // rst 32
168  op->jump = 0x20;
169  op->fail = addr + ilen;
170  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
171  break;
172  case 0xef: // rst 40
173  op->jump = 0x28;
174  op->fail = addr + ilen;
175  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
176  break;
177  case 0xf7: // rst 48
178  op->jump = 0x30;
179  op->fail = addr + ilen;
180  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
181  break;
182  case 0xff: // rst 56
183  op->jump = 0x38;
184  op->fail = addr + ilen;
185  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
186  break; // copypasta from gb and z80
187  }
188  return op->size = ilen;
189 }
190 
192  .name = "i8080",
193  .desc = "I8080 CPU code analysis plugin",
194  .license = "LGPL3",
195  .arch = "i8080",
196  .bits = 16,
197  .op = &i8080_op,
198 };
199 
200 #ifndef RZ_PLUGIN_INCORE
203  .data = &rz_analysis_plugin_i8080,
205 };
206 #endif
size_t len
Definition: 6502dis.c:15
#define mask()
static int i8080_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
RZ_API RzLibStruct rizin_plugin
RzAnalysisPlugin rz_analysis_plugin_i8080
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define RZ_API
int i8080_disasm(unsigned char const *const code, char *text, int text_sz)
uint8_t ut8
Definition: lh5801.h:11
RzAnalysisOpMask
Definition: rz_analysis.h:439
@ RZ_ANALYSIS_OP_TYPE_SUB
Definition: rz_analysis.h:402
@ RZ_ANALYSIS_OP_TYPE_UNK
Definition: rz_analysis.h:388
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_TRAP
Definition: rz_analysis.h:392
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_CRET
Definition: rz_analysis.h:386
@ RZ_ANALYSIS_OP_TYPE_PUSH
Definition: rz_analysis.h:397
@ RZ_ANALYSIS_OP_TYPE_POP
Definition: rz_analysis.h:398
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_NOP
Definition: rz_analysis.h:389
@ 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