Repository navigation
Conversation
The recursive descent in patches/xrefs.py (the stock map, and the re-descents relocate.py and xip.py run on the patched image) used capstone at patch time. gnwmanager will ship the patcher, and it shouldn't need capstone. patches/thumb_disasm.py decodes ARMv7E-M/FPv5 Thumb-2 into only the fields the descent reads: size, branch target, PC-relative load and address, the registers the pc-offset and table-branch patterns track, and whether it writes PC. Code._run keeps its rules, now on those fields. decode_capstone() derives the same fields from capstone with the old rules. tests/test_thumb_disasm.py compares the 2 over every 16-bit encoding, 100k random 32-bit ones (allowing only encodings outside ARMv7E-M and a few capstone quirks), and the whole stock map of both models, which is identical. The golden hashes are unchanged, and the descent is ~1.5x faster. capstone moves to requirements-dev.txt: the decoder tests, test_thumb_asm.py and tools/re/match_roms.py (which signs functions by instruction text) skip or need it; test_relocate.py checks the branch encoders with the in-house decoder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Closing this one. capstone is actively maintained and ships prebuilt wheels for the common platforms (keystone was the real problem, and that's already gone), so I don't think there's a strong enough reason to own a Thumb decoder. The web builder doesn't use Pyodide, which was the other main motivation. The branch stays around in case that changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second step toward shipping the patcher in gnwmanager without extra native dependencies (#124 is the first; this PR is independent of it). capstone was a runtime dependency because the recursive descent in
patches/xrefs.pydisassembles the stock firmware, andrelocate.py/xip.pyre-descend the patched image at patch time, so caching the stock map couldn't remove it.The decoder
patches/thumb_disasm.pydecodes ARMv7E-M + FPv5 Thumb-2 into anInsnwith only the fields the descent reads: size, branch target, PC-relative load (displacement and size) or address (adr,addw/subw rd, pc), the registers the pc-offset (ldr rX, [pc]; add rX, pc; adds rX, #adj) and table-branch (cmp rX, #n; tbb) patterns track, IT slots, and whether it writes or mentions PC. There's no assembly text.xrefs.Code._runkeeps every rule it had; they read these fields now instead of capstone operands.Code.insnsholdsInsnobjects instead of(size, mnemonic, op_str)tuples.The fields follow capstone's operand model on purpose, quirks included (e.g. a
strd [pc]counts as a word load,blo/blsstart withbl), so the map can't change.How it's checked
decode_capstone()derives the same fields from capstone using the old rules verbatim.tests/test_thumb_disasm.pycompares the 2:0xDEF9, which capstone rejects).hvc/smc, ARMv8-Mtt/stl*/lda*/*_ns, the MP extension'spldw, NEON, FP16, non-FP coprocessors) and 2 capstone quirks (udf.wwith any second halfword;rev/rbit/clzwith mismatched Rm fields). I also ran 900k more by hand with no other differences.The golden hashes are unchanged, also with capstone blocked at import (checked
zelda_xip_relocate, which exercisesrelocate.pyandxip.py). The descent is ~1.5x faster (Zelda's stock map: 1.8 s vs 2.5 s).capstone is dev-only now
requirements.txtdrops it; the newrequirements-dev.txtadds capstone and pytest.tests/test_thumb_disasm.py's comparisons,tests/test_thumb_asm.py(capstone's text is its oracle) andtests/test_match_roms.pyskip without capstone.tools/re/match_roms.pysigns functions by instruction text, so it runs the analysis withdecode_capstone.tests/test_relocate.pychecks relocate's branch and PC-relative encoders with the in-house decoder.No output changes, so no hardware check needed.
🤖 Generated with Claude Code