Move the hppa plugin from asm to anal ##refactor

This commit is contained in:
pancake 2022-09-05 16:17:05 +02:00 committed by pancake
parent ec873f35bd
commit 27556a3f74
10 changed files with 41 additions and 56 deletions

View File

@ -4,6 +4,7 @@ anal.amd29k
anal.arc
anal.evm_cs
anal.arm_cs
anal.hppa_gnu
anal.arm_v35
anal.arm_gnu
anal.jdh8
@ -70,7 +71,6 @@ esil.dummy
asm.arm
asm.arm_winedbg
asm.null
asm.hppa_gnu
asm.or1k
asm.ppc_as
asm.lanai_gnu

View File

@ -11,6 +11,7 @@ anal.bf
anal.chip8
anal.cr16
anal.cris
anal.hppa_gnu
anal.dalvik
anal.gb
anal.h8300
@ -63,7 +64,6 @@ esil.dummy
asm.arm
asm.arm_winedbg
asm.null
asm.hppa_gnu
asm.or1k
asm.ppc_as
asm.lanai_gnu

View File

@ -28,6 +28,7 @@ anal.or1k
anal.ppc_gnu
anal.mcs96
anal.s390_gnu
anal.hppa_gnu
anal.lm32
anal.sh
anal.sparc_gnu
@ -50,7 +51,6 @@ anal.propeller
esil.dummy
asm.arm_winedbg
asm.null
asm.hppa_gnu
asm.or1k
asm.ppc_as
asm.lanai_gnu

View File

@ -13,6 +13,7 @@ anal.gb
anal.mcs96
anal.i8080
anal.java
anal.hppa_gnu
anal.kvx
anal.lh5801
anal.lm32
@ -42,7 +43,6 @@ anal.riscv
anal.propeller
esil.dummy
asm.arm
asm.hppa_gnu
asm.lanai_gnu
asm.arm_as
asm.x86_as

View File

