/* SPDX-License-Identifier: MPL-2.0 * Links mGBA's decoder (Copyright (c) Jeffrey Pfau, MPL-2.0): a closed-box detector tool, * built locally and never distributed; see referees/README.md. */ /* mGBA's ARM and Thumb disassembler (the pinned tree's src/arm/decoder*.c) as a filter. * * Reads one request per line on stdin and writes one line of mGBA's text for each: * * A
an ARM word * T
a Thumb halfword * P
a Thumb BL pair, combined as mGBA's debugger does * * Numbers are hexadecimal. There is no core and no symbol table, so PC-relative loads print * their address, not the loaded value. Built by scripts/build_referees.py; driven by * scripts/disasm_judge.py, which uses it as a detector for arm7tdmi_python.disasm. */ #include #include #include /* The decoder calls these only with a symbol table, and this filter passes none. */ const char* mDebuggerSymbolReverseLookup(const struct mDebuggerSymbols* st, uint32_t value, int segment) { (void) st; (void) value; (void) segment; return NULL; } int main(void) { char line[256]; char text[256]; setvbuf(stdout, NULL, _IOLBF, 0); while (fgets(line, sizeof line, stdin)) { unsigned first = 0, second = 0, address = 0; struct ARMInstructionInfo info, info2, combined; text[0] = '\0'; if (line[0] == 'A' && sscanf(line + 1, "%x %x", &first, &address) == 2) { ARMDecodeARM(first, &info); ARMDisassemble(&info, NULL, NULL, address + 8, text, sizeof text); } else if (line[0] == 'T' && sscanf(line + 1, "%x %x", &first, &address) == 2) { ARMDecodeThumb((uint16_t) first, &info); ARMDisassemble(&info, NULL, NULL, address + 4, text, sizeof text); } else if (line[0] == 'P' && sscanf(line + 1, "%x %x %x", &first, &second, &address) == 3) { ARMDecodeThumb((uint16_t) first, &info); ARMDecodeThumb((uint16_t) second, &info2); if (ARMDecodeThumbCombine(&info, &info2, &combined)) { ARMDisassemble(&combined, NULL, NULL, address + 4, text, sizeof text); } else { strcpy(text, "(no combine)"); } } else { strcpy(text, "(bad request)"); } puts(text); } return 0; }