Add armv7 to the arm.v35 plugin ##disasm

This commit is contained in:
pancake 2021-10-19 20:21:36 +02:00 committed by GitHub
parent 8f31696ae2
commit 6ae90339fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 127 additions and 47 deletions

1
.gitignore vendored
View File

@ -63,6 +63,7 @@ libr/include/r_userconf.h
libr/include/r_version.h
libr/include/r_version.h.tmp
libr/asm/arch/arm/v35arm64/arch-arm64
libr/asm/arch/arm/v35arm64/arch-armv7
shlr/capstone/
shlr/java/out
shlr/java/out.exe

View File

@ -2,7 +2,7 @@ include ../config.mk
N=anal_arm_v35
V35ARM64_HOME=$(LIBR)/asm/arch/arm/v35arm64/
include ../asm/arch/arm/v35arm64/deps.mk
include ../asm/arch/arm/v35arm64/deps-arm64.mk
OBJ_ARM_V35=anal_arm_v35.o
# OBJ_ARM_V35+=${V35ARM64_LINK}

View File

@ -25,11 +25,7 @@ SDB=$(SDB_PATH)/sdb
gperfs:
PATH=$(SDB_PATH):$$PATH $(MAKE) -C d all
ifeq ($(HAVE_GPERF),1)
PATH=$(SDB_PATH):$$PATH cd d && for a in *.sdb ; do test $$a -nt `echo $$a.c|sed -e 's,.sdb,,'`; if [ $$? = 0 ]; then $(SDB) -t -C $$a ; fi ; done
else
PATH=$(SDB_PATH):$$PATH cd d && for a in *.sdb ; do test $$a -nt `echo $$a.c|sed -e 's,.sdb,,'`; if [ $$? = 0 ]; then $(SDB) -t -C $$a ; fi ; done
endif
plugins: ${LIBSO} ${LIBAR}
$(MAKE) -C d all

View File

@ -1,11 +1,16 @@
EXT_AR?=a
all: arch-arm64
all: arch-arm64 arch-armv7
$(MAKE) arm64dis.$(EXT_AR)
$(MAKE) armv7dis.$(EXT_AR)
V35ARM64_HOME=$(CURDIR)
include deps.mk
CFLAGS+=$(V35ARM64_CFLAGS) -fPIC
CFLAGS+=$(V35ARMV7_CFLAGS) -fPIC
ALIBS=$(addprefix arch-arm64/disassembler/,$(V35ARM64_OBJS))
ALIBS+=$(addprefix arch-armv7/armv7_disasm/,$(V35ARMV7_OBJS))
RANLIB?=ranlib
EXT_AR?=a
@ -17,10 +22,12 @@ mrproper: clean
.PHONY: all clean
ARCH_ARM64_COMMIT=91ff0d24ab189263eed241bc551484a2d0af69ec
ARCH_ARM64_COMMIT=3c5eaba46dab72ecb7d5f5b865a13fdeee95b464
ARCH_ARMV7_COMMIT=81d11bc9d89ae76661067223951bd2b626a1be0d
$(ALIBS): arch-arm64
$(ALIBS): arch-arm64 arch-armv7
## ARM64
arch-arm64:
git clone -q https://github.com/radareorg/vector35-arch-arm64 arch-arm64
cd arch-arm64 && git checkout -q radare2 > /dev/null && git reset --hard $(ARCH_ARM64_COMMIT)
@ -29,3 +36,13 @@ $(V35ARM64_HOME)/arm64dis.a arm64dis.a: $(ALIBS)
rm -f arm64dis.$(EXT_AR)
$(AR) q arm64dis.$(EXT_AR) $(ALIBS)
$(RANLIB) arm64dis.$(EXT_AR)
## ARMV7
arch-armv7:
git clone -q https://github.com/radareorg/vector35-arch-armv7 arch-armv7
cd arch-armv7 && git checkout -q radare2 > /dev/null && git reset --hard $(ARCH_ARMV7_COMMIT)
$(V35ARMV7_HOME)/armv7dis.a armv7dis.a: $(ALIBS)
rm -f armv7dis.$(EXT_AR)
$(AR) q armv7dis.$(EXT_AR) $(ALIBS)
$(RANLIB) armv7dis.$(EXT_AR)

View File