@ -1,14 +1,6 @@
/* radare - LGPL - Copyright 2015 - pancake */
/* radare - LGPL - Copyright 2015-2022 - pancake */
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_asm.h>
#include "disas-asm.h"
static R_TH_LOCAL unsigned long Offset = 0;
@ -16,16 +8,6 @@ static R_TH_LOCAL RStrBuf *buf_global = NULL;
static R_TH_LOCAL unsigned char bytes[4];
static int hppa_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, ut32 length, struct disassemble_info *info) {
#if 0 // XXX wtf ?!
if (length == 4) {
// swap
myaddr[0] = bytes[3];
myaddr[1] = bytes[2];
myaddr[2] = bytes[1];
myaddr[3] = bytes[0];
return 0;
}
#endif
int delta = (memaddr - Offset);
if (delta < 0) {
return -1; // disable backward reads
@ -48,48 +30,53 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in
DECLARE_GENERIC_PRINT_ADDRESS_FUNC()
DECLARE_GENERIC_FPRINTF_FUNC()
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
struct disassemble_info disasm_obj;
if (len < 4) {
return -1;
static int hppa_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
struct disassemble_info disasm_obj = {0};
if (mask & R_ANAL_OP_MASK_DISASM) {
buf_global = r_strbuf_new (NULL);
}
buf_global = &op->buf_asm;
Offset = a->pc;
memcpy (bytes, buf, 4); // TODO handle thumb
Offset = addr;
memcpy (bytes, buf, R_MIN (sizeof (bytes), len)); // TODO handle thumb
/* prepare disassembler */
memset (&disasm_obj, '\0', sizeof (struct disassemble_info));
disasm_obj.disassembler_options = (a->config->bits == 64)?"64":"";
disasm_obj.buffer = bytes;
disasm_obj.read_memory_func = &hppa_buffer_read_memory;
disasm_obj.symbol_at_address_func = &symbol_at_address;
disasm_obj.memory_error_func = &memory_error_func;
disasm_obj.print_address_func = &generic_print_address_func;
disasm_obj.endian = BFD_ENDIAN_BIG;
disasm_obj.endian = !a->config->big_endian;
disasm_obj.fprintf_func = &generic_fprintf_func;
disasm_obj.stream = stdout;
op->size = print_insn_hppa ((bfd_vma)Offset, &disasm_obj);
if (op->size == -1) {
r_strbuf_set (&op->buf_asm, "(data)");
if (mask & R_ANAL_OP_MASK_DISASM) {
op->mnemonic = r_strbuf_drain (buf_global);
for (char *c = op->mnemonic; *c != 0; c++) {
if (*c == '\t') {
*c = ' ';
}
}
buf_global = NULL;
}
return op->size;
}
RAsmPlugin r_asm_plugin_hppa_gnu = {
RAnalPlugin r_anal_plugin_hppa_gnu = {
.name = "hppa",
.arch = "hppa",
.license = "GPL3",
.bits = 32,
.cpus = "",
.bits = 16,
.endian = R_SYS_ENDIAN_BIG,
.desc = "HP PA-RISC",
.disassemble = &disassemble
.op = &hppa_op
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_hppa_gnu,
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_hppa_gnu,
.version = R2_VERSION
};
#endif

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

@ -0,0 +1,12 @@
OBJ_HPPA=anal_hppa_gnu.o
OBJ_HPPA+=../../asm/arch/hppa/gnu/hppa-dis.o
STATIC_OBJ+=${OBJ_HPPA}
TARGET_HPPA=anal_hppa_gnu.${EXT_SO}
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_HPPA}
${TARGET_HPPA}: ${OBJ_HPPA}
${CC} $(call libname,anal_hppa) ${LDFLAGS} ${CFLAGS} -o anal_hppa_gnu.${EXT_SO} ${OBJ_HPPA}
endif

View File

@ -11,7 +11,6 @@ r_asm_sources = [
join_paths('p','asm_arm.c'),
join_paths('p','asm_arm_winedbg.c'),
#join_paths('p','asm_gas.c'),
#join_paths('p','asm_hppa_gnu.c'),
'arch/arm/gnu/floatformat.c',
join_paths('p','asm_lanai_gnu.c'),
join_paths('p','asm_m68k_gnu.c'),
@ -31,7 +30,6 @@ r_asm_sources = [
#join_paths('arch','hexagon','gnu','hexagon-dis.c'),
#join_paths('arch','hexagon','gnu','hexagon-opc.c'),
#join_paths('arch','hexagon','gnu','safe-ctype.c'),
#join_paths('arch','hppa','gnu','hppa-dis.c'),
#join_paths('arch','i8080','i8080dis.c'),
join_paths('arch','lanai','gnu','lanai-dis.c'),
join_paths('arch','lanai','gnu','lanai-opc.c'),

View File

@ -1,12 +0,0 @@
OBJ_HPPA=asm_hppa_gnu.o
OBJ_HPPA+=../arch/hppa/gnu/hppa-dis.o
STATIC_OBJ+=${OBJ_HPPA}
TARGET_HPPA=asm_hppa_gnu.${EXT_SO}
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_HPPA}
${TARGET_HPPA}: ${OBJ_HPPA}
${CC} $(call libname,asm_hppa) ${LDFLAGS} ${CFLAGS} -o asm_hppa_gnu.${EXT_SO} ${OBJ_HPPA}
endif

View File

@ -2282,6 +2282,7 @@ extern RAnalPlugin r_anal_plugin_pyc;
extern RAnalPlugin r_anal_plugin_pickle;
extern RAnalPlugin r_anal_plugin_evm_cs;
extern RAnalPlugin r_anal_plugin_bpf;
extern RAnalPlugin r_anal_plugin_hppa_gnu;
extern RAnalPlugin r_anal_plugin_lm32;
extern RAnalEsilPlugin r_esil_plugin_dummy;

View File

@ -183,7 +183,6 @@ extern RAsmPlugin r_asm_plugin_arm;
extern RAsmPlugin r_asm_plugin_arm_winedbg;
extern RAsmPlugin r_asm_plugin_null;
extern RAsmPlugin r_asm_plugin_h8300;
extern RAsmPlugin r_asm_plugin_hppa_gnu;
extern RAsmPlugin r_asm_plugin_lanai_gnu;
extern RAsmPlugin r_asm_plugin_nios2;
extern RAsmPlugin r_asm_plugin_or1k;