From 2e43456293c33fdf721ff5cf056f79e39976c5f5 Mon Sep 17 00:00:00 2001 From: Siggi Date: Sun, 12 Apr 2026 14:28:20 +0000 Subject: [PATCH] Add radare2 ADSP-219x ASM plugin --- r2plugin/Makefile | 14 ++++++++++ r2plugin/README.md | 30 ++++++++++++++++++++ r2plugin/asm_adsp219x.c | 61 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 r2plugin/Makefile create mode 100644 r2plugin/README.md create mode 100644 r2plugin/asm_adsp219x.c diff --git a/r2plugin/Makefile b/r2plugin/Makefile new file mode 100644 index 0000000..5a94c73 --- /dev/null +++ b/r2plugin/Makefile @@ -0,0 +1,14 @@ +NAME=asm_adsp219x +R2_PLUGIN_PATH=$(shell r2 -H R2_USER_PLUGINS) + +all: $(NAME).so + +$(NAME).so: $(NAME).c + gcc -shared -Wall -O2 -fPIC $(shell pkg-config --cflags --libs r_asm) $< -o $@ + +install: $(NAME).so + mkdir -p $(R2_PLUGIN_PATH) + cp $(NAME).so $(R2_PLUGIN_PATH) + +clean: + rm -f $(NAME).so diff --git a/r2plugin/README.md b/r2plugin/README.md new file mode 100644 index 0000000..7aaa3a0 --- /dev/null +++ b/r2plugin/README.md @@ -0,0 +1,30 @@ +# ADSP-219x radare2 Plugin + +Dieses Plugin fügt ADSP-2191 Support zu radare2 und iaito hinzu. + +## Kompilieren & Installation +Da der Zielrechner air-gapped ist, stelle sicher, dass `gcc` und `radare2-dev` (oder Header) installiert sind. + +```bash +cd r2plugin +make +make install +``` + +## Nutzung +Lade dein ROM mit dem `-a` (Architecture) und `-b` (Bits) Schalter: + +```bash +r2 -a adsp219x -b 24 firmware_dump.bin +``` + +In `iaito`: +1. Datei öffnen +2. `Architecture`: `adsp219x` (im Dropdown suchen oder tippen) +3. `Bits`: `24` + +## Features +- Volle 24-bit Instruktionsbreite +- Unterstützung für Multifunktions-Compute (ALU/MAC) +- Anzeige von Delayed-Branch (DB) Flags +- Jump-Adressen Decodierung diff --git a/r2plugin/asm_adsp219x.c b/r2plugin/asm_adsp219x.c new file mode 100644 index 0000000..69c1db8 --- /dev/null +++ b/r2plugin/asm_adsp219x.c @@ -0,0 +1,61 @@ +#include +#include + +/* ADSP-219x 24-bit Opcode Table (Basic definitions) */ +static const char *AXOP[] = {"AX0", "AX1", "AR", "MR0", "MR1", "MR2", "SR0", "SR1"}; +static const char *AYOP[] = {"AY0", "AY1", "AF", "0"}; +static const char *COND[] = {"EQ", "NE", "GT", "LE", "LT", "GE", "AV", "NAV", "AC", "NAC", "SWCOND", "NSWCOND", "MV", "NMV", "NCE", "TRUE"}; + +static int adsp219x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { + if (len < 3) return -1; + ut32 ins = (buf[0] << 16) | (buf[1] << 8) | buf[2]; + op->size = 3; + + /* Simplified decoding for the r2-Backend */ + // Type 1: Compute (11xxxxxx) + if ((ins >> 22) == 0b11) { + ut32 amf = (ins >> 13) & 0x1F; + ut32 xop = (ins >> 8) & 0x7; + ut32 yop = (ins >> 11) & 0x3; + if (amf == 0) r_strbuf_setf(&op->buf_asm, "NOP"); + else if (amf >= 0x10) r_strbuf_setf(&op->buf_asm, "COMPUTE (ALU:%d, %s, %s)", amf, AXOP[xop], AYOP[yop]); + else r_strbuf_setf(&op->buf_asm, "COMPUTE (MAC:%d, %s, %s)", amf, AXOP[xop], AYOP[yop]); + } + // Type 6: Dreg = Imm16 (0100xxxx) + else if ((ins >> 20) == 0b0100) { + ut32 dreg = ins & 0xF; + ut32 data = (ins >> 4) & 0xFFFF; + r_strbuf_setf(&op->buf_asm, "D%d = 0x%x", dreg, data); + } + // Type 10: Jump (000110B xxxxx COND) + else if ((ins >> 19) == 0b00011) { + ut32 addr = (ins >> 4) & 0x1FFF; + ut32 cond = ins & 0xF; + ut8 b = (ins >> 16) & 0x1; + const char *db = b ? " (DB)" : ""; + if (cond == 0xF) r_strbuf_setf(&op->buf_asm, "JUMP 0x%x%s", addr, db); + else r_strbuf_setf(&op->buf_asm, "IF %s JUMP 0x%x%s", COND[cond], addr, db); + } + // Type 30: NOP (00000000) + else if (ins == 0) { + r_strbuf_setf(&op->buf_asm, "NOP"); + } + else { + r_strbuf_setf(&op->buf_asm, "unknown (0x%06x)", ins); + } + + return op->size; +} + +RAsmPlugin r_asm_plugin_adsp219x = { + .name = "adsp219x", + .desc = "Analog Devices ADSP-219x Disassembler (Air-Gapped RE)", + .arch = "adsp219x", + .bits = 24, + .endian = R_SYS_ENDIAN_BIG, + .disassemble = &adsp219x_disassemble +}; + +#ifndef R2_PLUGIN_INLINE +R_LIB_VERSION_SET(r_asm_plugin_adsp219x, r_asm); +#endif