Skip to content

feat(dex): Android/DEX hardening, R8 recovery, canonical enums, and parallel export (v0.11.0) - #38

Merged
VillanCh merged 2 commits into
mainfrom
feat/v0.11.0-android-dex-hardening
Nov 22, 2026
Merged

VillanCh merged 2 commits into
mainfrom
feat/v0.11.0-android-dex-hardening

Conversation

@VillanCh

Copy link
Copy Markdown
Contributor

Summary

This minor feature release (v0.11.0) substantially hardens javajive's pure-Go Android/DEX -> JAR translation (dex2jar), R8 recovery, enum lifting, and best-effort archive decompilation (jarwar) against real-world, R8-obfuscated, and adversarial APKs/AABs while keeping all strict contracts (FailureStrict, filesys security, and strict enum/constructor decompilation proofs) intact.

Key Improvements

  1. DEX Recovery & Annotation Fault Tolerance (internal/dexparser, dex2jar/input, dex2jar/dex2jar.go)

    • Tolerate mismatched DEX header SHA-1 signatures with valid Adler-32 checksums and orphan AnnotationDefault elements under FailureRecover (and recover mode), while preserving fail-closed rejection under FailureStrict.
    • Allow method_ids growth >65,535 (Code.PatchedMethods, Code.PatchedNullArgs) across dex2jar/model and dex2jar/ir.
  2. Sound Bytecode Verification, Register Typing & Exception Coalescing (dex2jar/ir, dex2jar/lower)

    • Safe ExceptionTable coalescing and stackmap lowering (stackmap.go), clamping debug positions and empty local ranges (wave1_soundness_test.go).
    • Multi-kind companion slots and prologue stores (webPolySlots/pinned.polySlots, resolvedDefCategoryAt, resolvedUseCategoryAt), single-kind pinnedZeroKind handling in assignHomesLegacy, and consistent zero-source move/loadAs/transferSlotFrame local-kind emission (VerifyError elimination).
    • Null-array ops (0x44..0x51), JVMS §4.10.1.2 interface verification assignability (references.go), and open untyped-descriptor reference propagation across non-array uses (ir/constants.go, ir/categories.go) so null values merged with array paths lower soundly.
  3. CFG Constructor Validation & R8 <init> Synthesis (dex2jar/lower/validate.go, dex2jar/r8_init.go)

    • Dataflow-based constructor this-initialization validation (thisUninit/thisInit/thisMixed), supporting mutually-exclusive branching <init>, throw-only <init>, discarded filled-new-array, and recovered right-aligned constructor parameter annotations.
    • R8-inlined/stripped forwarding <init> synthesis across multi-DEX hierarchies and platform exception/core superclasses, with Ljava/lang/Void; parameter collision disambiguation (PatchedNullArgs) and constructor reuse.
  4. Canonical DEX/Kotlin Enum Lowering & Decompiler Cooperation (dex2jar/lower/enum_canonical.go, classparser/decompiler/core, classparser/decompiler/rewriter)

    • Infer enum declaration ordinal order from <clinit> (inferEnumFieldOrdinals), fuse pure enum constant allocations in <clinit>, and emit javac/Kotlin-canonical values() (including [Ljava/lang/Object;.clone()), valueOf(String), synthetic $values(), $VALUES, and Kotlin $ENTRIES bytecode sequences.
    • Delegate sealed SourceAssignmentForward wraps in statementReferencesLocal (classparser/decompiler/core/guarded_call_inline.go) and clean up dangling caught-exception expression discards (rewrite_var.go, try_rewriter.go) so regenerated enums lift without extends Enum fallbacks.
  5. Best-Effort Case-Fold Subdirectory Disambiguation & Bounded Parallel Export (internal/filesys, classparser/jarwar, classparser/dumper.go)

    • Sanitize colliding case-folded paths into <dir>__case<n>/<base> preserving .java basenames on case-insensitive filesystems, collect dump tasks deterministically, and parallelize DumpToLocalFileSystem via a bounded worker pool.
    • Sanitize synthetic stub method names with class_context.SafeIdentifier.
  6. Sealed CI & Soundness Tests (tools/requiredci, dex2jar, dex2jar/lower, classparser/..., internal/dexparser)

    • Added pure-Go and -Xverify:all regression suites (wave1_soundness_test.go, wave2_soundness_test.go, wave3_soundness_test.go, r8_init_test.go, casefold_recover_test.go, stub_method_name_test.go, parser_recover_test.go, and core/rewriter tests), bumped javajive.Version to "0.11.0", and updated sealed inventory hashes in tools/requiredci/main.go.

Real-World 8-APK / AAB Benchmark Scorecard (v0.10.1 Baseline -> v0.11.0, Temurin JDK 21 -Xverify:all + android-34.jar)

Target v0.10.1 Baseline (Recover / StubC / VErr / Java) v0.11.0 Result (Recover / StubC / VErr / Java / Stage B)
bundletool-install-time.aab (3 DEX 037, 1,298 cls) complete / 0 / 1 / 1298 complete (Strict=true) / 0 / 0 / 1298 / 35.562s (P1Err 3522->3507)
UnCrackable-Level1.apk (1 DEX 035, 7 cls) ERR (header SHA-1) partial / 0 / 0 / 7 / 147ms
UnCrackable-Level2.apk (1 DEX 035, 625 cls) ERR (header SHA-1) partial / 0 / 0 / 625 / 15.653s (P1Err=521(0))
UnCrackable-Level3.apk (1 DEX 035, 1,396 cls) ERR (header SHA-1) partial / 0 / 0 / 1396 / 40.991s (P1Err 701->250)
r2pay-v1.0.apk (1 DEX 035, 647 cls) ERR (header SHA-1) partial / 0 / 0 / 647 / 25.194s
NetGuard-v2.337-release.apk (1 DEX 035, 2,603 cls) ERR (orphan AnnotationDefault) partial / 0 / 0 / 2603 / 1m3.588s (P1Err 1141->754)
NewPipe_v0.29.3.apk (3 DEX 035, 11,501 cls) partial / 9709 / 0 / 11501 partial / 81 / 0 (11490 ok, 11 missing_dep) / 11501 / 9m28.171s
KeePassDX-4.5.8-libre.apk (3 DEX 035, 18,278 cls) partial / 1 / 10 / 8575 (5m timeout) complete (Strict=true) / 0 / 0 (18256 ok, 22 missing_dep) / 18278 / 8m35.222s
  • Across all 36,355 classes: 0 VerifyError, 0 ClassFormatError, 0 IncompatibleClassChangeError, 7/8 real-world apps at 0 stubbed classes (NewPipe reduced 9,709 -> 81, 99.17% reduction), and 36,355/36,355 Java source files emitted cleanly without Stage B timeouts.

Verification

  • git diff --check
  • go vet ./...
  • CGO_ENABLED=0 go build ./... and CGO_ENABLED=0 go build -tags javajive_full_jdk ./...
  • go run ./tools/requiredci -check, -run contract, -run dex, -run algorithm, -run corpus
  • go test -count=1 . ./cmd/javajive & go run ./cmd/javajive version (javajive 0.11.0)
  • JAVAJIVE_EXTERNAL_EVAL=1 go test -v -count=1 ./test/external (TestExternalJModAndJImage skipped without JAVAJIVE_JIMAGE_INTEGRATION=1)

…ms, and parallel archive export

- DEX recovery & annotation hardening (internal/dexparser, dex2jar/input): tolerate mismatched DEX SHA-1 headers with valid Adler-32 checksums and orphan AnnotationDefault elements under FailureRecover while preserving FailureStrict failure contracts.
- IR & register-kind soundness (dex2jar/ir, dex2jar/lower): fix null-array ops (0x44..0x51), JVMS interface assignability, untyped-null reference joins across non-array uses, multi-kind companion slots/prologue stores, legacy single-kind pinnedZeroKind, zero-source move/stackmap local-kind alignment, and safe try-catch exception table coalescing.
- CFG constructor validation & R8 <init> synthesis (dex2jar/r8_init.go, dex2jar/lower/validate.go): synthesize R8-inlined/stripped forwarding <init> chains (including platform exception/core hierarchies and Void-parameter collision disambiguation via PatchedMethods/PatchedNullArgs) plus CFG-based this-initialization, branching/throw-only <init>, discarded filled-new-array, and recovered parameter annotation right-alignment.
- Canonical DEX/Kotlin enums & enum decompilation (dex2jar/lower/enum_canonical.go, classparser/decompiler/core): infer declaration ordinal order from <clinit>, emit javac/Kotlin-canonical values()/valueOf()/()///enum-constant bytecode, and delegate sealed SourceAssignmentForward checks in guarded_call_inline.go.
- Archive export recovery & throughput (internal/filesys, classparser/jarwar, classparser/dumper.go): sanitize best-effort case-fold archive collisions into __caseN/ subdirectories preserving .java filenames, parallelize DumpToLocalFileSystem deterministically with bounded workers, and sanitize stub method names with SafeIdentifier.
- Sealed CI & soundness tests: add Wave 1-3.5 regression tests and sync tools/requiredci/main.go.
@VillanCh
VillanCh merged commit 241343a into main Nov 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant