* Add 'static-plugin' feature to r_asm module

* Make rabin2 support 'arm' instead of 'asm_arm' for -a (autoprefix 'asm_')
* Some build fixtures
* Static plugins are configurable in libr/config.mk and libr/config.h
This commit is contained in:
pancake 2009-03-08 23:49:15 +00:00
parent 9ecc5775a7
commit b2e785fc61
24 changed files with 239 additions and 117 deletions

11
doc/static-plugins Normal file
View file

@ -0,0 +1,11 @@
Edit libr/config.h and libr/config.mk
In libr/config.mk set a list of static asm plugins...
STATIC_ASM_PLUGINS=p/java.mk p/mips.mk
In libr/config.h define the list of struct plugins
#define R_ASM_STATIC_PLUGINS \
&r_asm_plugin_java, 0

View file

@ -1,5 +1,18 @@
NAME=r_asm
DEPS=r_lib r_util
OBJ=asm.o
foo: pre libr_asm.so plugins
CFLAGS+=-DCORELIB -Iarch/include -Iarch
include ../config.mk
include ${STATIC_ASM_PLUGINS}
STATIC_OBJS=$(subst ..,p/..,$(subst asm_,p/asm_,$(STATIC_OBJ)))
OBJ=asm.o ${STATIC_OBJS}
pre:
if [ ! -e libr_asm.so ]; then rm -f ${STATIC_OBJS} ; fi
plugins:
cd p && ${MAKE} all
include ../rules.mk

View file

