All posts
Mobile Security
android
reverse-engineering
apk
dex
smali
decompiler
kotlin
mobile-security
on-device

APK Inspector: Building an On-Device APK Explorer and Decompiler

An Android app that unpacks, indexes and decompiles APKs entirely on the phone — with no network permission at all. The binary XML decoder written from scratch, the indexing strategy that keeps it fast, and the viewer that scrolls a 200,000-line dump.

September 19, 2026 8 min read
MOBILE SECURITY
android
reverse-engineering
dex
smali
kotlin

Author

Aman Kumar

Published

Sep 19, 2026

Project

APK Inspector

TL;DR

An Android app that opens an APK, walks its package tree, and shows any class as Java or smali — plus the file tree, decoded manifest, signing certificates and per-DEX statistics. Everything runs on the phone, and there is no INTERNET permission in the manifest.

Parser

Binary AndroidManifest.xml decoder written from scratch. No external tool.

Indexing

Only DEX class_def tables up front. Members parsed on demand.

Viewer

One list row per source line, so a 200,000-line dump still scrolls.

The Idea

Why Build This At All

Inspecting an APK is a desktop ritual — pull the file off the device, move it to a laptop, open a decompiler GUI. But most of what I actually want to know is small:

Is this build debuggable?
What does the manifest really declare?
Which certificate signed it?
What is in this one obfuscated class?
How close is this DEX to the method ceiling?

Two-minute questions that cost a fifteen-minute round trip. The on-device alternatives are either closed-source utilities with an ad SDK bolted on, or web services whose first step is uploading the APK to someone else’s server — a non-starter for a pre-release build or a client’s app.

Which means unpacking, binary XML decoding, DEX parsing, disassembly and decompilation all run in one Android process, on a device that might be a mid-range phone.

Primer

What Is Actually Inside an APK

An APK is a ZIP

A standard ZIP reader opens it — which also means it carries every classic ZIP risk.

The manifest is not text

It is compiled binary XML. A text viewer shows noise, which is why most tools shell out to decode it.

Code lives in DEX

One or more classes*.dex files of Dalvik bytecode, each opening with a fixed 112-byte header.

Two views of the same code

Smali is the exact bytecode, so it is what you trust. Java is the readable summary you reach for first.

Showing both, one tap apart and able to jump to the same member in either, means you never have to pick one up front.

Architecture

How the App Is Put Together

Every screen is one step deeper into the same file:

APKpackagesclassesfields & methodsJava | smali

Four packages, strict one-way dependencies — ui may call core, never the reverse:

core/

Everything that touches an APK

Unpacking, binary XML decoding, the class index, the disassembler, the decompiler. 9 files, ~1,700 lines. No Android UI types — which is what makes it testable on a plain JVM.

ui/

Twenty files, one row layout

Six tabs over an open APK, plus the class screen and code viewer. Every list renders through one shared row helper — why the screens look like a single product.

model/

Plain data

~100 lines of data classes — node tree, package info, certificates, DEX entries.

util/

Formatting, colour, errors

Formatters, syntax highlighters for Java/smali/XML, preferences, and the error translator every failure routes through.

Opening an APK runs a six-stage pipeline, each stage reporting a real percentage rather than an indeterminate spinner:

Open pipeline

Copy into app cache (2 → 20%)Read the ZIP directory (22%)Unpack every entry (22 → 82%)Decode AndroidManifest.xml (86%)Read package info (92%)Done (100%)
The Toolkit

What I Used, and What For

A few well-chosen libraries for the formats that are genuinely hard — and hand-written code wherever the format is small enough to own outright.

PieceWhat it does
Kotlin + XML viewsThe whole app. No Compose — view binding and RecyclerView give finer control over the code viewer, the screen that had to be fastest.
Material 3Theming, light and dark, Material You, edge-to-edge on Android 15.
Coroutines + StateFlowUnpacking, indexing and decompiling off the main thread, with progress the UI can observe.
Standard ZIP readerUnpacking the archive.
Hand-written binary XML decoderThe manifest and every compiled res/*.xml. Written in-project.
Hand-written DEX header readerPer-DEX statistics, straight from the 112-byte header.
A DEX/smali libraryLoading DEX files and producing smali — a format big enough that owning a parser would be its own project.
A Java decompiler engineReconstructing readable Java from bytecode.
RecyclerViewThe code viewer, one row per source line.
SAF + MediaStoreReceiving a file without storage permissions; saving exports to Downloads/.
Deep Dive

Five Decisions That Made It Work

Five problems, and the shape of each answer:

1

Writing the binary XML decoder by hand

8 chunk types

Challenge

The manifest is compiled binary XML — a chunked format with a string pool and typed attribute values.

Approach

A self-contained chunk parser with no dependency beyond the JDK. Unknown chunks are skipped by their own declared size rather than treated as errors.

Result

One decoder covers the manifest and every compiled res/*.xml — so tapping a layout file shows readable XML, for free.

2

Indexing only what is cheap

class_def only

Challenge

A large app holds thousands of classes across several DEX files. Parsing every member up front is slow and almost entirely wasted.

Approach

Read only the class_def table per DEX — type, name, package, access flags, source DEX. Full member lists are parsed per class, on open.

Result

The package tree appears quickly and memory stays flat no matter how large the app is.

3

Reading the DEX header directly

112 bytes

Challenge

The statistics tab wants counts of strings, types, fields, methods and classes for every DEX in the APK.

Approach

Parse the fixed-size header at the start of each file. No DEX library involved — just the right offsets.

Result

Statistics render instantly at any file size, including method references charted against the 65,536 ceiling.

4

One list row per source line

200,000 lines

Challenge

A whole-DEX smali dump runs to hundreds of thousands of lines. A single text view freezes the app on open.

Approach

Split on newlines and make each line its own list row, so only the lines on screen ever render. Highlighting is lazy, with a 600-line cache.

Result

Huge dumps open and scroll like any other screen — and find-in-file, line numbers and wrap all build on the same structure.

5

Keeping the heavy component isolated

0 dependents

Challenge

Decompiling is the one operation that loads an entire APK into memory.

Approach

A strict one-way dependency: nothing else in the app is allowed to depend on the decompiler.

Result

Structure, manifest, DEX statistics and smali all work regardless — and decompilation can be switched off entirely in Settings.

Security Posture

Hardening an App That Eats Untrusted Files

Every input this app takes is untrusted by definition.

No INTERNET permission

The one declared permission is QUERY_ALL_PACKAGES, for the installed-apps picker. Remove it and file-opening still works.

Two-layer zip-slip guard

Entry names are filtered, then every resolved path is independently checked against the work directory before a byte is written.

Every error is translated

Raw exception text never reaches the UI — internal prefixes stripped, common failures mapped to plain sentences.

Failures stay contained

Out-of-memory conditions on very large archives are caught and reported in place, not allowed to take the process down.

The traversal guard being two independent layers is deliberate: string filtering alone has a long history of being defeated by encoding tricks, so a canonical-path comparison backs it up.

Results

What’s next

Parse resources.arsc — resolve the raw resource IDs in the decoded manifest, and open the door to a proper resources browser.

Cross-references — “find usages” and string search across a DEX, the features I most want on an unfamiliar app.

Wrap Up

Conclusion

Take away the server and every easy answer goes with it. What’s left is a long run of decisions about how much work a screen is allowed to do before anyone notices — and getting those right is the app.

It fits in a pocket now. That still feels like it shouldn’t be true.

Further Reading

References

APK Inspector links against open source components under BSD-3-Clause, Apache-2.0 and SIL OFL 1.1. The required notices ship inside the app, under About → Open source licences.