summaryrefslogtreecommitdiff
path: root/misc/radare2
diff options
context:
space:
mode:
Diffstat (limited to 'misc/radare2')
-rw-r--r--misc/radare2/Makefile7
-rw-r--r--misc/radare2/asm_fspec.c29
2 files changed, 22 insertions, 14 deletions
diff --git a/misc/radare2/Makefile b/misc/radare2/Makefile
index aff2fdb..b8fcdd2 100644
--- a/misc/radare2/Makefile
+++ b/misc/radare2/Makefile
@@ -8,7 +8,7 @@ WARNINGS := -Wall -Wextra -Wformat=2 -Wstrict-aliasing=3 -Wstrict-overflow=5 -Ws
override CFLAGS ?= -g
override CFLAGS += -std=c11 $(WARNINGS)
-libs = asm_fspec.so
+libs = asm_fspec.so anal_fspec.so
all: $(libs)
%.so:
@@ -18,11 +18,16 @@ asm_fspec.so: private CFLAGS += $(shell pkg-config --cflags r_anal)
asm_fspec.so: private LDLIBS += $(shell pkg-config --libs-only-l r_anal)
asm_fspec.so: asm_fspec.c
+anal_fspec.so: private CFLAGS += $(shell pkg-config --cflags r_anal)
+anal_fspec.so: private LDLIBS += $(shell pkg-config --libs-only-l r_anal)
+anal_fspec.so: anal_fspec.c
+
install: $(libs)
install -Dm755 $^ -t "$(R2_PLUGIN_PATH)"
uninstall:
$(RM) "$(R2_PLUGIN_PATH)"/asm_fspec.so
+ $(RM) "$(R2_PLUGIN_PATH)"/anal_fspec.so
clean:
$(RM) $(libs)
diff --git a/misc/radare2/asm_fspec.c b/misc/radare2/asm_fspec.c
index fa7c1ad..9eb28ea 100644
--- a/misc/radare2/asm_fspec.c
+++ b/misc/radare2/asm_fspec.c
@@ -12,7 +12,8 @@ enum fspec_instruction {
INS_REG,
INS_PUSH,
INS_PUSHR,
- INS_STORE,
+ INS_POP,
+ INS_INCR,
INS_OP,
INS_QUEUE,
INS_IO,
@@ -54,7 +55,8 @@ ins_name_str(const enum fspec_instruction name)
case INS_REG: return "reg";
case INS_PUSH: return "push";
case INS_PUSHR: return "pushr";
- case INS_STORE: return "store";
+ case INS_INCR: return "incr";
+ case INS_POP: return "pop";
case INS_OP: return "op";
case INS_QUEUE: return "queue";
case INS_IO: return "io";
@@ -98,26 +100,27 @@ op_name_str(const enum fspec_operation op)
static int
disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len)
{
+ (void)a;
+
union {
struct { unsigned name:5; unsigned n:2; uint64_t v:57; } ins;
- uint8_t v[16];
+ uint8_t v[sizeof(uint64_t)];
} u = {0};
- memcpy(u.v, buf, R_MIN(sizeof(u.v[0]), len));
- const uint8_t insw = sizeof(uint16_t) * (1 << u.ins.n);
+ memcpy(u.v, buf, R_MIN(1, (size_t)len));
+ const uint8_t insw = 1 << u.ins.n;
memcpy(u.v, buf, R_MIN(insw, len));
+
const char *buf_asm = "invalid";
+ const bool reg_arg = (u.ins.name == INS_PUSHR || u.ins.name == INS_INCR || u.ins.name == INS_POP ||
+ u.ins.name == INS_EXEC || u.ins.name == INS_CALL);
if (u.ins.name == INS_OP)
buf_asm = sdb_fmt("%s %s", ins_name_str(u.ins.name), op_name_str(u.ins.v));
- else if (u.ins.n == 0)
- buf_asm = sdb_fmt("%s 0x%02x", ins_name_str(u.ins.name), (uint16_t)u.ins.v);
- else if (u.ins.n == 1)
- buf_asm = sdb_fmt("%s 0x%04x", ins_name_str(u.ins.name), (uint32_t)u.ins.v);
- else if (u.ins.n == 2)
- buf_asm = sdb_fmt("%s 0x%08x", ins_name_str(u.ins.name), (uint64_t)u.ins.v);
+ else if (reg_arg)
+ buf_asm = sdb_fmt("%s r%" PRIu64, ins_name_str(u.ins.name), (uint64_t)u.ins.v);
else
- return 0;
+ buf_asm = sdb_fmt("%s %" PRIu64, ins_name_str(u.ins.name), (uint64_t)u.ins.v);
r_strbuf_set(&op->buf_asm, buf_asm);
return (op->size = insw + (u.ins.name == INS_REG ? u.ins.v : 0));
@@ -128,7 +131,7 @@ RAsmPlugin r_asm_plugin_fspec = {
.license = "LGPL3",
.desc = "fspec disassembly plugin",
.arch = "fspec",
- .bits = 16 | 32 | 64,
+ .bits = 8 | 16 | 32 | 64,
.endian = R_SYS_ENDIAN_LITTLE,
.disassemble = disassemble
};