跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
其他技能

match-file

Use when decompiling one C source file of an old DOS program (or of an armcc5 or TI C2000 firmware image) into C that recompiles byte for byte to the original - the per-file loop of writing C, compiling in headless DOS, reading instruction diffs and restructuring until every function matches and verify passes. Also the brief to give an agent that matches a file.

abedegno · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add abedegno/Exhume --skill match-file

技能说明


name: match-file description: Use when decompiling one C source file of an old DOS program (or of an armcc5 or TI C2000 firmware image) into C that recompiles byte for byte to the original - the per-file loop of writing C, compiling in headless DOS, reading instruction diffs and restructuring until every function matches and verify passes. Also the brief to give an agent that matches a file.

Match one C file

You are rebuilding one original source file (one code segment) as C that the original compiler turns into the same bytes. Paths are relative to the Exhume checkout; run tools from the project root so src/FILE.C resolves.

Before writing

  • Read the profile's compiler.md (for Borland, profiles/borland-tc101/compiler.md). It lists switches and what the compiler's output reveals about the source; most of the answers are there.
  • Read the target table targets/SEG.tsv: base, size, org, one row per function (name, listing name, offset, size).
  • Pick the closest matched file as a worked example (same kind: overlay or resident) and reuse its struct and global declarations where your code touches the same data.
  • symbols.tsv maps names to addresses. Use its name for any address already there. Use the sibling build's names (tools/sibling.py NAME) for callees and globals where they exist. If evidence says a name in symbols.tsv is wrong, report it; do not diverge.

Loop

  1. Start the file with /* target: SEG */ and /* opts: ... */ (for UW2: -mm -1 -G -O -Y -d). Change switches only when the bytes demand it, and say why.
  2. python3 tools/match.py src/FILE.C compiles in DOS (about half a second in emu2, a few seconds in js-dos) and prints each function as MATCH, bytes differing, or size against the table's. Add --dis NAME for an instruction diff of one function; --no-build re-compares the last build.
  3. Work function by function, smallest differences first. A length difference shows as the first instruction that differs; fix that one and rebuild. Batch edits: every build costs time and, in a queue, budget.
  4. When the instructions agree but registers or reloads differ, restructure (statement order, nesting against early return or continue, declaration order for SI/DI, x += y against x = x + y, block-scoped locals). The compiler.md lists which source shapes give which bytes.
  5. Stop at WHOLE SEGMENT MATCHES. Then python3 tools/verify.py src/FILE.C (without --update) must end -- fixups and data verified.

When the search stalls

A function or unit that stays a few instructions off after many variants is usually telling you the context is wrong, not that the right statement order is still out there. On two firmwares and a DSP image the long tails were broken by context; local sweeps of thousands of variants of one function recovered nothing once the instructions agreed but registers or schedule did not. Stop varying the function and audit, in this order:

  1. File boundaries. Is the unit one original source file, with the right first and last function? The compiler's knowledge of callees in the same file (registers kept live across the call, frame and push size, inlining) changes callers; a missing or extra function changes neighbours you think are unrelated.
  2. What the file owns. Which globals it defines and which are extern; a value defined in the file, read through an extern, or reached as a member of a struct compiles differently (load reuse, literal pool, base register). The same memory can need two names in one file.
  3. Types and grouping. Sizes and signedness of every object the unit touches; a group of variables as one struct or as separate scalars; arrays against pointer arithmetic.
  4. Linkage and declarations. Static against global functions and data, prototypes (missing, old-style, or with other parameter types), volatile, inline helpers and macros the original had.
  5. The compiler and options for this file. Another build of the same compiler, or another option set, before assuming the source is wrong; one file in an image can have been built differently (profiles' compiler.md say how to scan for it). Compile a small control (a matched sibling, or a few lines with the same idiom) under every installed build first, and when a tool runs under another build than the gate's, check that the function's listing is the same under both.
  6. Another build of the same code. When the vendor's earlier or later release, or another board, has the same function, the source must rebuild both with only the changed lines different. A form that fits one image only is compensation for something else (skills/carry-forward, "One source for both").
  7. Other builds of the same source. Ask the owner for every version of the program. An older version may hold the same function built with other options, often unoptimised, where the source is far easier to recover. Compare versions by compiling one candidate under each version's options, not by comparing their instructions, because two builds of the same source at different levels can look unrelated. One 11.7 KB armcc function resisted two and a half weeks of search. Its source then came from an -O0 build in an older version in two days, and that source compiled unchanged at -O1 was exact (profiles/armcc5/compiler.md, "Searching for the source").
  8. The neighbours. Match the other functions of the file, and a few functions elsewhere that the compiler treats the same way, before going on with the hard one. If they all match with natural C, the toolchain is right and the difference is in the hard function's own text.

Partial scores can mislead when the compiler allocates over the whole function. Measure how much a small change that keeps the instructions moves the score before you trust it. If the score moves about as much by chance, count only exact matches. A checker that decides whether a change keeps th

阅读完整来源 ↗