@ -0,0 +1,33 @@
V35ARM64_SRCDIR=$(V35ARM64_HOME)/arch-arm64/disassembler/
V35ARM64_CFLAGS=-I$(V35ARM64_SRCDIR)
# V35ARM64_OBJS+=arm64dis.o
# V35ARM64_OBJS+=encodings.o
# V35ARM64_OBJS+=test.o
V35ARM64_OBJS+=decode.o
V35ARM64_OBJS+=decode0.o
V35ARM64_OBJS+=decode1.o
V35ARM64_OBJS+=decode2.o
V35ARM64_OBJS+=decode_fields32.o
V35ARM64_OBJS+=decode_scratchpad.o
V35ARM64_OBJS+=encodings_dec.o
V35ARM64_OBJS+=encodings_fmt.o
V35ARM64_OBJS+=format.o
V35ARM64_OBJS+=gofer.o
V35ARM64_OBJS+=operations.o
V35ARM64_OBJS+=pcode.o
V35ARM64_OBJS+=regs.o
V35ARM64_OBJS+=sysregs.o
V35ARM64_LINK=$(addprefix $(V35ARM64_SRCDIR),$(V35ARM64_OBJS))
V35ARM64_LIBS=$(V35ARM64_HOME)/arm64dis.a
${V35ARM64_LINK}: $(V35ARM64_SRCDIR)
$(V35ARM64_SRCDIR):
$(MAKE) $(V35ARM64_HOME)/arm64dis.a
# $(MAKE) git-clone-arm64v35
git-clone-arm64v35: # $(V35ARM64_HOME)/arm64dis.a:
$(MAKE) -C $(V35ARM64_HOME) arch-arm64
.PHONY: git-clone-arm64v35

View File

@ -0,0 +1,19 @@
V35ARMV7_ARCH?=arch-armv7
V35ARMV7_SRCDIR=$(V35ARM64_HOME)/$(V35ARMV7_ARCH)/armv7_disasm/
V35ARMV7_CFLAGS=-I$(V35ARMV7_SRCDIR)
V35ARMV7_OBJS+=armv7.c
V35ARMV7_LINK=$(addprefix $(V35ARMV7_SRCDIR),$(V35ARMV7_OBJS))
V35ARMV7_LIBS=$(V35ARM64_HOME)/armv7dis.a
${V35ARMV7_LINK}: $(V35ARMV7_SRCDIR)
$(V35ARMV7_SRCDIR):
$(MAKE) $(V35ARM64_HOME)/armv7dis.a
git-clone-armv7v35: # $(V35ARM64_HOME)/armv7dis.a:
$(MAKE) -C $(V35ARM64_HOME) arch-armv7
.PHONY: git-clone-armv7v35

View File

@ -1,34 +1,4 @@
jedum:
V35ARM64_ARCH?=arch-arm64
V35ARM64_SRCDIR=$(V35ARM64_HOME)/$(V35ARM64_ARCH)/disassembler/
V35ARM64_CFLAGS=-I$(V35ARM64_SRCDIR)
# V35ARM64_OBJS+=arm64dis.o
# V35ARM64_OBJS+=encodings.o
# V35ARM64_OBJS+=test.o
V35ARM64_OBJS+=decode.o
V35ARM64_OBJS+=decode0.o
V35ARM64_OBJS+=decode1.o
V35ARM64_OBJS+=decode2.o
V35ARM64_OBJS+=decode_fields32.o
V35ARM64_OBJS+=decode_scratchpad.o
V35ARM64_OBJS+=encodings_dec.o
V35ARM64_OBJS+=encodings_fmt.o
V35ARM64_OBJS+=format.o
V35ARM64_OBJS+=gofer.o
V35ARM64_OBJS+=operations.o
V35ARM64_OBJS+=pcode.o
V35ARM64_OBJS+=regs.o
V35ARM64_OBJS+=sysregs.o
V35ARM64_LINK=$(addprefix $(V35ARM64_SRCDIR),$(V35ARM64_OBJS))
V35ARM64_LIBS=$(V35ARM64_HOME)/arm64dis.a
${V35ARM64_LINK}: $(V35ARM64_SRCDIR)
$(V35ARM64_SRCDIR):
$(MAKE) $(V35ARM64_HOME)/arm64dis.a
# $(MAKE) git-clone-arm64v35
git-clone-arm64v35: # $(V35ARM64_HOME)/arm64dis.a:
$(MAKE) -C $(V35ARM64_HOME) arch-arm64
.PHONY: git-clone-arm64v35
include $(CURDIR)/deps-arm64.mk
include $(CURDIR)/deps-armv7.mk

View File

