Initial implementation of i8080 analyser.

This commit is contained in:
Alexander 2012-10-29 20:43:08 +00:00
parent 278a24126e
commit 2c5cd9b32d
6 changed files with 184 additions and 1 deletions

167
libr/anal/p/anal_i8080.c Normal file
View File

@ -0,0 +1,167 @@
/* radare - LGPL - Copyright 2012 - pancake<nopcode.org> */
#include <string.h>>
#include <r_types.h>
#include <r_lib.h>
#include <r_asm.h>
#include <r_anal.h>
// hack
#include "../../asm/arch/i8080/i8080dis.c"
static int i8080_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) {
char out[32];
int ilen = i8080_disasm (data, out, len);
memset (op, '\0', sizeof (RAnalOp));
op->addr = addr;
op->type = R_ANAL_OP_TYPE_UNK;
switch (data[0]) {
case 0x00:
op->type = R_ANAL_OP_TYPE_NOP;
break;
case 0x03:
case 0x04:
case 0x0c:
case 0x13:
case 0x14:
case 0x1c:
case 0x23:
case 0x24:
case 0x2c:
case 0x33:
case 0x34:
case 0x3c:
op->type = R_ANAL_OP_TYPE_ADD; // INC
break;
case 0x09:
case 0x19:
case 0x29:
case 0x39:
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0xc6:
op->type = R_ANAL_OP_TYPE_ADD;
break;
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0xd6:
op->type = R_ANAL_OP_TYPE_SUB;
break;
case 0xc0:
case 0xc8:
case 0xc9:
case 0xd0:
case 0xd8:
case 0xe0:
case 0xe8:
case 0xf0:
case 0xf8:
op->type = R_ANAL_OP_TYPE_RET;
break;
case 0x05:
case 0x0b:
case 0x0d:
case 0x15:
case 0x1b:
case 0x1d:
case 0x25:
case 0x2b:
case 0x2d:
case 0x35:
case 0x3b:
case 0x3d:
// XXXX: DEC
op->type = R_ANAL_OP_TYPE_SUB;
break;
case 0xc5:
case 0xd5:
case 0xe5:
case 0xf5:
op->type = R_ANAL_OP_TYPE_PUSH;
break;
case 0xc1:
case 0xd1:
case 0xe1:
case 0xf1:
op->type = R_ANAL_OP_TYPE_POP;
break;
case 0x40:
case 0x49:
case 0x52:
case 0x5b:
case 0x64:
case 0x6d:
case 0x76:
case 0x7f:
op->type = R_ANAL_OP_TYPE_TRAP; // HALT
break;
case 0x10:
case 0x18:
case 0x20:
case 0x28:
case 0x30:
case 0x38:
case 0xc2:
case 0xc3:
case 0xca:
case 0xd2:
case 0xda:
case 0xe2:
case 0xe9:
case 0xea:
case 0xf2:
case 0xfa:
op->type = R_ANAL_OP_TYPE_JMP; // jmpz
break;
case 0xc4:
case 0xcc:
case 0xcd:
case 0xd4:
case 0xdc:
case 0xdd:
case 0xe4:
case 0xec:
case 0xed:
case 0xf4:
case 0xfc:
case 0xfd:
op->type = R_ANAL_OP_TYPE_CALL;
break;
}
return op->length = ilen;
}
struct r_anal_plugin_t r_anal_plugin_i8080 = {
.name = "i8080",
.arch = R_SYS_ARCH_I8080,
.bits = 16,
.desc = "I8080 CPU code analysis plugin",
.init = NULL,
.fini = NULL,
.op = &i8080_op,
.set_reg_profile = NULL,
.fingerprint_bb = NULL,
.fingerprint_fcn = NULL,
.diff_bb = NULL,
.diff_fcn = NULL,
.diff_eval = NULL
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_i8080
};
#endif

12
libr/anal/p/i8080.mk Normal file
View File

@ -0,0 +1,12 @@
OBJ_I8080=anal_i8080.o
STATIC_OBJ+=${OBJ_I8080}
TARGET_I8080=anal_i8080.${EXT_SO}
ALL_TARGETS+=${TARGET_I8080}
#LDFLAGS+=-L../../lib -lr_lib
#LDFLAGS+=-L../../syscall -lr_syscall
#LDFLAGS+=-L../../diff -lr_diff
${TARGET_I8080}: ${OBJ_I8080}
${CC} $(call libname,anal_z80) ${LDFLAGS} ${CFLAGS} -o anal_z80.${EXT_SO} ${OBJ_I8080}

View File

@ -815,6 +815,7 @@ extern RAnalPlugin r_anal_plugin_sparc;
extern RAnalPlugin r_anal_plugin_bf;
extern RAnalPlugin r_anal_plugin_m68k;
extern RAnalPlugin r_anal_plugin_z80;
extern RAnalPlugin r_anal_plugin_i8080;
extern RAnalPlugin r_anal_plugin_arc;
#endif

View File

@ -28,6 +28,7 @@
#define R_ASM_ARCH_BF R_SYS_ARCH_BF
#define R_ASM_ARCH_SH R_SYS_ARCH_SH
#define R_ASM_ARCH_Z80 R_SYS_ARCH_Z80
#define R_ASM_ARCH_I8080 R_SYS_ARCH_I8080
#define R_ASM_ARCH_ARC R_SYS_ARCH_ARC
#define R_ASM_GET_OFFSET(x,y,z) \

View File

@ -210,7 +210,8 @@ enum {
R_SYS_ARCH_AVR = 0x1000,
R_SYS_ARCH_DALVIK = 0x2000,
R_SYS_ARCH_Z80 = 0x4000,
R_SYS_ARCH_ARC = 0x8000
R_SYS_ARCH_ARC = 0x8000,
R_SYS_ARCH_I8080 = 0x10000,
};
/* os */

View File

@ -31,6 +31,7 @@ anal.x86
anal.x86_udis86
anal.x86_simple
anal.z80
anal.i8080
anal.arm
anal.arc
anal.bf