mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-08 14:58:54 +00:00
Add the first multiarch assembler plugin: vasm ##asm
This commit is contained in:
parent
4020dfe52a
commit
58312182e8
1
dist/plugins-cfg/plugins.bin.cfg
vendored
1
dist/plugins-cfg/plugins.bin.cfg
vendored
@ -36,6 +36,7 @@ parse.dalvik_pseudo
|
||||
parse.x86_pseudo
|
||||
parse.6502_pseudo
|
||||
parse.wasm_pseudo
|
||||
asm.vasm
|
||||
asm.arc
|
||||
asm.ppc_cs
|
||||
anal.ppc_cs
|
||||
|
1
dist/plugins-cfg/plugins.def.cfg
vendored
1
dist/plugins-cfg/plugins.def.cfg
vendored
@ -122,6 +122,7 @@ asm.xcore_cs
|
||||
asm.z80
|
||||
asm.lh5801
|
||||
asm.v810
|
||||
asm.vasm
|
||||
asm.vax
|
||||
asm.alpha
|
||||
asm.mcs96
|
||||
|
@ -366,13 +366,33 @@ R_API bool r_asm_use(RAsm *a, const char *name) {
|
||||
return false;
|
||||
}
|
||||
r_list_foreach (a->plugins, iter, h) {
|
||||
if (!strcmp (h->name, name) && h->arch) {
|
||||
if (!a->cur || (a->cur && strcmp (a->cur->arch, h->arch))) {
|
||||
load_asm_descriptions (a, h);
|
||||
r_asm_set_cpu (a, NULL);
|
||||
if (h->arch) {
|
||||
if (!strcmp (h->name, name)) {
|
||||
if (!a->cur || (a->cur && strcmp (a->cur->arch, h->arch))) {
|
||||
load_asm_descriptions (a, h);
|
||||
r_asm_set_cpu (a, NULL);
|
||||
}
|
||||
a->cur = h;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
char *vv = strchr (name, '.');
|
||||
if (vv) {
|
||||
if (!strcmp (vv + 1, h->name)) {
|
||||
char *cpu = r_str_ndup (name, vv - name);
|
||||
r_asm_set_cpu (a, cpu);
|
||||
a->cur = h;
|
||||
free (cpu);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (!strcmp (name, h->name)) {
|
||||
h->arch = name;
|
||||
r_asm_set_cpu (a, NULL);
|
||||
a->cur = h;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
a->cur = h;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
sdb_free (a->pair);
|
||||
@ -527,7 +547,7 @@ static bool assemblerMatches(RAsm *a, RAsmPlugin *h) {
|
||||
if (!a || !h->arch || !h->assemble || !has_bits (h, a->bits)) {
|
||||
return false;
|
||||
}
|
||||
return (!strncmp (a->cur->arch, h->arch, strlen (a->cur->arch)));
|
||||
return (a->cur->arch && !strncmp (a->cur->arch, h->arch, strlen (a->cur->arch)));
|
||||
}
|
||||
|
||||
static Ase findAssembler(RAsm *a, const char *kw) {
|
||||
@ -846,7 +866,7 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) {
|
||||
continue;
|
||||
}
|
||||
// XXX TODO remove arch-specific hacks
|
||||
if (!strncmp (a->cur->arch, "avr", 3)) {
|
||||
if (a->cur->arch && !strncmp (a->cur->arch, "avr", 3)) {
|
||||
for (ptr_start = buf_token; *ptr_start && isavrseparator (*ptr_start); ptr_start++);
|
||||
} else {
|
||||
for (ptr_start = buf_token; *ptr_start && IS_SEPARATOR (*ptr_start); ptr_start++);
|
||||
|
41
libr/asm/p/asm_vasm.c
Normal file
41
libr/asm/p/asm_vasm.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* radare - LGPL - Copyright 2021 - pancake */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_util.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_asm.h>
|
||||
|
||||
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
|
||||
int len = 0;
|
||||
const char *cpu = a->cpu? a->cpu: "x86";
|
||||
char *cmd = r_str_newf (
|
||||
"r2pm -r vasm%s_std -Fbin -quiet -o /dev/stdout /dev/stdin <<__\n"
|
||||
".org 0x%"PFMT64x"\n%s\n__", cpu, a->pc, buf);
|
||||
ut8 *out = (ut8 *)r_sys_cmd_str (cmd, "", &len);
|
||||
if (out) {
|
||||
r_asm_op_set_buf (op, out, len);
|
||||
free (out);
|
||||
}
|
||||
op->size = len;
|
||||
free (cmd);
|
||||
return len;
|
||||
}
|
||||
|
||||
RAsmPlugin r_asm_plugin_vasm = {
|
||||
.name = "vasm",
|
||||
.arch = NULL, // null on purpose
|
||||
.license = "MIT",
|
||||
.desc = "Use -a arm.vasm, 6502.vasm, 6809, c16x, jagrisc, m68k, pdp11, ppc, qnice, tr3200, vidcore, x86, z80",
|
||||
.author = "http://sun.hasenbraten.de/vasm/",
|
||||
.bits = 8 | 16 | 32 | 64,
|
||||
.endian = R_SYS_ENDIAN_LITTLE,
|
||||
.assemble = &assemble
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
R_API RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_ASM,
|
||||
.data = &r_asm_plugin_vasm,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
9
libr/asm/p/vasm.mk
Normal file
9
libr/asm/p/vasm.mk
Normal file
@ -0,0 +1,9 @@
|
||||
OBJ_VASM=asm_vasm.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_VASM}
|
||||
TARGET_VASM=asm_vasm.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_VASM}
|
||||
|
||||
${TARGET_VASM}: ${OBJ_VASM}
|
||||
${CC} $(call libname,asm_vasm) ${LDFLAGS} ${CFLAGS} -o ${TARGET_VASM} ${OBJ_VASM}
|
@ -276,6 +276,7 @@ extern RAsmPlugin r_asm_plugin_arm_v35;
|
||||
extern RAsmPlugin r_asm_plugin_pyc;
|
||||
extern RAsmPlugin r_asm_plugin_pdp11_gnu;
|
||||
extern RAsmPlugin r_asm_plugin_alpha;
|
||||
extern RAsmPlugin r_asm_plugin_vasm;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -826,7 +826,9 @@ R_API int r_main_rasm2(int argc, const char *argv[]) {
|
||||
ret = 0;
|
||||
goto beach;
|
||||
}
|
||||
r_asm_set_cpu (as->a, cpu);
|
||||
if (cpu) {
|
||||
r_asm_set_cpu (as->a, cpu);
|
||||
}
|
||||
r_asm_set_bits (as->a, (env_bits && *env_bits)? atoi (env_bits): bits);
|
||||
r_anal_set_bits (as->anal, (env_bits && *env_bits)? atoi (env_bits): bits);
|
||||
as->a->syscall = r_syscall_new ();
|
||||
|
Loading…
x
Reference in New Issue
Block a user