Finding Vulnerable Libraries in an APK (Mobile SCA Done Right)

A huge fraction of an Android app is not the developer's code, it is third-party libraries: networking stacks, crypto helpers, analytics SDKs, image loaders, JSON parsers. When one of those ships a known CVE, the app inherits it, and nobody writes a line of vulnerable code to make that happen. On the server side, software composition analysis (SCA) reads your pom.xml or your lockfile and tells you exactly what you depend on. In an APK you have none of that. You have a single binary: shrunk, inlined, renamed bytecode with the dependency manifest long gone. This post is about doing real SCA on that binary anyway, why the obvious approach fails silently, the mechanism that works, and the limits we will not pretend away.

The problem: no manifest, just bytecode

A desktop or server SCA tool has it easy. The build system wrote down every dependency and its exact version, and the tool reads that list. An Android release build does the opposite: it takes all those dependencies, compiles them together with the app, and then runs the whole thing through R8, which exists specifically to make the result smaller and faster, not auditable. The versions.txt is not in the APK. The group and artifact coordinates are not in the bytecode. What you get is a classes.dex where the app's code and a dozen libraries' code are fused into one renamed graph of types. SCA on an APK is the problem of recovering "which versions of which libraries are in here" from that graph alone.

Why you cannot just hash the classes

The first instinct is the clean one: fingerprint each bundled library by hashing its class files, build a database of those hashes for every published version, and match. It is simple, it is exact, and it breaks on the first real app. Three things R8 does each defeat a hash independently.

Shrinking removes unused classes and methods. The okhttp3 in a real app is not the okhttp3 on Maven, it is the subset the app actually calls, with the rest deleted. A hash of the full artifact matches a subset exactly never. Inlining and optimization rewrite method bodies, fold constants, and merge code, so even a class that survives has different bytes. Renaming turns okhttp3.internal.connection.RealCall into a.b.c and every member name with it, which changes the bytes again and destroys the one thing a hash needed to be stable: identity. After R8, the library in the app and the library on Maven share almost no bytes, so a hash of one matches the other with probability zero.

The failure would be tolerable if it were loud. It is not. You run a hash-based scan against a release APK, you get zero library matches, and the natural conclusion is "this app has no known-vulnerable dependencies." The app is full of them, under stripped names, and the tool just told you it was clean. A dependency scanner that reports nothing on an obfuscated app is not reassuring, it is broken in the one way you cannot see.

Identify by shape, not by name or hash

The property that survives R8 is structure. R8 renames identifiers and strips unused members, but it cannot rename the Java and Android platform. It cannot change what a method takes and returns at the type level without breaking the program, and it cannot rename java.lang.String or android.net.Uri. So the stable identity of a library class is not its name or its bytes, it is the shape of its method signatures and its place in the type hierarchy, read through a normalization that throws away everything R8 is allowed to touch and keeps everything it is not.

