Repository navigation
feat(android): annotate class and method inspection with R8/ProGuard mappings - #7137
555aaditya wants to merge 4 commits into
Conversation
…ted R8/ProGuard mappings Refs morluto#6329
[Medium impact] The reviewed changes appear safe to merge; both previous findings are addressed and no new blocking issue was found. SummaryAdds optional R8/ProGuard name annotations to Android class and method inspection. Mapping claims stay separate from observed APK names.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Request reaches queue front] --> B[Clear idle timer]
B --> C[Create operation deadline]
C --> D[Read and parse optional mapping]
D -->|Accepted| E[Run JADX inspection]
E --> F[Add mapping claims separately]
D -->|Refused| G[Return error without using session]
F --> H[Schedule idle retirement]
G -->|Session remains loaded| H
Reviews (4) · Last reviewed commit: "fix(android): read mappings under the op..." · Reviewed by Greptile |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Integrate the class, method and field mapping boundary from PR #7137 while preserving the shared manifest inventory and default-package regression. Co-authored-by: 555aaditya <[email protected]>
|
Closing as superseded: this landed on main through #7456 (03f17cf), which carries this branch at 505b95e with co-author credit. Thanks @gensokyo-dev for integrating it and extending it with retained summaries and the parsed-index reuse! |
Summary
Refs #6329. This is the first of two PRs: it covers class and method inspection. Search and trace come in the follow-up, so the issue stays open.
inspect_android_classandinspect_android_method(andrea inspect-android-class/inspect-android-method --mapping-path) accept an optional absolutemapping_pathto an R8/ProGuardmapping.txt.The result gains one additive
mappingblock:compiler,compiler_version,min_api,map_version,pg_map_id,pg_map_hash;Observed rows, selectors and Evidence for calls without a mapping are unchanged. Mapped names are reported as claims from the file, never as observations of the APK.
Problem and expected behavior
R8/ProGuard release APKs show names like
a.b.c(). An analyst who has the build'smapping.txtcurrently has to translate every class and member by hand.Expected behavior: look names up by raw DEX identity, not JADX display aliases, and never guess. Each symbol resolves to one of three statuses:
mappedverified_by: "class"), methods by DEX prototype ("descriptor"), fields by DEX type ("type"). R8residualsignaturemetadata is used when present; otherwise original types are translated through the file's class records.ambiguousmultiple-records,descriptor-mismatch,type-mismatchorambiguous-class, withcandidate_countand up to 8 candidates. A name-only match whose prototype or type doesn't verify is never reported as mapped.unmappedFurther behaviour:
Inline frames: a line continues a stack when it repeats the previous line's minified range and obfuscated name and gives a single call-site line (
:7), as R8 writes caller frames. Only the outermost original becomes a candidate. Original line numbers and source files aren't projected.Malformed records are counted and skipped, and parsing continues.
Refused with an input error, before JADX is touched:
resource_constraint);usage.txtorseeds.txtpassed by mistake.So a bad mapping never launches or retires the JADX session, and switching to a different mapping reuses the loaded APK.
Change and scope
Domain (pure):
src/domain/android/proguardMapping.ts: line grammar, inline-frame grouping, residual-signature metadata, malformed samples.src/domain/android/androidMapping.ts: limits, the result schema andprojectAndroidMapping.src/domain/android/dexTypes.ts: holdsdexDescriptorSchemaand the newdexTypeSchema, so the mapping schema can share them without a circular import.Provider:
src/android/AndroidMappingFile.tsreads the file through the provider's#prerequisitesresource scope.JadxProviderreads the mapping inside the request's queue turn and under the operation deadline, before any session work. Only one parsed mapping is held at a time. A refused mapping keeps the loaded session, and its idle timer is rescheduled.JadxAnalysisresolves against the bridge's raw identities. It checks that the display and raw inner-class lists line up, and fails withAnalysisOutputErrorotherwise.Bridge (additive, version 7 → 8):
bridge/android/ReaJadxBridge.javaadds:raw_nameon methods;raw_nameanddex_typeon fields (TypeGen.signatureof the raw field type);inner_class_raw_nameson the class summary.JadxProtocol, the Java metadata regression andscripts/verify/android/metadata.mjsare updated to match, following the shape of fix(android): report DEX static values of static final fields #6981.Contracts and CLI:
mapping_pathon the two tools, with an example;--mapping-pathoption.Docs:
docs/android-analysis.md: a new "Apply an R8/ProGuard mapping" section, the interpretation note and the memory bound;docs/testing.md;Limits are fixed, with no runtime override (see #6176):
The file is read once per call and parsed in memory, with no caching.
Not included:
search_android_classesandtrace_android_references(PR 2).pg_map_idis reported, not compared, and a limitation says so.No speculative race or security hardening was added. The fail-closed rules come from the format itself (record grammar, prototype and type verification) and from refusing to guess between candidates.
Contribution scope: static name annotation from a caller-supplied local file. There's no APK modification, no fetching, no execution and no new provider.
Contract and boundary impact
src/domain/android/proguardMapping.tsowns record interpretation and resolution;mapping_pathand optional outputmappingon two tools;tools/listgrows slightly;mapping_pathin its parameters and the file's SHA-256 in the result.docs:generateanddocs:checkpass.Expected effects:
Evidence and regression coverage
Tests added or updated:
src/domain/android/proguardMapping.test.ts, 25 tests covering:tests/boundary/android/JadxAnalysis.test.ts:tests/boundary/process/androidMappingMcp.test.ts: stdio MCP against the fake JADX server.tests/boundary/process/jadxIntegration.test.ts: after a refused mapping, a loaded engine still retires when idle.tests/acceptance/tools/localToolContracts.test.ts: the contract examples.tests/conformance/android/ReaJadxMetadataRegression.java(verifyRawMemberNames) plus theRenamedMembers*.smalifixtures. These check that the real bridge reports raw method and field names,dex_typeand inner-class raw names for members JADX renames.scripts/verify/android/metadata.mjsassertsRAW_MEMBER_NAME_REGRESSION_PASS.Base reproduction: I temporarily broke three pieces of logic and confirmed the matching tests fail:
Representative output (fake JADX,
inspect_android_class a.b):Remaining proof gaps:
Real Android metadata bridgeworkflow (Ubuntu 24.04, JDK 21, checksum-pinned JADX): run 40197903690. That run passed every regression marker, including the newRAW_MEMBER_NAME_REGRESSION_PASS. Later commits don't touch the bridge or its fixtures.mapping.txt, wasn't tested.For evidence-bearing changes:
Validation performed
macOS arm64, pinned Node 24.22.1 / npm 11.19.1,
npm ci, branch merged withorigin/mainatd41c1c6ff:npm run test:local -- src/domain/android/proguardMapping.test.ts: 25 passed.npm run test:focused -- tests/boundary/android/JadxAnalysis.test.ts tests/boundary/process/androidAnalysisMcp.test.ts tests/boundary/process/jadxIntegration.test.ts tests/boundary/process/androidMappingMcp.test.ts tests/acceptance/tools/localToolContracts.test.ts: 5 files, 151 passed.npm run verify:test-discovery: all 2,487 test files discovered once.npm run check:fast: passed.node scripts/verify-module-boundaries.mjs: clean.npx oxfmt --checkon all changed files: clean.npm run docs:generate && npm run docs:check: passed.npm run test:fast(after merging main): 18,918 passed, 27 skipped, 0 failed.toolInputReferences,absoluteLocalPathSchemaand three other MCP tests.mainwas failing the same tests at the time (for example onf69c52a1c). After merging the now-greenmain, they pass locally.Compatibility, safety, and release
JadxSessionalready refuses a bridge that reports a different identity.JADX_RELEASE0.7.1) on Linux x64 / JDK 21 through the fork workflow above; macOS and Windows not run.Open questions for review
class_name: "com.example.Original")? I kept v1 to observed names only.pg_map_idagainst anything in the APK? Today it only reports the value, with a limitation.ambiguous-class), each member of it that has no candidates is reported asunmapped, notambiguous. Is that the reading you'd expect?Author readiness
Human owner: @555aaditya
Before merge
type(scope): outcome.