Repository navigation
fix(android): report DEX static values of static final fields - #6981
Conversation
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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; both previous findings are addressed and no new actionable issue was established. SummaryAdds typed
Reviews (2) · Last reviewed commit: "fix(android): move the bridge to version..." · Reviewed by Greptile |
|
Ran the real Android lane on native Windows, which the PR notes it does not have. Host: Windows 11 Pro x64 (build 26300), non-elevated, Node 24.22.1, Temurin 21.0.12.1, and the pinned
Not run: Linux, and the new field through MCP by hand (the lane reports CLI/MCP parity, but I did not inspect the MCP field separately). |
|
@pablodiazjorge thanks a lot for the native Windows run. Seeing |
Summary
Fixes #6397.
inspect-android-classlistedstatic finalfields with only a name and type. javac and d8 inline compile-time constants and store their values in the class definition's DEX static values, so these classes usually have no<clinit>and REA had no way to show the value at all. Each field in the result now carriesdex_static_value: a typed value for astatic finalfield whose class definition encodes one, andnullotherwise.Problem and expected behavior
REA's JADX bridge (
bridge/android/ReaJadxBridge.java) builds the class summary from parsedFieldNodes and only copied the alias and type:JADX already parses the encoded static value into the field's
CONSTANT_VALUEattribute when it loads the class, before any code generation, so the information was there and just never reported. For the issue's example class,MAX_SIZE,PACKET_FLAG_CONFIGandTAGcame back with no values, andinspect-android-method ... <clinit>correctly said the method does not exist. Expected: each such field reports its typed value (int, long, string, and so on).Change and scope
dexStaticValue(FieldNode)readsCONSTANT_VALUEforstatic finalfields and emits{type, value}for the Java constant kinds:boolean,byte,short,char(UTF-16 code unit as a number) andintas JSON values, andlong,floatanddoubleas Java's text for the value, so1L << 63stays"-9223372036854775808"and doesn't get rounded as a JSON number. Strings are reported as-is. The value is captured in the same pre-generation snapshot as the rest of the summary.EncodedValue.NULLto everystatic finalfield that has no encoded value (for example a field assigned only in<clinit>), and an encoded null comes back as that same instance, so the two can't be told apart. Those fields reportdex_static_value: null, the same as non-final, instance, and other encoded kinds (enum, type, array, and so on).get_class_summarytakes an optional booleandex_static_values, and only theinspect_android_classpath sets it.inspect_android_methodandtrace_android_referencesget the same member-only summary as before, so large encoded strings can't push their lookup past the 8 MiB frame limit. A non-boolean flag is refused.JADX_BRIDGE_IDENTITY, because the summary request and shape changed. Main moved the bridge to 6 for binary class selectors while this was open, so I merged main and took the next number. That follows how earlier bridge changes were versioned.dexStaticValueSchemainsrc/domain/android/androidAnalysis.tsvalidates the value per type with exact ranges: byte/short/char/int as JSON integers,longtext within the signed 64-bit range,floattext that stays finite as a 32-bit float anddoubletext that stays finite, withNaNandInfinityspellings accepted. Nonzero text that would round to zero is refused. The bridge protocol accepts it as optional and the result always includes it, nullable. A malformed or lossy value from the bridge fails with the existing "JADX class summary failed or was malformed" output error, so I didn't add any new user-visible error text.docs/android-analysis.mdand theinspect_android_classtool description. Both say that a static initializer can still assign the field, and that<clinit>evidence still comes frominspect_android_method. The docs also say only class inspection asks for the values.I limited this to
static finalto match the issue. The DEX static values array also holds initial values for non-final statics, but those are not constants and I didn't want to present them as such.Follow the contribution scope.
Scope decision: not applicable (ordinary fix within existing boundaries).
Contract and boundary impact
ReaJadxBridgeclass indexing (selected), where the frozen per-class summary is built from parsed members.inspect_android_classfields[]gains a required, nullabledex_static_value. The tool input schema is unchanged. The tool description mentions the new value.NOT_LOADED.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): none committed;metadata:checkpasses.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
(Same APK reads through the existing JADX session; one more parsed attribute is reported.)
Evidence and regression coverage
Tests added or updated:
tests/conformance/android/ReaJadxMetadataRegression.java: newverifyConstantFieldsagainst the real audited JAR, using a new smali fixturetests/fixtures/android/static-initializers/ConstantFields.smaliassembled into the existing initializer APK. It checks all nine Java constant kinds, includinglong-0x8000000000000000L,char'A',float1.5fanddouble0.5. Four fields must report no value: an explicitnullString, an unencodedstatic finalobject, a non-final static with an encoded7, and an instance field. It also checks that the existing<clinit>-assigned finals (InitializationPolicy.POLICY,MixedInitialization.LABEL) do not pick up JADX's null placeholder, that the class staysNOT_LOADED, and that a repeated summary is identical. It also checks that the default summary (nodex_static_values, orfalse) equals the valued one withdex_static_valuestripped, and that a non-boolean flag is refused.scripts/verify/android/metadata.mjsasserts the newCONSTANT_FIELD_REGRESSION_PASS ... opt_in=trueline.tests/boundary/android/JadxAnalysis.test.ts: the issue's three constants plus an unencoded field go through the adapter. A lossy long number, a string int, a numeric double and an unsupportedenumkind are each refused. Boundary values for every numeric type are accepted, and out-of-range ones (for example long9223372036854775808, float1.0E40and3.4028236E38, double1.8E308) are refused. A table over class inspection, method inspection and both trace forms checks that only class inspection sendsdex_static_values: true.Base reproduction (executed): with the tests and without the fix. These outputs are from the first commit; the review follow-ups were checked the same way (the opt-in conformance check fails on the previous bridge with
Default class summary carried DEX static values, and the eight new out-of-range cases plus the class-inspection request case fail on the previous adapter).Conformance against the real JAR (JDK 21, jadx-headless-mcp 0.7.1, ApiDemos fixture):
Adapter test:
With the fix, conformance prints
CONSTANT_FIELD_REGRESSION_PASS encoded=9 absent=4 opt_in=trueand exits 0 with every other regression line still passing, and the adapter file isTests 79 passed (79)on the current head (it includes main's new tests).User-visible CLI/MCP output (if applicable): the issue's class, assembled from smali into a one-class APK (
com.example.FlagswithMAX_SIZE = 1024,PACKET_FLAG_CONFIG = 1L << 63,TAG = "flags", no<clinit>), run through a freshly compiled runtime with the real JADX engine. Output trimmed tonormalized_result.fields.Before:
After:
Remaining proof gaps: I ran macOS arm64 only. @pablodiazjorge ran
npm run verify:androidon native Windows against the first commit and it passed; Linux is not run. I did not run MCP by hand for the new field; it uses the same adapter and result schema, and the real verify lane's MCP checks pass. A trailing default-valued constant that the DEX writer leaves out of the static values array reportsnull, because JADX then has only its null placeholder. I saw this with smali's writer (A = 1,ZERO = 0givesZEROnull). I did not check d8. The docs describe it as "no value is encoded".For evidence-bearing changes:
Validation performed
Run with Node 24.18.0 and Temurin JDK 21.0.13 on macOS arm64, using the pinned JAR and ApiDemos APK from
npm run fixtures:android.ReaJadxMetadataRegressioncompiled withjavacagainst the JAR and run asscripts/verify/android/metadata.mjsdoes: all regression lines pass, includingCONSTANT_FIELD_REGRESSION_PASS encoded=9 absent=4 opt_in=trueand main'sRAW_CLASS_SELECTOR_REGRESSION_PASS nested=true metadata=true references=true(fails without the fix, shown above)REA_ANDROID_TEST_APK=... REA_JADX_MCP_JAR=... npm run verify:androidon the merged head: exit 0, 35 PASS lines, every metadata, method-body and direct-invoke PASS line, and a report withcli_mcp_parity: true,metadata_without_code_generation: true,apk_executed: falsenpx vitest run tests/boundary/android/JadxAnalysis.test.ts: 79 passednpx vitest runovertests/boundary/android,tests/boundary/providers/android,tests/boundary/mcp/androidPackageSummaryMcp.test.ts,tests/boundary/mcp/androidLateCompletionMcp.test.tsand the Android/JADX process tests (jadxIntegration,androidAnalysisMcp,jadxStartup,androidSearchEvidenceBudget,androidSnapshotClose): 16 files passed, 1 skipped; 338 passed, 1 skippednpm run checktasks run individually:lint:built(0 errors),knip,metadata:checkandverify:architecture-guardspassed.typecheckpasses with no errors.format:checkwas run asoxfmt --checkon the changed files (clean).npm run compile, then the CLI commands above.Compatibility, safety, and release
fields[]would need to acceptdex_static_value. Bridge version 7 is required, and it ships in the same package.Author readiness
Human owner: @Abelo9996
Before merge
type(scope): outcome.