Skip to content

perf: prefix-only DEX inflate for faster class lookup - #53

Merged
MG1937 merged 4 commits into
mainfrom
dev-0.1.0
Oct 21, 2026
Merged

MG1937 merged 4 commits into
mainfrom
dev-0.1.0

Conversation

@MG1937

@MG1937 MG1937 commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Summary

This update improves Python ASC's smali disassembly quality, fixes missing method parameters in code-less methods, and reduces class lookup latency through prefix-only DEX inflation.

Python and Rust implementations will continue to be maintained in parallel so users can choose the integration style that fits their workflow.

Key Changes

Smali disassembly

  • Added complete smali rendering for:
    • .class, .super, .implements
    • fields and annotations
    • methods and .locals
    • branch labels
    • try/catch blocks
    • optional .line and local-variable debug directives
  • Added --debuginfo to enable DEX debug metadata output.
  • Added --method 'run(I)V' to render one exact method by full signature.
  • Fixed smali syntax:
    • field references now use ->field:Type
    • invoke instructions now use {v0, v1}
    • range invokes now use {v0 .. v3}
    • method descriptors no longer contain invalid spaces
  • Fixed abstract/native methods whose parameter list was incorrectly rendered as empty when no code_item existed.

DEX rebuild correctness

  • Fixed rebuilt code_item.debug_info_off so debug metadata remains addressable after DEX reconstruction.
  • Added fallback handling for stored entries, malformed prefixes, and DEX 041 containers.

Prefix-only DEX inflation

Class lookup now:

  1. Inflates only the DEX prefix needed to inspect string_ids, type_ids, class_defs, and the target descriptor.
  2. Rejects unrelated DEX files without full inflation.
  3. Fully inflates only the candidate DEX that contains the requested class.
  4. Falls back to the original full-inflate path when prefix parsing is unsafe.

Performance

Measured on:

  • APK: douyinneice.apk
  • Target class: com.bytedance.android.ec.core.hybrid.prefetch.NativePrefetch
  • Same command and workload before/after the prefix-inflate change
Metric Before After Improvement
APK class lookup median 727 ms 307 ms -57.8%
Internal total median 769 ms 342 ms -55.6%
Wall-clock median 1007 ms 523 ms -48.0%

The previous cli_getclass regression was also traced to method descriptor normalization in the decompiler hot path. Descriptor normalization is now performed only by the smali formatter, avoiding repeated string processing during decompilation.

Validation

  • Full test suite: 139 tests passed.
  • Prefix inflate tests cover:
    • deflated DEX entries
    • stored DEX entries
    • partial prefix parsing
    • full-inflate fallback
  • Disassembly tests cover:
    • annotations
    • debug info
    • fields
    • invoke/range invoke syntax
    • exact method filtering
    • try/catch and branch labels

Release

  • Python package version: 0.1.2-post3
  • Target branch: dev-0.1.0
  • Latest commit: b9cba55

- Add dadguard smali rendering for class metadata, fields, annotations, locals, labels, try/catch and optional debuginfo output.

- Normalize field references, method descriptors, invoke register braces and range invoke syntax so output is smali-assemblable.

- Fix rebuilt DEX debug_info_off handling and add --debug phase timing.

- Add prefix-only raw-deflate inflation for class lookup, with DEX 041, stored-entry and malformed-prefix fallback to full inflation.

- Add regression fixtures and tests for disassembly, invoke/field syntax, prefix inflation and CLI behavior.

- Measured NativePrefetch lookup improvement: 727ms median to 307ms; total pipeline 769ms to 342ms.
Keep declared parameters visible for abstract and native methods without code items, and add a regression test.
Add --method filtering for exact method descriptors, update CLI documentation and version, and cover API and CLI regression cases.
Restore the cached core descriptor path for decompiler instruction rendering and compact method descriptors only in smali output, preserving valid syntax without the getclass slowdown.
@MG1937
MG1937 merged commit 9216fe2 into main Oct 21, 2026
2 of 4 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