fix: harden smali hooks against branch targets and register limits #67

Merged
midas merged 1 commit from fix/issue-59-harden-smali-hooks into dev 2026-10-11 12:29:52 +02:00
Owner

Closes #59.

Changes

  1. Branch targets. New addInstructionsAtControlFlowLabel (shared/util/Instructions.kt): the hook goes in at the label of the instruction it precedes, so a goto/if-* to a return/invoke no longer skips it. It re-adds the instruction after itself, inserts the hook in between and removes the original location; dexlib2 moves its labels and debug items to the first hook instruction. Used at all sites from the issue: Edition review prompts and onboarding isSuppressed, the VideoProduction constructors, Kubus ArticleDetailResponse.<init>, the toolbar setValue call and getSections.
  2. 4-bit register forms. const/4 pN becomes const/16, invokes on parameter or derived registers become /range, and instance-of/iget-object copy into a checked scratch register first (move-object/from16 v0, pN). requireLocalRegisters now takes a count: Edition navigateToUrl needs two scratch registers for {p0, p2}. The Kubus deep link hook now passes only the Activity, and ProfileMenuPatch.handleDeepLink(Activity) reads the intent itself.
  3. Argument register. invokeArgumentRegister derives the register from the call's MethodReference: the parameter index, +1 for this unless it is invoke-static, wide types counted, and both the 35c and the range form. Edition Markdown uses it for addShareAction's list, and Kubus Markdown for setValue's argument.
  4. AGENTS.md: added pitfalls for branch targets, 4-bit forms and argument registers. Fixed docs/apps/gelderlander.md for the new deep link signature.

Verification

  • gradlew buildAndroid succeeds.
  • scripts/check-patches.sh prints ok (every patch applied) for AD, Trouw, Het Parool, BD, BN DeStem, De Stentor, ED, PZC, Tubantia (XAPKs), Volkskrant 7.52.0 and Videoland 1.115.2 (base APK). De Gelderlander 9.21.1: Morphe Desktop patch applied every patch.
  • I decompiled the patched Volkskrant and Gelderlander to smali. The hooks sit right before their return/invoke, with the original .line on the hook, and use the range form.
  • Device smoke test: not done yet.

🤖 Generated with Claude Code

Closes #59. ## Changes 1. **Branch targets.** New `addInstructionsAtControlFlowLabel` (`shared/util/Instructions.kt`): the hook goes in at the label of the instruction it precedes, so a `goto`/`if-*` to a return/invoke no longer skips it. It re-adds the instruction after itself, inserts the hook in between and removes the original location; dexlib2 moves its labels and debug items to the first hook instruction. Used at all sites from the issue: Edition review prompts and onboarding `isSuppressed`, the `VideoProduction` constructors, Kubus `ArticleDetailResponse.<init>`, the toolbar `setValue` call and `getSections`. 2. **4-bit register forms.** `const/4 pN` becomes `const/16`, invokes on parameter or derived registers become `/range`, and `instance-of`/`iget-object` copy into a checked scratch register first (`move-object/from16 v0, pN`). `requireLocalRegisters` now takes a `count`: Edition `navigateToUrl` needs two scratch registers for `{p0, p2}`. The Kubus deep link hook now passes only the Activity, and `ProfileMenuPatch.handleDeepLink(Activity)` reads the intent itself. 3. **Argument register.** `invokeArgumentRegister` derives the register from the call's `MethodReference`: the parameter index, +1 for `this` unless it is `invoke-static`, wide types counted, and both the 35c and the range form. Edition Markdown uses it for `addShareAction`'s list, and Kubus Markdown for `setValue`'s argument. 4. AGENTS.md: added pitfalls for branch targets, 4-bit forms and argument registers. Fixed docs/apps/gelderlander.md for the new deep link signature. ## Verification - `gradlew buildAndroid` succeeds. - `scripts/check-patches.sh` prints `ok` (every patch applied) for AD, Trouw, Het Parool, BD, BN DeStem, De Stentor, ED, PZC, Tubantia (XAPKs), Volkskrant 7.52.0 and Videoland 1.115.2 (base APK). De Gelderlander 9.21.1: Morphe Desktop `patch` applied every patch. - I decompiled the patched Volkskrant and Gelderlander to smali. The hooks sit right before their return/invoke, with the original `.line` on the hook, and use the range form. - Device smoke test: not done yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix: harden smali hooks against branch targets and register limits
All checks were successful
CI / Build (pull_request) Successful in 1m4s
db1a17c323
- New addInstructionsAtControlFlowLabel (shared/util/Instructions.kt): a hook
  inserted before a return or invoke takes over that instruction's labels, so
  a goto/if-* to it no longer skips the hook. Used for the review prompt and
  onboarding returns, the VideoProduction and ArticleDetailResponse
  constructors, Kubus getSections and the toolbar setValue call.
- No 4-bit register forms on parameter registers: const/16 instead of
  const/4, /range invokes, and move-object/from16 into a checked scratch
  register before instance-of/iget-object. requireLocalRegisters takes a
  count (Edition navigateToUrl needs two). The Kubus deep link hook passes
  only the Activity; the extension reads the intent itself.
- invokeArgumentRegister derives an argument's register from the call's
  MethodReference; the Edition Markdown hook uses it for addShareAction's
  list instead of assuming registerD.
- AGENTS.md: pitfalls for branch targets, 4-bit forms and argument registers.

Closes #59

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.