Skip to content

v2.0.0 - Kotlin rewrite

Latest

Choose a tag to compare

@CalebFenton CalebFenton released this 08 Nov 17:33
· 1 commit to master since this release
d0645c7

Simplify 2.0 is a rewrite of all three tools in Kotlin: the virtual machine (smalivm), the deobfuscator (simplify) and the debugger (sdbg). The command line works the same way, but the analysis, its limits and the smalivm API are new, so results differ from 1.x.

Highlights

  • Android 16 framework. smalivm executes the framework Smali captured from the API 36 (Android 16) boot classpath. The API 25 corpus from 1.x is no longer packaged.
  • Every path, with unknown inputs. smalivm explores every path of a method and keeps every possible register and class value. A branch on an unknown value takes both arms.
  • Rewrites need a complete analysis. Simplify rewrites a method only when its analysis finished. A method that hits a limit is reported as skipped and left unchanged, instead of being rewritten from partial evidence.
  • Host calls are authorized and checked. A framework method runs on the host JVM only when the reflection policy (safe_classes.cfg, safe_methods.cfg, unsafe_methods.cfg) allows it. Its effect on guest state is measured by comparing the objects it can reach before and after the call; a call whose effect is unknown is kept.
  • Reflection. Method.invoke of an application method runs as a guest call with ART's reflection rules, and unreflection turns it into a direct call when the target has no effect. Class.forName with no effect becomes const-class.
  • Strings. Constant propagation turns a computed String into const-string unless the method compares or locks on that object.
  • Dead code. Dead code removal deletes allocations nothing observes, with their constructors and calls, and calls that have no effect.
  • Memory. A method whose analysis would fill the JVM heap is skipped with MEMORY_LIMIT instead of ending the run with OutOfMemoryError. Give the JVM more heap with -Xmx to analyze it.
  • Documented semantics. docs/DALVIK-SEMANTICS.md states where each execution rule comes from (Dalvik spec, ART source, device measurement or engine choice). Many rules are checked against ART by device fixtures.

The bundled example app shows the result: its encrypted strings, reflection and string building reduce to System.out.println("magic answer = 42"), in under a minute.

Breaking changes

  • Building and running need JDK 21 or later.
  • The smalivm API is new (VmServices, ExecutionSession, ExecutionGraph, TrustedGraphView). Code that embeds smalivm 1.x must be rewritten; demoapp shows how to embed 2.0.
  • An APK or archive with more than one DEX file (classes2.dex) is rejected.
  • The exit status is 1 when the input is rejected, a method fails to execute, or an optimizer edit is rejected. --ignore-errors skips failed methods and exits 0. Skipped methods do not change the exit status.

Downloads

  • simplify-2.0.0.jar: the deobfuscator. java -jar simplify-2.0.0.jar --help
  • sdbg-2.0.0.jar: the Smali debugger.
  • smalivm-2.0.0.jar: smalivm with its runtime dependencies, for embedding.

APK output replaces classes.dex and must be signed again before installation.

Known issues

  • In the example app, MainActivity.<init> and onCreate are skipped: exploring the framework's Activity.onCreate reaches the method limit, or MEMORY_LIMIT on a small heap.
  • invoke-polymorphic, invoke-custom, const-method-handle and const-method-type are not supported. A path through them ends the analysis as partial, so the method is skipped.
  • Constructor.newInstance of an application constructor is not run as a guest call.
  • For contributors: the pinned ART image that tools/art-runner uses to record device fixtures can no longer be rebuilt, because Alpine edge/testing no longer publishes it.