Skip to content

App hardening techniques

A look at mobile app hardening techniques such as control flow flattening, string encryption and native library protection, and how they are used to defeat reverse engineering.

Updated

Building resistance into the application binary

App hardening transforms a compiled app so that analyzing, reverse engineering or modifying it takes far more time and skill. The goal is to make an attack too costly to be worth it, not to make it impossible.

Mobile application hardening is the technical process of applying structural and cryptographic transformations to compiled code. The goal is to make the application so mathematically complex and so opaque that analyzing, reverse-engineering or tampering with it becomes computationally exhausting and economically unviable for an attacker.

Basic minification tools (like ProGuard or R8) just rename variables to save space. Real app hardening combines several techniques that change the structure of the application without changing what it does when it runs.

Below are the core app hardening techniques that enterprise protection platforms like nultr use to secure Android APKs and AABs.

1. Control-flow flattening

Control-flow flattening is an obfuscation technique that hides the readable order of an app's decisions, so decompiled code no longer shows its logic plainly. Its main effect is to slow down anyone trying to understand or patch how the app decides things.

Of all app hardening techniques, control-flow flattening is the most disruptive to an attacker's workflow.

When developers write code, they use logical structures like if/else statements, switch cases and for loops. Decompilers (like JADX) are very good at recognizing these structures and rebuilding them into readable source code. An attacker reads this flow to understand how the app makes decisions (e.g., If password is correct -> grant access; Else -> show error).

How it works:

Control-flow flattening removes this linear predictability. The hardening engine breaks the basic blocks of your code apart and puts them all inside one large, artificially generated switch statement, which itself sits inside an infinite loop.

A complex, obfuscated state variable now controls the execution order. The code still runs correctly on the CPU, but once it is decompiled, the logical hierarchy is gone. The attacker sees a "spaghetti" maze of jump instructions that makes it nearly impossible to trace the logical path of a function.

2. String and asset encryption

String and asset encryption keeps readable text such as API addresses, keys and messages out of the shipped file. Without it, those strings act as signposts that lead an attacker straight to sensitive code.

Strings are the biggest vulnerability in an unprotected application. They work as signposts for attackers. An attacker looking for your payment gateway API just searches the decompiled code for "https://api.stripe.com" or "auth_token".

How it works:

The hardening engine finds all plaintext strings in the bytecode and encrypts them, usually with AES or custom cryptographic algorithms. Encrypted byte arrays take the place of the plaintext strings in the code.

The engine also injects heavily obfuscated decryption routines. The application decrypts each string in device memory only at the exact millisecond the processor needs it, then clears it right away. Static analysis tools see nothing.

3. Class and method hiding (reflection)

Class and method hiding removes the obvious links between parts of the code, so a decompiler cannot easily map how the app is built. The app's overall architecture becomes much harder to trace from the shipped file.

Applications are built on relationships: Class A calls Method B in Class C. Decompilers map these static cross-references perfectly, which lets attackers understand the application's entire architecture.

How it works:

Hardening can use the Java Reflection API to hide these relationships. Instead of a direct, static method call, the hardening engine rewrites the code to look up and invoke the method at runtime using encrypted strings.

Because the link between the classes is no longer hardcoded in the binary, automated reverse engineering tools cannot map the application tree, and the attacker has to guess by hand how the components interact.

4. Dummy code insertion (dead code)

Dummy code insertion adds code that runs but changes nothing, so an attacker spends time on paths that do not matter. It raises the effort of analysis rather than hiding any single secret.

Attackers assume that every line of code they analyze has a specific purpose.

How it works:

Hardening engines inject large amounts of "dead code", or dummy instructions, directly into the application's real methods. This is mathematically valid code that runs, changes variables and performs calculations, yet has no effect at all on the application's final state or output.

This makes the code exponentially more complex. An attacker might spend hours on a complicated cryptographic function only to find that the whole block is a decoy built purely to waste their time.

5. Native library hardening (C/C++)

Apps that keep sensitive logic in native C or C++ libraries need hardening that covers that native code too, because Java and Kotlin obfuscators do not reach it. Games and fintech apps often fall into this group.

Many high-performance applications (such as games built in Unity/Unreal, or complex fintech apps) compile their most sensitive logic into native C/C++ shared libraries (.so files) instead of Java/Kotlin.

How it works:

Basic Java obfuscators cannot touch native code. Enterprise app hardening platforms need LLVM-based obfuscation that works directly on the native compiler toolchain. Techniques include:

Symbol stripping: removing function names and debugging symbols from the native binary.

Instruction substitution: replacing standard CPU instructions with more complex, equivalent instruction sequences that confuse decompilers (like IDA Pro or Ghidra).

Native string encryption: encrypting strings stored in the .rodata sections of the ELF binary.

6. Environmental telemetry (RASP injection)

The last hardening layer adds runtime application self-protection (RASP), so the app can tell when it runs under a debugger, a hooking tool or on a modified device. Together with obfuscation, this lets the app respond while it runs instead of relying on static defense alone.

Hardening covers self-defense as well as obfuscation. The final stage of app hardening injects Runtime Application Self-Protection (RASP) capabilities into the application.

How it works:

The hardening engine weaves environmental sensors directly into the obfuscated code. These sensors check for debuggers, hooking frameworks (like Frida) and compromised operating systems (like Magisk). With structural obfuscation and runtime telemetry working together, the hardened app is protected both on disk and in memory.

Hardening has to be automated

Applying hardening by hand does not scale across frequent releases, so it belongs in the build pipeline. nultr protects the finished build after it is compiled, with no source code changes, and can run from CI/CD.

Applying these techniques by hand is impossible at scale, so modern DevSecOps needs app hardening to be automated.

Platforms like nultr build these hardening techniques directly into the CI/CD pipeline. The pipeline outputs a standard binary, and nultr automatically applies the control-flow flattening, encryption and RASP injections, then delivers a fully armored application ready for release.

Protect your next release

Register your app, submit a build, and ship it protected.