Skip to content

feat: add multi-DEX support for parsing APKs and directories#1

Open
komen205 wants to merge 1 commit intoandroguard:mainfrom
komen205:feat/multi-dex
Open

feat: add multi-DEX support for parsing APKs and directories#1
komen205 wants to merge 1 commit intoandroguard:mainfrom
komen205:feat/multi-dex

Conversation

@komen205
Copy link
Copy Markdown

@komen205 komen205 commented Apr 3, 2026

Summary

Android apps exceeding the 65K method reference limit use multiple DEX files (classes.dex, classes2.dex, ..., classesN.dex). This PR implements the Multi-DEX Aware feature from the README TODO, providing a unified view across all DEX files in an APK or directory.

  • Rust: MultiDexHelper with from_directory() and from_apk() constructors, unified classes()/methods()/fields()/strings() iterators, Sourced<T> wrapper for provenance tracking
  • Python: MultiDEXHelper with from_apk(), from_directory(), from_dex_files() constructors, unified iterators yielding (DexSource, item) tuples
  • CLI: --apk and --dir flags for both Rust and Python CLIs

Design

Since DexHelper/DEXHelper already resolve all indices to strings, there's no need to merge index namespaces. MultiDexHelper wraps multiple DexHelper instances and flat-maps their iterators, tagging each item with its source DEX filename. Fully backward compatible — no changes to existing APIs.

Dependencies

  • Rust: Optional zip crate behind apk feature flag (cargo build --features apk)
  • Python: Uses stdlib zipfile — zero new dependencies

Tested against

Ticketmaster APK (10 DEX files, 82K+ classes, 50K+ methods):

$ dexparser --apk base.apk
Loaded 10 DEX file(s) from APK
  [classes.dex] (index 0)
  [classes2.dex] (index 1)
  ...
  [classes10.dex] (index 9)

CLASSES:
  [classes.dex] CLASS LCityEntity; (super: Ljava/lang/Object;)
  [classes10.dex] CLASS Lorg/xmlpull/v1/XmlPullParser; (super: Ljava/lang/Object;)
  ...

Files changed

File What
dexparser-rs/src/multidex.rs NewMultiDexHelper, DexSource, Sourced<T>, constructors, iterators, 7 unit tests + 1 integration test
dexparser/multidex.py NewMultiDEXHelper, DexSource, constructors, iterators
dexparser-rs/src/error.rs Add NoDexFiles, Io error variants
dexparser-rs/src/lib.rs Wire up pub mod multidex + re-exports
dexparser-rs/Cargo.toml Add optional zip dep + apk feature
dexparser-rs/src/bin/dexparser.rs Add --apk/--dir CLI flags
dexparser/__init__.py Export MultiDEXHelper, DexSource
dexparser/main.py Add --apk/--dir CLI flags
README.md Remove [TODO], add multi-DEX usage examples

Test plan

  • cargo test — 28 unit tests pass (sort key, name matching, empty/single/multi DEX, directory scan)
  • cargo test --features apk test_real_apk -- --ignored — integration test against real 10-DEX APK
  • cargo run --bin dexparser -- -i classes.dex — single-DEX backward compat verified
  • cargo run --features apk --bin dexparser -- --apk base.apk — multi-DEX APK parsing verified
  • Python --apk and --dir flags functional

🤖 Generated with Claude Code

Android apps exceeding the 65K method limit split across multiple DEX
files (classes.dex, classes2.dex, ...). This adds MultiDexHelper (Rust)
and MultiDEXHelper (Python) that provide a unified view across all DEX
files with source provenance tracking.

- New MultiDexHelper/MultiDEXHelper with from_apk(), from_directory()
- Sourced<T> wrapper tags each item with its source DEX filename
- APK support via optional `zip` crate behind `apk` feature flag
- CLI: --apk and --dir flags for multi-DEX mode
- 7 unit tests + 1 integration test against real 10-DEX APK
- Python uses stdlib zipfile (zero new dependencies)
- Fully backward compatible: existing single-DEX API unchanged

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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