@ -6,6 +6,10 @@
#include <r_util.h>
#include <r_asm.h>
#include <list.h>
#include "../config.h"
static struct r_asm_handle_t *asm_static_plugins[] =
{ R_ASM_STATIC_PLUGINS, 0 };
struct r_asm_t *r_asm_new()
{
@ -21,12 +25,15 @@ void r_asm_free(struct r_asm_t *a)
int r_asm_init(struct r_asm_t *a)
{
int i;
a->user = NULL;
INIT_LIST_HEAD(&a->asms);
r_asm_set_bits(a, 32);
r_asm_set_big_endian(a, 0);
r_asm_set_syntax(a, R_ASM_SYN_INTEL);
r_asm_set_pc(a, 0);
for(i=0;asm_static_plugins[i];i++)
r_asm_add(a, asm_static_plugins[i]);
return R_TRUE;
}
@ -37,8 +44,16 @@ void r_asm_set_user_ptr(struct r_asm_t *a, void *user)
int r_asm_add(struct r_asm_t *a, struct r_asm_handle_t *foo)
{
struct list_head *pos;
if (foo->init)
foo->init(a->user);
/* avoid dupped plugins */
list_for_each_prev(pos, &a->asms) {
struct r_asm_handle_t *h = list_entry(pos, struct r_asm_handle_t, list);
if (!strcmp(h->name, foo->name))
return R_FALSE;
}
list_add_tail(&(foo->list), &(a->asms));
return R_TRUE;
}

View file

@ -6,113 +6,23 @@ CFLAGS_IMP=-I../../include -I../arch/ -I../arch/include -w -fPIC -shared -Wl,-R.
# XXX
CFLAGS_IMP+=-DLIL_ENDIAN=1 -D__UNIX__
## X86
# udis86
OBJ_X86=asm_x86.o
OBJ_X86+=../arch/x86/udis86/syn.o
OBJ_X86+=../arch/x86/udis86/input.o
OBJ_X86+=../arch/x86/udis86/udis86.o
OBJ_X86+=../arch/x86/udis86/decode.o
OBJ_X86+=../arch/x86/udis86/itab.o
OBJ_X86+=../arch/x86/udis86/syn-intel.o
OBJ_X86+=../arch/x86/udis86/syn-att.o
# olly
OBJ_X86_OLLY=asm_x86_olly.o
OBJ_X86_OLLY+=../arch/x86/ollyasm/disasm.o
OBJ_X86_OLLY+=../arch/x86/ollyasm/asmserv.o
OBJ_X86_OLLY+=../arch/x86/ollyasm/assembl.o
## ARM
OBJ_ARM=asm_arm.o
# gnu arm-dis
OBJ_ARM+=../arch/arm/gnu/arm-dis.o
## MIPS
OBJ_MIPS=asm_mips.o
# gnu mips-dis
OBJ_MIPS+=../arch/mips/gnu/mips-dis.o
OBJ_MIPS+=../arch/mips/gnu/mips16-opc.o
OBJ_MIPS+=../arch/mips/gnu/mips-opc.o
## SPARC
OBJ_SPARC=asm_sparc.o
# gnu sparc-dis
OBJ_SPARC+=../arch/sparc/gnu/sparc-dis.o
OBJ_SPARC+=../arch/sparc/gnu/sparc-opc.o
## PPC
OBJ_PPC=asm_ppc.o
# ppc-disasm
OBJ_PPC+=../arch/ppc/ppc_disasm/ppc_disasm.o
## BF
OBJ_BF=asm_bf.o
## CSR
OBJ_CSR=asm_csr.o
# csr-disasm
OBJ_CSR+=../arch/csr/csr_disasm/dis.o
## M68K
OBJ_M68K=asm_m68k.o
# mk8k-disasm
OBJ_M68K+=../arch/m68k/m68k_disasm/m68k_disasm.o
## JAVA
OBJ_JAVA=asm_java.o
# javasm
OBJ_JAVA+=../arch/java/javasm/javasm.o
foo: all
ALL_TARGETS=
ARCHS=dummy.mk mips.mk sparc.mk java.mk bf.mk arm.mk m68k.mk ppc.mk x86bea.mk x86olly.mk x86.mk
include $(ARCHS)
all: asm_dummy.so asm_x86.so asm_x86_olly.so \
asm_x86_bea.so asm_arm.so asm_mips.so \
asm_sparc.so asm_ppc.so asm_bf.so \
asm_csr.so asm_m68k.so asm_java.so
all: ${ALL_TARGETS}
@true
asm_dummy.so: asm_dummy.o
${CC} ${CFLAGS} -o asm_dummy.so asm_dummy.o
@#strip -s asm_dummy.so
asm_x86.so: ${OBJ_X86}
${CC} ${CFLAGS} -o asm_x86.so ${OBJ_X86}
@#strip -s asm_x86.so
asm_x86_olly.so: ${OBJ_X86_OLLY}
${CC} ${CFLAGS} -o asm_x86_olly.so ${OBJ_X86_OLLY}
@#strip -s asm_x86_olly.so
asm_x86_bea.so:
${CC} ${CFLAGS_IMP} -o asm_x86_bea.so \
asm_x86_bea.c ../arch/x86/bea/BeaEngine.c
@#strip -s asm_x86_bea.so
asm_arm.so: ${OBJ_ARM}
${CC} ${CFLAGS} -o asm_arm.so ${OBJ_ARM}
@#strip -s asm_x86.so
asm_mips.so: ${OBJ_MIPS}
${CC} ${CFLAGS} -o asm_mips.so ${OBJ_MIPS}
@#strip -s asm_x86.so
asm_sparc.so: ${OBJ_SPARC}
${CC} ${CFLAGS} -o asm_sparc.so ${OBJ_SPARC}
@#strip -s asm_x86.so
asm_ppc.so: ${OBJ_PPC}
${CC} ${CFLAGS} -o asm_ppc.so ${OBJ_PPC}
@#strip -s asm_x86.so
asm_bf.so: ${OBJ_BF}
${CC} ${CFLAGS} -o asm_bf.so ${OBJ_BF}
@#strip -s asm_x86.so
asm_csr.so: ${OBJ_CSR}
${CC} ${CFLAGS} -o asm_csr.so ${OBJ_CSR}
@#strip -s asm_x86.so
asm_m68k.so: ${OBJ_M68K}
${CC} ${CFLAGS} -o asm_m68k.so ${OBJ_M68K}
@#strip -s asm_x86.so
asm_java.so: ${OBJ_JAVA}
${CC} ${CFLAGS} -o asm_java.so ${OBJ_JAVA}
@#strip -s asm_x86.so
clean:
-rm -f *.so *.o \
-rm -f *.so *.o ${STATIC_OBJ} \
${OBJ_X86} ${OBJ_X86_OLLY} ${OBJ_ARM} \
${OBJ_MIPS} ${OBJ_SPARC} ${OBJ_PPC} \
${OBJ_BF} ${OBJ_CSR} ${OBJ_M68K} ${OBJ_JAVA}
.PHONY: all clean foo

11
libr/asm/p/arm.mk Normal file
View file

@ -0,0 +1,11 @@
OBJ_ARM=asm_arm.o
OBJ_ARM+=../arch/arm/gnu/arm-dis.o
STATIC_OBJ+=${OBJ_ARM}
TARGET_ARM=asm_arm.so
ALL_TARGETS+=${TARGET_ARM}
${TARGET_ARM}: ${OBJ_ARM}
${CC} ${CFLAGS} -o asm_arm.so ${OBJ_ARM}
@#strip -s asm_x86.so

View file

@ -66,7 +66,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
return i;
}
static struct r_asm_handle_t r_asm_plugin_bf = {
struct r_asm_handle_t r_asm_plugin_bf = {
.name = "asm_bf",
.desc = "BF disassembly plugin",
.init = NULL,

View file

@ -37,7 +37,7 @@ static int assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
return aop->inst_len;
}
static struct r_asm_handle_t r_asm_plugin_java = {
struct r_asm_handle_t r_asm_plugin_java = {
.name = "asm_java",
.desc = "java disassembly plugin",
.init = NULL,
@ -46,7 +46,9 @@ static struct r_asm_handle_t r_asm_plugin_java = {
.assemble = &assemble
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_java
};
#endif

View file

@ -95,7 +95,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
return aop->inst_len;
}
static struct r_asm_handle_t r_asm_plugin_mips = {
struct r_asm_handle_t r_asm_plugin_mips = {
.name = "asm_mips",
.desc = "MIPS disassembly plugin",
.init = NULL,
@ -104,7 +104,9 @@ static struct r_asm_handle_t r_asm_plugin_mips = {
.assemble = NULL
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_mips
};
#endif

9
libr/asm/p/bf.mk Normal file
View file

@ -0,0 +1,9 @@
OBJ_BF=asm_bf.o
TARGET_BF=asm_bf.so
ALL_TARGETS+=${TARGET_BF}
STATIC_OBJ+=${OBJ_BF}
${TARGET_BF}: ${OBJ_BF}
${CC} ${CFLAGS} -o ${TARGET_BF} ${OBJ_BF}
@#strip -s asm_x86.so

11
libr/asm/p/csr.mk Normal file
View file

@ -0,0 +1,11 @@
OBJ_CSR=asm_csr.o
OBJ_CSR+=../arch/csr/csr_disasm/dis.o
STATIC_OBJ+=${OBJ_CSR}
TARGET_CSR=asm_csr.so
ALL_TARGETS+=${TARGET_CSR}
${TARGET_CSR}: ${OBJ_CSR}
${CC} ${CFLAGS} -o asm_csr.so ${OBJ_CSR}
@#strip -s asm_x86.so

9
libr/asm/p/dummy.mk Normal file
View file

@ -0,0 +1,9 @@
OBJ_DUMMY+=asm_dummy.o
TARGET_DUMMY=asm_dummy.so
ALL_TARGETS+=${TARGET_DUMMY}
STATIC_OBJ+=${OBJ_DUMMY}
${TARGET_DUMMY}: ${OBJ_DUMMY}
${CC} ${CFLAGS} -o asm_dummy.so asm_dummy.o
@#strip -s asm_dummy.so

11
libr/asm/p/java.mk Normal file
View file

@ -0,0 +1,11 @@
OBJ_JAVA=asm_java.o
OBJ_JAVA+=../arch/java/javasm/javasm.o
STATIC_OBJ+=${OBJ_JAVA}
TARGET_JAVA=asm_java.so
ALL_TARGETS+=${TARGET_JAVA}
${TARGET_JAVA}: ${OBJ_JAVA}
${CC} ${CFLAGS} -o asm_java.so ${OBJ_JAVA}
@#strip -s asm_x86.so

11
libr/asm/p/m68k.mk Normal file
View file

@ -0,0 +1,11 @@
OBJ_M68K=asm_m68k.o
OBJ_M68K+=../arch/m68k/m68k_disasm/m68k_disasm.o
STATIC_OBJ+=${OBJ_M68K}
TARGET_M68K=asm_m68k.so
ALL_TARGETS+=${TARGET_M68K}
${TARGET_M68K}: ${OBJ_M68K}
${CC} ${CFLAGS} -o asm_m68k.so ${OBJ_M68K}
@#strip -s asm_x86.so

13
libr/asm/p/mips.mk Normal file
View file

@ -0,0 +1,13 @@
OBJ_MIPS=asm_mips.o
# gnu mips-dis
OBJ_MIPS+=../arch/mips/gnu/mips-dis.o
OBJ_MIPS+=../arch/mips/gnu/mips16-opc.o
OBJ_MIPS+=../arch/mips/gnu/mips-opc.o
TARGET_MIPS=asm_mips.so
ALL_TARGETS+=${TARGET_MIPS}
STATIC_OBJ+=${OBJ_MIPS}
${TARGET_MIPS}: ${OBJ_MIPS}
${CC} ${CFLAGS} -o ${TARGET_MIPS} ${OBJ_MIPS}
@#strip -s asm_x86.so

11
libr/asm/p/ppc.mk Normal file
View file

@ -0,0 +1,11 @@
OBJ_PPC=asm_ppc.o
OBJ_PPC+=../arch/ppc/ppc_disasm/ppc_disasm.o
STATIC_OBJ+=${OBJ_PPC}
TARGET_PPC=asm_ppc.so
ALL_TARGETS+=${TARGET_PPC}
${TARGET_PPC}: ${OBJ_PPC}
${CC} ${CFLAGS} -o asm_ppc.so ${OBJ_PPC}
@#strip -s asm_x86.so

13
libr/asm/p/sparc.mk Normal file
View file

@ -0,0 +1,13 @@
OBJ_SPARC=asm_sparc.o
OBJ_SPARC+=../arch/sparc/gnu/sparc-dis.o
OBJ_SPARC+=../arch/sparc/gnu/sparc-opc.o
STATIC_OBJ+=${OBJ_SPARC}
TARGET_SPARC=asm_sparc.so
ALL_TARGETS+=${TARGET_SPARC}
${TARGET_SPARC}: ${OBJ_SPARC}
${CC} ${CFLAGS} -o ${TARGET_SPARC} ${OBJ_SPARC}
@#strip -s asm_x86.so

19
libr/asm/p/x86.mk Normal file
View file

@ -0,0 +1,19 @@
OBJ_X86=asm_x86.o
# udis86
OBJ_X86=asm_x86.o
OBJ_X86+=../arch/x86/udis86/syn.o
OBJ_X86+=../arch/x86/udis86/input.o
OBJ_X86+=../arch/x86/udis86/udis86.o
OBJ_X86+=../arch/x86/udis86/decode.o
OBJ_X86+=../arch/x86/udis86/itab.o
OBJ_X86+=../arch/x86/udis86/syn-intel.o
OBJ_X86+=../arch/x86/udis86/syn-att.o
STATIC_OBJ+=${OBJ_X86}
TARGET_X86=asm_x86.so
ALL_TARGETS+=${TARGET_X86}
asm_x86.so: ${OBJ_X86}
${CC} ${CFLAGS} -o asm_x86.so ${OBJ_X86}
@#strip -s asm_x86.so

15
libr/asm/p/x86bea.mk Normal file
View file

@ -0,0 +1,15 @@
OBJ_X86_BEA=asm_x86_bea.o
OBJ_X86_BEA+=../arch/x86/bea/BeaEngine.o
STATIC_OBJ+=${OBJ_X86_BEA}
TARGET_X86_BEA=asm_x86_bea.so
ALL_TARGETS+=${TARGET_X86_BEA}
#${TARGET_X86_BEA}: ${OBJ_X86_BEA}
asm_x86_bea.so: ${OBJ_X86_BEA}
${CC} ${CFLAGS_IMP} -o asm_x86_bea.so \
asm_x86_bea.c ../arch/x86/bea/BeaEngine.c
@#strip -s asm_x86_bea.so
${CC} ${CFLAGS} -o ${TARGET_X86_BEA} ${OBJ_X86_BEA}
@#strip -s asm_x86.so

13
libr/asm/p/x86olly.mk Normal file
View file

@ -0,0 +1,13 @@
OBJ_X86_OLLY=asm_x86_olly.o
OBJ_X86_OLLY+=../arch/x86/ollyasm/disasm.o
OBJ_X86_OLLY+=../arch/x86/ollyasm/asmserv.o
OBJ_X86_OLLY+=../arch/x86/ollyasm/assembl.o
STATIC_OBJ+=${OBJ_X86_OLLY}
TARGET_X86_OLLY=asm_x86_olly.so
ALL_TARGETS+=${TARGET_X86_OLLY}
${TARGET_X86_OLLY}: ${OBJ_X86_OLLY}
${CC} ${CFLAGS} -o ${TARGET_X86_OLLY} ${OBJ_X86_OLLY}
@#strip -s asm_x86.so

View file

@ -15,15 +15,15 @@ static struct r_asm_t a;
static int rasm_show_help()
{
printf( "rasm2 [-e] [-o offset] [-a arch] [-s syntax] -d \"opcode\"|\"hexpairs\"|-\n"
" -d Disassemble from hexpair bytes\n"
" -o [offset] Offset where this opcode is suposed to be\n"
" -a [arch] Set architecture plugin\n"
" -b [bits] Set architecture bits\n"
" -s [syntax] Select syntax (intel, att)\n"
" -e Use big endian\n"
" If the last argument is '-' reads from stdin\n\n"
"Available plugins:\n");
printf ("rasm2 [-e] [-o offset] [-a arch] [-s syntax] -d \"opcode\"|\"hexpairs\"|-\n"
" -d Disassemble from hexpair bytes\n"
" -o [offset] Offset where this opcode is suposed to be\n"
" -a [arch] Set architecture plugin\n"
" -b [bits] Set architecture bits\n"
" -s [syntax] Select syntax (intel, att)\n"
" -e Use big endian\n"
" If the last argument is '-' reads from stdin\n\n"
"Available plugins:\n");
r_asm_list(&a);
return R_TRUE;
@ -136,12 +136,16 @@ int main(int argc, char *argv[])
}
if (arch) {
if (!r_asm_set(&a, arch)) {
char *str = malloc(strlen(arch)+10);
sprintf(str, "asm_%s", arch);
if (!r_asm_set(&a, str)) {
fprintf(stderr, "Error: Unknown plugin\n");
free (str);
return 1;
}
if (!strcmp(arch, "asm_bf"))
if (!strcmp(str, "asm_bf"))
str = 1;
free (str);
} else if (!dis) {
if (!r_asm_set(&a, "asm_x86_olly")) {
fprintf(stderr, "Error: Cannot find asm_x86_olly plugin\n");
@ -161,14 +165,12 @@ int main(int argc, char *argv[])
if (feof(stdin))
break;
buf[strlen(buf)-1]='\0';
if (dis)
offset += rasm_disasm(buf, offset, str);
if (dis) offset += rasm_disasm(buf, offset, str);
else offset += rasm_asm(buf, offset);
}
return 0;
}
if (dis)
return rasm_disasm(argv[optind], offset, str);
if (dis) return rasm_disasm(argv[optind], offset, str);
else return rasm_asm(argv[optind], offset);
}

View file

@ -49,6 +49,12 @@ int r_bin_add(struct r_bin_t *bin, struct r_bin_handle_t *foo)
{
if (foo->init)
foo->init(bin->user);
/* avoid dupped plugins */
list_for_each_prev(pos, &a->asms) {
struct r_asm_handle_t *h = list_entry(pos, struct r_asm_handle_t, list);
if (!strcmp(h->name, foo->name))
return R_FALSE;
}
list_add_tail(&(foo->list), &(bin->bins));
return R_TRUE;
}

7
libr/config.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef _INCLUDE_CONFIG_H_
#define _INCLUDE_CONFIG_H_
#define R_ASM_STATIC_PLUGINS \
&r_asm_plugin_java, 0
#endif

View file

@ -4,3 +4,6 @@ BSD=0
SOLARIS=0
WINDOWS=0
USE_RIO=1
# static plugins
STATIC_ASM_PLUGINS=p/java.mk p/mips.mk

View file

@ -56,4 +56,9 @@ int r_asm_set_syntax(struct r_asm_t *a, int syntax);
int r_asm_set_pc(struct r_asm_t *a, u64 pc);
int r_asm_disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len);
int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf);
/* plugin pointers */
extern struct r_asm_handle_t r_asm_plugin_bf;
extern struct r_asm_handle_t r_asm_plugin_java;
extern struct r_asm_handle_t r_asm_plugin_mips;
#endif