Add radare2 ADSP-219x ASM plugin

This commit is contained in:
Siggi
2026-04-12 14:28:20 +00:00
parent 88337dfdf3
commit 2e43456293
3 changed files with 105 additions and 0 deletions

14
r2plugin/Makefile Normal file
View File

@@ -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

30
r2plugin/README.md Normal file
View File

@@ -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

61
r2plugin/asm_adsp219x.c Normal file
View File

@@ -0,0 +1,61 @@
#include <r_asm.h>
#include <r_lib.h>
/* 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