From 64636e9505f9ca8b408958d3c01ac8e3ce254a9b Mon Sep 17 00:00:00 2001 From: condret Date: Tue, 15 Sep 2015 20:44:42 +0000 Subject: [PATCH] add basic 6502-analysis plugin for @ricardoquesada --- libr/anal/p/6502.mk | 9 +++ libr/anal/p/Makefile | 2 +- libr/anal/p/anal_6502.c | 155 ++++++++++++++++++++++++++++++++++++++++ libr/include/r_anal.h | 1 + plugins.def.cfg | 1 + 5 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 libr/anal/p/6502.mk create mode 100644 libr/anal/p/anal_6502.c diff --git a/libr/anal/p/6502.mk b/libr/anal/p/6502.mk new file mode 100644 index 0000000000..6ad5ad9201 --- /dev/null +++ b/libr/anal/p/6502.mk @@ -0,0 +1,9 @@ +OBJ_6502=anal_6502.o + +STATIC_OBJ+=${OBJ_6502} +TARGET_6502=anal_6502.${EXT_SO} + +ALL_TARGETS+=${TARGET_6502} + +${TARGET_6502}: ${OBJ_6502} + ${CC} $(call libname,anal_6502) ${LDFLAGS} ${CFLAGS} -o anal_6502.${EXT_SO} ${OBJ_6502} diff --git a/libr/anal/p/Makefile b/libr/anal/p/Makefile index a11bb57e1c..eaa259862e 100644 --- a/libr/anal/p/Makefile +++ b/libr/anal/p/Makefile @@ -12,7 +12,7 @@ all: ${ALL_TARGETS} ; ALL_TARGETS= # TODO: rename to enabled plugins -ARCHS=null.mk x86_udis.mk ppc_gnu.mk ppc_cs.mk arm_gnu.mk avr.mk csr.mk dalvik.mk sh.mk ebc.mk gb.mk malbolge.mk ws.mk h8300.mk cr16.mk v850.mk msp430.mk sparc_gnu.mk sparc_cs.mk x86_cs.mk cris.mk +ARCHS=null.mk x86_udis.mk ppc_gnu.mk ppc_cs.mk arm_gnu.mk avr.mk csr.mk dalvik.mk sh.mk ebc.mk gb.mk malbolge.mk ws.mk h8300.mk cr16.mk v850.mk msp430.mk sparc_gnu.mk sparc_cs.mk x86_cs.mk cris.mk 6502.mk include $(ARCHS) clean: diff --git a/libr/anal/p/anal_6502.c b/libr/anal/p/anal_6502.c new file mode 100644 index 0000000000..6a4384f33a --- /dev/null +++ b/libr/anal/p/anal_6502.c @@ -0,0 +1,155 @@ +/* radare - LGPL - Copyright 2015 - condret */ + + +#include +#include +#include +#include +#include +#include "../../asm/arch/snes/snes_op_table.h" + +static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) { + memset (op, '\0', sizeof (RAnalOp)); + op->size = snes_op[data[0]].len; //snes-arch is similiar to nes/6502 + op->addr = addr; + op->type = R_ANAL_OP_TYPE_UNK; + switch (data[0]) { + case 0x80: + case 0x02: + case 0x03: + case 0x04: + case 0x12: + case 0x13: + case 0x14: + case 0x22: + case 0x23: + case 0x32: + case 0x33: + case 0x34: + case 0x42: + case 0x43: + case 0x44: + case 0x52: + case 0x53: + case 0x54: + case 0x62: + case 0x63: + case 0x64: + case 0x72: + case 0x73: + case 0x74: + case 0x82: + case 0x83: + case 0x92: + case 0x93: + case 0xa3: + case 0xb2: + case 0xb3: + case 0xc2: + case 0xc3: + case 0xd2: + case 0xd3: + case 0xd4: + case 0xe2: + case 0xe3: + case 0xf2: + case 0xf3: + case 0xf4: + case 0x07: + case 0x17: + case 0x27: + case 0x37: + case 0x47: + case 0x57: + case 0x67: + case 0x77: + case 0x87: + case 0x97: + case 0xa7: + case 0xb7: + case 0xc7: + case 0xd7: + case 0xe7: + case 0xf7: + case 0x89: + case 0x0b: + case 0x0c: + case 0x1a: + case 0x1b: + case 0x1c: + case 0x2b: + case 0x3a: + case 0x3b: + case 0x3c: + case 0x4b: + case 0x5a: + case 0x5b: + case 0x5c: + case 0x6b: + case 0x7a: + case 0x7b: + case 0x7c: + case 0x8b: + case 0x9b: + case 0x9c: + case 0xab: + case 0xbb: + case 0xcb: + case 0xda: + case 0xdb: + case 0xdc: + case 0xeb: + case 0xfa: + case 0xfb: + case 0xfc: + case 0x0f: + case 0x1f: + case 0x2f: + case 0x3f: + case 0x4f: + case 0x5f: + case 0x6f: + case 0x7f: + case 0x8f: + case 0x9e: + case 0x9f: + case 0xaf: + case 0xbf: + case 0xcf: + case 0xdf: + case 0xef: + case 0xff: + op->size = 1; + op->type = R_ANAL_OP_TYPE_ILL; //those do not exist for 6502 - snes only + break; + case 0xea: + op->type = R_ANAL_OP_TYPE_NOP; + break; + } + return op->size; +} + +struct r_anal_plugin_t r_anal_plugin_6502 = { + .name = "6502", + .desc = "6502/NES analysis plugin", + .license = "LGPL3", + .arch = R_SYS_ARCH_NONE, + .bits = 8, + .init = NULL, + .fini = NULL, + .op = &_6502_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_6502, + .version = R2_VERSION +}; +#endif diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h index 7605706d8f..b3696fcc4d 100644 --- a/libr/include/r_anal.h +++ b/libr/include/r_anal.h @@ -1489,6 +1489,7 @@ extern RAnalPlugin r_anal_plugin_propeller; extern RAnalPlugin r_anal_plugin_msp430; extern RAnalPlugin r_anal_plugin_cris; extern RAnalPlugin r_anal_plugin_v810; +extern RAnalPlugin r_anal_plugin_6502; #ifdef __cplusplus } #endif diff --git a/plugins.def.cfg b/plugins.def.cfg index c27ffb2c0e..c80adfeca3 100644 --- a/plugins.def.cfg +++ b/plugins.def.cfg @@ -34,6 +34,7 @@ anal.x86_udis anal.xcore_cs anal.z80 anal.v810 +anal.6502 asm.6502 asm.8051 asm.arc