Remove asm.ebc and merge disasm into the anal ##refactor

This commit is contained in:
pancake 2021-12-16 18:27:45 +01:00 committed by GitHub
parent ea2c017c3a
commit 9986b6e464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 42 additions and 107 deletions

View File

@ -73,7 +73,6 @@ asm.dalvik
asm.dcpu16
asm.null
asm.hexagon
asm.ebc
asm.gb
asm.h8300
asm.hppa_gnu

View File

@ -10,7 +10,6 @@ anal.chip8
anal.cr16
anal.cris
anal.dalvik
anal.ebc
anal.gb
anal.h8300
anal.hexagon
@ -71,7 +70,6 @@ asm.dalvik
asm.dcpu16
asm.null
asm.hexagon
asm.ebc
asm.gb
asm.h8300
asm.hppa_gnu

View File

@ -58,7 +58,6 @@ asm.dalvik
asm.dcpu16
asm.null
asm.hexagon
asm.ebc
asm.gb
asm.h8300
asm.hppa_gnu

View File

@ -34,7 +34,6 @@ asm.cr16
asm.xap
asm.dalvik
asm.dcpu16
asm.ebc
asm.gb
asm.h8300
asm.i4004

View File

@ -42,7 +42,6 @@ r_anal_sources = [
'var.c',
'vtable.c',
'xrefs.c',
join_paths('p','esil_dummy.c'),
join_paths('p','anal_6502.c'),
join_paths('p','anal_6502_cs.c'),
join_paths('p','anal_8051.c'),
@ -63,8 +62,8 @@ r_anal_sources = [
join_paths('p','anal_i4004.c'),
join_paths('p','anal_i8080.c'),
join_paths('p','anal_java.c'),
join_paths('p','anal_m68k_cs.c'),
join_paths('p','anal_m680x_cs.c'),
join_paths('p','anal_m68k_cs.c'),
join_paths('p','anal_malbolge.c'),
join_paths('p','anal_mcore.c'),
join_paths('p','anal_mips_cs.c'),
@ -80,11 +79,11 @@ r_anal_sources = [
join_paths('p','anal_pyc.c'),
join_paths('p','anal_riscv.c'),
join_paths('p','anal_rsp.c'),
join_paths('p','anal_s390_cs.c'),
join_paths('p','anal_sh.c'),
join_paths('p','anal_snes.c'),
join_paths('p','anal_sparc_cs.c'),
join_paths('p','anal_sparc_gnu.c'),
join_paths('p','anal_s390_cs.c'),
join_paths('p','anal_tms320.c'),
join_paths('p','anal_tms320_c55x_plus.c'),
#join_paths('p','anal_tms320c64x.c'),
@ -99,7 +98,9 @@ r_anal_sources = [
join_paths('p','anal_xcore_cs.c'),
#join_paths('p','anal_xtensa.c'),
join_paths('p','anal_z80.c'),
join_paths('p','esil_dummy.c'),
#join_paths('arch','gb','meta_gb_cmt.c'),
join_paths('arch','ebc','ebc_disas.c'),
join_paths('arch','hexagon','hexagon_anal.c'),
join_paths('..','asm','arch','amd29k','amd29k.c'),
join_paths('..','asm','arch','arm','winedbg','be_arm.c'),
@ -107,7 +108,6 @@ r_anal_sources = [
join_paths('..','asm','arch','avr','format.c'),
join_paths('..','asm','arch','avr','disasm.c'),
join_paths('..','asm','arch','cr16','cr16_disas.c'),
join_paths('..','asm','arch','ebc','ebc_disas.c'),
join_paths('..','asm','arch','h8300','h8300_disas.c'),
join_paths('..','asm','arch','hexagon','hexagon.c'),
join_paths('..','asm','arch','hexagon','hexagon_disas.c'),

View File

@ -1,51 +1,36 @@
/* radare - LGPL - Copyright 2012-2013 - pancake, fedor.sakharov */
/* radare - LGPL - Copyright 2012-2021 - pancake, fedor.sakharov */
#include <string.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_asm.h>
#include <r_anal.h>
#include <ebc_disas.h>
#include "../arch/ebc/ebc_disas.h"
static void ebc_anal_jmp8(RAnalOp *op, ut64 addr, const ut8 *buf) {
int jmpadr = (int8_t)buf[1];
op->jump = addr + 2 + (jmpadr * 2);
op->addr = addr;
op->fail = addr + 2;
if (TEST_BIT(buf[0], 7)) {
op->type = R_ANAL_OP_TYPE_CJMP;
} else {
op->type = R_ANAL_OP_TYPE_JMP;
}
op->jump = op->fail + (jmpadr * 2);
op->type = TEST_BIT (buf[0], 7) ? R_ANAL_OP_TYPE_CJMP: R_ANAL_OP_TYPE_JMP;
}
static void ebc_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) {
op->fail = addr + 6;
op->jump = (ut64)*(int32_t*)(buf + 2);
op->jump = r_read_le32 (buf + 2);
if (TEST_BIT (buf[1], 4)) {
op->jump += addr + 6;
}
if (buf[1] & 0x7) {
op->type = R_ANAL_OP_TYPE_UJMP;
} else {
if (TEST_BIT(buf[1], 7)) {
op->type = R_ANAL_OP_TYPE_CJMP;
} else {
op->type = R_ANAL_OP_TYPE_JMP;
}
op->type = (TEST_BIT (buf[1], 7)) ? R_ANAL_OP_TYPE_CJMP: R_ANAL_OP_TYPE_JMP;
}
}
static void ebc_anal_call(RAnalOp *op, ut64 addr, const ut8 *buf) {
int32_t addr_call;
op->fail = addr + 6;
if ((buf[1] & 0x7) == 0 && TEST_BIT(buf[0], 6) == 0
&& TEST_BIT(buf[0], 7)) {
addr_call = *(int32_t*)(buf + 2);
if ((buf[1] & 0x7) == 0 && TEST_BIT (buf[0], 6) == 0 && TEST_BIT (buf[0], 7)) {
int addr_call = r_read_le32 (buf + 2);
if (TEST_BIT(buf[1], 4)) {
op->jump = (addr + 6 + addr_call);
} else {
@ -58,28 +43,34 @@ static void ebc_anal_call(RAnalOp *op, ut64 addr, const ut8 *buf) {
}
static int ebc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
int ret;
ebc_command_t cmd;
ut8 opcode = buf[0] & EBC_OPCODE_MASK;
if (!op) {
return 2;
}
if (mask & R_ANAL_OP_MASK_DISASM) {
op->mnemonic = strdup ("invalid");
}
op->addr = addr;
ret = op->size = ebc_decode_command(buf, &cmd);
int ret = op->size = ebc_decode_command (buf, &cmd);
if (ret < 0) {
return ret;
op->type = R_ANAL_OP_TYPE_ILL;
return -1;
}
if (mask & R_ANAL_OP_MASK_DISASM) {
char *inststr = (cmd.operands[0]) ? r_str_newf ("%s %s", cmd.instr, cmd.operands): strdup (cmd.instr);
op->mnemonic = inststr;
}
switch (opcode) {
case EBC_JMP8:
ebc_anal_jmp8(op, addr, buf);
ebc_anal_jmp8 (op, addr, buf);
break;
case EBC_JMP:
ebc_anal_jmp(op, addr, buf);
ebc_anal_jmp (op, addr, buf);
break;
case EBC_MOVBW:
case EBC_MOVWW:
@ -157,16 +148,24 @@ static int ebc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len,
op->type = R_ANAL_OP_TYPE_UNK;
break;
}
return ret;
}
static int archinfo(RAnal *anal, int q) {
if (q == R_ANAL_ARCHINFO_MAX_OP_SIZE) {
return 18;
}
return 1;
}
RAnalPlugin r_anal_plugin_ebc = {
.name = "ebc",
.desc = "EBC code analysis plugin",
.desc = "EFI Bytecode architecture",
.license = "LGPL3",
.author = "Fedor Sakharov",
.archinfo = archinfo,
.arch = "ebc",
.bits = 64,
.bits = 32 | 64,
.op = &ebc_op,
};

View File

@ -1,13 +1,10 @@
OBJ_EBC=anal_ebc.o
CFLAGS+=-I../asm/arch/ebc/
OBJ_EBC+=../arch/ebc/ebc_disas.o
STATIC_OBJ+=$(OBJ_EBC)
CFLAGS+=-Iarch/ebc/
TARGET_EBC=anal_ebc.$(EXT_SO)
STATIC_OBJ+=${OBJ_EBC}
#OBJ_EBC+=../../../../../../../../../../../../../../../../../../../../${LTOP}/asm/arch/ebc/ebc_disas.o
OBJ_EBC+=../../asm/arch/ebc/ebc_disas.o
TARGET_EBC=anal_ebc.${EXT_SO}
ALL_TARGETS+=$(TARGET_EBC)
ALL_TARGETS+=${TARGET_EBC}
${TARGET_EBC}: ${OBJ_EBC} ${SHARED_OBJ}
${CC} $(call libname,anal_ebc) ${CFLAGS} \
-o ${TARGET_EBC} ${OBJ_EBC}
$(TARGET_EBC): $(OBJ_EBC) $(SHARED_OBJ)
$(CC) $(call libname,anal_ebc) $(CFLAGS) -o $(TARGET_EBC) $(OBJ_EBC)

View File

@ -22,7 +22,6 @@ r_asm_sources = [
join_paths('p','asm_cris_gnu.c'),
join_paths('p','asm_dalvik.c'),
join_paths('p','asm_dcpu16.c'),
join_paths('p','asm_ebc.c'),
#join_paths('p','asm_gas.c'),
join_paths('p','asm_gb.c'),
join_paths('p','asm_h8300.c'),
@ -108,7 +107,6 @@ r_asm_sources = [
#join_paths('arch','dcpu16','asm.c'),
#join_paths('arch','dcpu16','dis.c'),
#join_paths('arch','dcpu16','main.c'),
join_paths('arch','ebc','ebc_disas.c'),
#join_paths('arch','gb','gbasm.c'),
#join_paths('arch','gb','gbdis.c'),
join_paths('arch','h8300','h8300_disas.c'),
@ -196,7 +194,6 @@ r_asm_inc = [
join_paths('arch','mcore'),
join_paths('arch','v850'),
join_paths('arch','propeller'),
join_paths('arch','ebc'),
join_paths('arch','cr16'),
join_paths('arch','8051'),
join_paths('arch','v810'),

View File

@ -1,36 +0,0 @@
/* radare - LGPL - Copyright 2012-2018 - pancake, fedor sakharov */
#include <stdio.h>
#include <string.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_asm.h>
#include <ebc_disas.h>
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
ebc_command_t cmd = { {0}, {0} };
int ret = ebc_decode_command (buf, &cmd);
const char *buf_asm = (cmd.operands[0])
? sdb_fmt ("%s %s", cmd.instr, cmd.operands): cmd.instr;
r_asm_op_set_asm (op, buf_asm);
return op->size = ret;
}
RAsmPlugin r_asm_plugin_ebc = {
.name = "ebc",
.license = "LGPL3",
.desc = "EFI Bytecode",
.author = "Fedor Sakharov",
.arch = "ebc",
.bits = 32|64,
.endian = R_SYS_ENDIAN_LITTLE,
.disassemble = &disassemble,
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_ebc,
.version = R2_VERSION
};
#endif

View File

@ -1,15 +0,0 @@
EBC_ROOT=$(LIBR)/asm/arch/ebc
OBJ_EBC=asm_ebc.o
OBJ_EBC+=$(EBC_ROOT)/ebc_disas.o
CFLAGS+=-I$(EBC_ROOT)
STATIC_OBJ+=${OBJ_EBC}
TARGET_EBC=asm_ebc.${EXT_SO}
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_EBC}
${TARGET_EBC}: ${OBJ_EBC}
${CC} ${LDFLAGS} ${CFLAGS} \
-o ${TARGET_EBC} ${OBJ_EBC}
endif

View File

@ -218,7 +218,6 @@ extern RAsmPlugin r_asm_plugin_cr16;
extern RAsmPlugin r_asm_plugin_cris_gnu;
extern RAsmPlugin r_asm_plugin_dalvik;
extern RAsmPlugin r_asm_plugin_dcpu16;
extern RAsmPlugin r_asm_plugin_ebc;
extern RAsmPlugin r_asm_plugin_gb;
extern RAsmPlugin r_asm_plugin_h8300;
extern RAsmPlugin r_asm_plugin_hexagon;

View File

@ -190,7 +190,6 @@ asm_plugins += [
'cr16',
'dalvik',
'dcpu16',
'ebc',
'gb',
'h8300',
'hexagon',