@ -1,9 +1,10 @@
# vector35 arm64 disassembler
OBJ_ARMV35=asm_arm_v35.o
V35ARM64_HOME=$(shell pwd)/arch/arm/v35arm64/
include arch/arm/v35arm64/deps.mk
OBJ_ARMV35+=asm_arm_v35_v7.o
V35ARM64_HOME=arch/arm/v35arm64/
OBJ_ARMV35+=$(V35ARM64_LINK)
OBJ_ARMV35+=$(V35ARMV7_LINK)
STATIC_OBJ+=${OBJ_ARMV35}
SHARED_OBJ+=${SHARED_ARMV35}
@ -12,11 +13,17 @@ TARGET_ARMV35=asm_arm_v35.${LIBEXT}
ALL_TARGETS+=${TARGET_ARMV35}
%.o: %.c
$(CC) $(V35ARM64_CFLAGS) $(CFLAGS) -o $@ -c $<
$(CC) $(V35ARM64_CFLAGS) $(V35ARMV7_CFLAGS) $(CFLAGS) -o $@ -c $<
$(OBJC_ARMV35): $(V35ARM64_SRCDIR) $(ARM64_LINK)
$(OBJC_ARM64V35): $(V35ARM64_SRCDIR) $(ARM64_LINK)
$(OBJC_ARMV7V35): $(V35ARMV7_SRCDIR) $(ARMV7_LINK)
${TARGET_ARMV35}: $(V35ARM64_LINK) $(OBJ_ARMV35)
${CC} $(call libname,asm_arm_v35) -o $(TARGET_ARMV35) \
$(V35ARMV7_LDFLAGS) \
$(V35ARMV7_CFLAGS) \
${OBJ_ARMV35} $(V35ARM64_LDFLAGS) \
${LDFLAGS} $(V35ARM64_CFLAGS) $(CFLAGS)
include $(CURDIR)/../arch/arm/v35arm64/deps-arm64.mk
# include arch/arm/v35arm64/deps-armv7.mk

View File

@ -8,7 +8,12 @@
#include "encodings_dec.h"
#include "arm64dis.h"
extern int disassemble_armv7(RAsm *a, RAsmOp *op, const ut8 *buf, int len);
static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
if (a->bits == 16 || a->bits == 32) {
return disassemble_armv7 (a, op, buf, len);
}
Instruction inst = {0};
char output[256];
op->size = 4;
@ -87,7 +92,7 @@ RAsmPlugin r_asm_plugin_arm_v35 = {
.desc = "Vector35 ARM64 disassembler",
.license = "Apache",
.arch = "arm",
.bits = 64,
.bits = 16|32|64,
.endian = R_SYS_ENDIAN_LITTLE,
.mnemonics = mnemonics,
.disassemble = &disassemble,

View File

@ -0,0 +1,27 @@
/* radare2 - LGPL - Copyright 2021 - pancake, aemmitt */
#include <r_asm.h>
#include <r_lib.h>
#include "../arch/arm/v35arm64/arch-armv7/armv7_disasm/armv7.c"
// #include "armv7.h"
#define DISASM_SUCCESS 0
R_API int disassemble_armv7(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
Instruction inst = {0};
char output[256];
int fc = armv7_disassemble (&inst, output, sizeof (output));
if (fc != DISASM_SUCCESS) {
return -1;
}
op->size = 2;
r_str_trim_tail (output);
r_str_replace_char (output, '\t', ' ');
r_str_replace_char (output, '#', ' ');
if (r_str_startswith (output, "UNDEF")) {
r_strbuf_set (&op->buf_asm, "undefined");
return 2 - (a->pc % 2);
}
r_strbuf_set (&op->buf_asm, output);
return op->size;
}

View File

@ -10,10 +10,15 @@ gmake --version > /dev/null 2>&1
[ $? = 0 ] && MAKE=gmake
${MAKE} -C shlr capstone > /dev/null 2>&1 || exit 1
echo OK
printf "[*] Checking out vector35... "
printf "[*] Checking out vector35-arm64... "
rm -rf libr/asm/arch/arm/v35arm64/arch-arm64
${MAKE} -C libr/asm/arch/arm/v35arm64 arch-arm64 > /dev/null || exit 1
echo OK
printf "[*] Checking out vector35-armv7... "
rm -rf libr/asm/arch/arm/v35arm64/arch-armv7
${MAKE} -C libr/asm/arch/arm/v35arm64 arch-armv7 > /dev/null || exit 1
echo OK
if [ `uname` = Linux ]; then
./configure --with-rpath
else