We call the unit of that shape an atom: one normalized method descriptor. Take a method's full proto, say (Lokhttp3/Request;ILjava/lang/String;)Lokhttp3/Response;, and normalize each parameter and return type by a fixed rule. Primitives (I, Z, J, and the rest) are kept verbatim. A type on a framework allow-list, anything under java/, android/, androidx/, kotlin/, kotlinx/, javax/, org/json/, org/w3c/, org/xml/, is kept verbatim, because a shrinker cannot rename those. Every other type, the app-specific and library-specific ones R8 can rename, collapses to a single placeholder, L#;. Array dimensions are preserved. Member names and the type's own name never enter the atom at all. So the descriptor above normalizes to (L#;ILjava/lang/String;)L#; whether the library kept its names or was renamed to gibberish. That normalized string is hashed to 64 bits, and that is one atom.

From atoms to a class profile

A single atom is not distinctive, plenty of classes have a (L#;)L#; method. A class is distinctive, and we model it as the set of its atoms: one atom per non-synthetic method descriptor, plus the normalized superclass and each interface folded in as tagged pseudo-atoms (tagged so a superclass relationship and a method with the same normalized form do not collide, and folded as a set so declaration order does not matter). That set, sorted and de-duplicated, is the class profile.

Two guards keep the profiles honest. A type with fewer than two distinct normalized method descriptors is marked non-distinctive and yields no profile at all, because tiny types (a two-method POJO, an empty marker interface) collide across every library and would inflate any similarity score they touched. And the profile is a set of a class's own structural facts, nothing about the app around it, which is what lets the same reference class be recognized whether it was bundled whole or shrunk to half its methods.

Matching: Jaccard per class, fraction per library

Matching happens at two levels, and both use thresholds rather than equality, because shrinking means you are always matching a subset.

At the class level, a reference class (built from a real published artifact) is "present" in the app if some app class has a Jaccard similarity of at least CLASS_SIM = 0.70 with it. Jaccard is intersection over union of the two atom sets, so a reference class that R8 shrank by a method or two, dropping a few atoms, still clears 0.70 against the surviving app class. An app class that merely coincidentally shares a couple of atoms does not.

At the library level, the score is the fraction of a reference version's distinctive classes that are present: score = |present reference classes| / |reference classes|. A version is a candidate match only if that fraction clears THRESHOLD = 0.75 and the absolute count of present distinctive classes is at least MIN_ABS = 10. The absolute floor matters as much as the fraction: a small library, or a heavily shrunk inclusion of a large one, can reach 0.75 on a handful of coincidental class matches, but ten distinctive classes agreeing at this strictness, each a set of at least two distinct normalized descriptors hashed together with its hierarchy, is far beyond what unrelated code produces by accident.

Checking every reference class against every app class would be quadratic. The candidate app classes for a given reference come from a MinHash band index: classes that share a band are likely to be similar, so the index proposes a short list and the exact Jaccard is computed only on those. The index bounds how many comparisons run; the 0.70 Jaccard gate still makes the final call.

What R8 does Breaks a hash? Breaks shape matching?
Rename classes and members Yes, identity is gone No, names never enter the atom
Shrink unused classes/methods Yes, bytes differ Tolerated by the 0.70 Jaccard gate
Inline and optimize bodies Yes, bytes differ No, atoms are from signatures, not bodies
Keep platform types (java/, android/) n/a This is the anchor it relies on

A worked example: okhttp under R8

Say an app bundles okhttp and R8 renames RealCall, Request, and HttpUrl to a.b.c, a.b.d, and a.b.e. The fingerprint stage recognizes each by its profile, the set of its normalized descriptors, against the reference profile for the okhttp version it came from, without ever seeing the real names. That alone identifies the version.

The structure recovery goes one step further for the cases that need it. RealCall holds exactly one field whose type is a Request, and Request holds exactly one field whose type is an HttpUrl. Those "exactly one field of this type" relationships are preserved by R8 (it renames the types but does not change that a.b.c has a single a.b.d-typed field), so once the three classes are located by shape, the RealCall → Request → HttpUrl → url chain is resolved by field type, unambiguously. That is the same structural-identity idea, class shape, applied not just to name a version but to hand the runtime a renamed class to hook. Version identification and obfuscation-resilient instrumentation are the same technique at different altitudes.

From "which version" to "which CVE"

Identifying the library and version is half the job. The other half is the vulnerability lookup, and this is where a lot of SCA quietly inflates its numbers. Knowing an app contains okhttp 3.12.1 is not a finding; knowing that 3.12.1 falls inside the affected range of a specific advisory is.

Rutken fetches a published vulnerability dataset sourced from OSV, the open vulnerability database, and matches each identified version against the advisories' affected ranges, not against a name. An advisory carries a range (introduced-in, fixed-in, last-affected), and the extracted version is compared inside that range with ecosystem-correct version ordering, so a 3.12.1 is correctly placed relative to a "fixed in 3.12.2" boundary. A finding is emitted as confirmed vulnerable only when the version lands inside at least one advisory's affected range; a library we identified but whose version we could not confirm against a range is reported separately, at lower confidence, as a presence match rather than a vulnerability. The distinction is deliberate: a confirmed-vulnerable finding says "this exact version is in a published affected range, here is the advisory," and a presence finding says "this component is here, we could not confirm the version against a range," and those are different claims that deserve different confidence.

Confidence tracks how the version was established, too. A version recovered only from the structural fingerprint is one thing; a version corroborated by an embedded build-info string the library itself left behind is stronger, and the finding's confidence reflects that rather than flattening both to the same number.

The honest limits

Three caveats, because the alternative is you finding them at the worst moment.

It is a precision problem, not a data problem. The hard part is not having library fingerprints, it is not confusing adjacent versions of the same library, whose shapes are nearly identical, and not admitting a spurious neighbour when two versions are genuinely co-bundled. We spend the engineering exactly here: a version admitted alongside a stronger match has to bring a real fraction of its own uniquely-claimed classes, measured so that spurious neighbour-major matches (around 0.23 unique) fall below genuine distinct co-bundled versions (0.52 and up), with the admission bar set between them. The reference built from a full library can still drift below the class threshold against an app that calls only two of its methods, so an extremely thin inclusion is the case most likely to be missed. We would rather miss that than guess a version we cannot stand behind.

Coverage is a working set. The high-confidence, zero-false-positive fingerprint corpus is a Maven-centric set of the libraries that actually matter in Android apps, on the order of 120 common ones, not every artifact that has ever been published. It grows, but it is honest about being a set rather than the universe.

Native code is a separate track. Bundled .so libraries (a vulnerable OpenSSL, a dated image codec) are a different fingerprinting problem than DEX classes, with its own methods and its own coverage. The dependency picture of an app is DEX libraries plus native ones, and the two are not identified the same way.

Doing it in Rutken

Open the APK and click DEPS on the left rail. Rutken lists the third-party libraries it identified by structure, the versions it recovered, and the known vulnerabilities from the OSV range match, confirmed-vulnerable findings separated from lower-confidence presence matches, alongside the static findings in the developer's own code. You get the dependency risk picture of an app from its binary alone: no source, no build files, no gradle manifest, just the APK you were handed.

Scan your first APK's dependencies free

The dependency analysis runs with no device and no source. Download Rutken, open an APK you own, and see which libraries, and which CVEs, it is carrying, even after R8 did its best to hide them.

Frequently asked questions

Can you find CVEs in an APK without the source? Yes. Rutken identifies bundled library versions by class shape and cross-checks them against OSV affected ranges, so you get confirmed-vulnerable findings from the binary alone, no build manifest required.

Why does hash-based dependency scanning miss libraries in release APKs? R8 shrinks, inlines, and renames the bytecode, so the bundled library shares almost no bytes with the published artifact and an exact hash matches nothing, silently. Structural, shape-based matching survives all three transformations because it reads method signatures and hierarchy, not names or bodies.

How does it tell two close versions apart? By requiring a candidate version to claim distinctive classes that the stronger matches do not already explain, with the admission threshold calibrated between measured spurious and genuine co-bundling rates. Adjacent versions with near-identical shape are the hardest case and where the precision work lives.

Does it produce an SBOM? It produces the core of one: the identified third-party components and recovered versions in the app, plus their confirmed-vulnerable advisories, derived from the binary.

How current is the vulnerability data? The CVE cross-check matches against an OSV-sourced dataset, so newly-disclosed advisories flow in through the data, not a tool release.

What about vulnerable native (.so) libraries? Those are fingerprinted on a separate native track with its own coverage; the full dependency picture is DEX libraries plus native ones.