mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-06 18:13:46 +00:00
Initial implementation of the arch.any.as plugin ##arch
This commit is contained in:
parent
53b28aecab
commit
f08fc91dd9
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2021 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2022 - pancake */
|
||||
|
||||
#include <r_main.h>
|
||||
|
||||
|
@ -39,6 +39,7 @@ help () {
|
||||
cfg=./plugins.cfg
|
||||
|
||||
if [ ! -f "$cfg" ]; then
|
||||
echo "configure-plugins: Copying dist/plugins-cfg/plugins.def.cfg"
|
||||
cp -f dist/plugins-cfg/plugins.def.cfg plugins.cfg
|
||||
fi
|
||||
|
||||
|
1
dist/plugins-cfg/plugins.def.cfg
vendored
1
dist/plugins-cfg/plugins.def.cfg
vendored
@ -44,6 +44,7 @@ anal.ppc_cs
|
||||
anal.ppc_gnu
|
||||
anal.propeller
|
||||
anal.pyc
|
||||
arch.any_as
|
||||
arch.riscv
|
||||
anal.riscv_cs
|
||||
anal.s390_cs
|
||||
|
10
libr/arch/p/any_as.mk
Normal file
10
libr/arch/p/any_as.mk
Normal file
@ -0,0 +1,10 @@
|
||||
OBJ_ANYAS=p/as/plugin.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_ANYAS}
|
||||
TARGET_ANYAS=arch_as.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_ANYAS}
|
||||
|
||||
${TARGET_ANYAS}: ${OBJ_ANYAS}
|
||||
${CC} ${CFLAGS} $(call libname,arch_as) $(CS_CFLAGS) \
|
||||
-o arch_as.${EXT_SO} ${OBJ_ANYAS} $(CS_LDFLAGS)
|
44
libr/arch/p/arch_as.c
Normal file
44
libr/arch/p/arch_as.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* radare2 - BSD - Copyright 2022 - pancake */
|
||||
|
||||
#include <r_arch.h>
|
||||
#include <r_lib.h>
|
||||
}
|
||||
|
||||
static bool encode (RArchSession *a, RAnalOp *op, RArchEncodeMask mask) {
|
||||
int len = 0;
|
||||
ut8 *out;
|
||||
char *gas = r_sys_getenv ("RASM2_AS");
|
||||
if (!gas) {
|
||||
gas = strdup ("as");
|
||||
}
|
||||
char *cmd = r_str_newf (
|
||||
"%s /dev/stdin -o /dev/stdout <<__\n"
|
||||
"BITS %i\nORG 0x%"PFMT64x"\n%s\n__",
|
||||
gas, a->bits, a->pc, buf);
|
||||
ut8 *out = (ut8 *)r_sys_cmd_str (cmd, "", &len);
|
||||
if (out) {
|
||||
r_anal_op_setbytes (op, op->addr, out, len);
|
||||
free (out);
|
||||
}
|
||||
op->size = len;
|
||||
free (cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
RArchPlugin r_arch_plugin_as = {
|
||||
.name = "as",
|
||||
.desc = "GNU/Clang assembler RASM2_AS or `as`",
|
||||
.license = "LGPL3",
|
||||
.arch = NULL,
|
||||
.bits = R_SYS_BITS_PACK3 (16, 32, 64),
|
||||
.encode = &encode,
|
||||
.endian = R_SYS_ENDIAN_LITTLE | R_:SYS_ENDIAN_BIG,
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
R_API RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_ARCH,
|
||||
.data = &r_arch_plugin_as,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
44
libr/arch/p/as/plugin.c
Normal file
44
libr/arch/p/as/plugin.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* Copyright (C) 2008-2022 - pancake */
|
||||
|
||||
#include <r_arch.h>
|
||||
|
||||
static bool as_encode(RArchSession *s, RAnalOp *op, RArchEncodeMask mask) {
|
||||
int len = 0;
|
||||
char *gas = r_sys_getenv ("RASM2_AS");
|
||||
if (!gas) {
|
||||
// TODO: find in PATH
|
||||
gas = strdup ("as");
|
||||
}
|
||||
char *cmd = r_str_newf (
|
||||
"%s -o a.out /dev/stdin <<__\n%s\n__\n"
|
||||
"rabin2 -rO 'd/S/*text' a.out; rm -f a.out\n",
|
||||
gas, op->mnemonic);
|
||||
ut8 *out = (ut8 *)r_sys_cmd_str (cmd, NULL, &len);
|
||||
if (out) {
|
||||
r_anal_op_set_bytes (op, op->addr, out, len);
|
||||
free (out);
|
||||
}
|
||||
op->size = len;
|
||||
free (cmd);
|
||||
return len > 0;
|
||||
}
|
||||
|
||||
RArchPlugin r_arch_plugin_any_as = {
|
||||
.name = "any.as",
|
||||
.desc = "Uses system gnu/clang 'as' assembler",
|
||||
.author = "pancake",
|
||||
.license = "LGPL3",
|
||||
// TODO: add the "any" architecture to support any, instead of using null
|
||||
.arch = "any", // on purpose because that's a multi-arch plugin
|
||||
.bits = R_SYS_BITS_PACK3 (16, 32, 64),
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.encode = &as_encode,
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
R_API RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_ARCH,
|
||||
.data = &r_arch_plugin_any_as,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
@ -256,6 +256,7 @@ extern RArchPlugin r_arch_plugin_v810;
|
||||
extern RArchPlugin r_arch_plugin_rsp;
|
||||
extern RArchPlugin r_arch_plugin_riscv;
|
||||
extern RArchPlugin r_arch_plugin_x86_nz;
|
||||
extern RArchPlugin r_arch_plugin_any_as;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user