Considerations during Android anti-compilation obfuscation

Source: Internet
Author: User
Tags xml attribute

This article originates from the PPT shared by the members of the group, and the other Members ' documents are not disclosed because they are not authorized.

This article command is a Windows 7 environment, if not specifically noted.

This article only touches on the approximate knowledge point, does not involve the concrete detail, needs to pay attention.



Can decompile resource file (XML, point Nine) and code Smali code

Use command: Apktool d xxx.apk Output_filepath


Anti-compile Dex file (extract apk obtained classes.dex) as Jar

Use command: Dex2jar xxx.dex


View the jar file code

Using the method, open the jar file directly to

AXMLPrinter2 a single XML file

Java-jar Axmlprinter2.jar Xxx.xml >output.xml

The Counter-compilation response

• Code obfuscation

• Increase the code that will cause the anti-compiler exception

• Key code uses NDK

• Software Packers (e.g. UPX)

• Test simulator, debugger against dynamic commissioning

• Check signature, verify protection (classes.dex hash value) to prevent recompilation


• Confusion principle

The application keeps the statement meaning unchanged from program p to P '.

Obfuscation refers to the semantic transformation of the application to be published, so that the transformed program and the original program are functionally identical or similar, but more difficult to be attacked by reverse engineering.

• Common methods

Code shape Confusion (renaming)

Control command Confusion (change the program's judging conditions or add controllable conditions and other adjustments to the program's structure and process)

Internal data obfuscation (transformations of data structures, splitting and merging of variables, data structure transformations, dynamic generation of static data, class inheritance conversions)

Prevent confusion (add code that will be faulted for some specific anti-compilation decompile)

• Evaluation indicators

Intensity, obfuscation algorithm adds complexity to the program

Resilient, confusing program anti-machine attack capability

Overhead, additional overhead from code conversion


• Code Shape Confusion

Sdkpath\tools\proguard \proguard-android.txt

• Project Proguard-project.txt

    # This was a configuration file for Proguard.#
-dontusemixedcaseclassnames #包明不混合大小写-dontskipnonpubliclibraryclasses #不去忽略非公共的库类-verbose
# optimization is turned off by default. Dex does not like code run# through the Proguard optimize and preverify steps (and performs some# of these optimizations on its own).-dontoptimize #优化-dontpreverify #预校验# Note If you want to enable optimization, you cannot just# include optimization flags in your own project configuration file;# instead you'll need to the# "Proguard-android-optimize.txt" file instead of this one from your# file.
-keepattributes *annotation* #保护注解-keep public class #保护指定的类-keep public class
# for native methods, see Http://不混淆jni方法-keepclasseswithmembernames class * {native <methods>;}
# Keep setters in animations can still work.# See Http:// public class * extends Android.view.View {void set* (* * *);* * * get* ();}
# We want to keep methods in Activity that could is used in the XML attribute OnClick-keepclassmembers class * extends {Public void * (Android.view.View);}
# For enumeration classes, see Http:// enum * {Public static **[] values ();Public Static * * VALUEOF (java.lang.String);}#不混淆Parcelable的子类 to prevent android.os.BadParcelableException-keep class * Implements Android.os.Parcelable {Public static Final Android.os.parcelable$creator *;}#不混淆资源类-keepclassmembers class * *. r$* {Public static <fields>;}
# The Support library contains references to newer platform versions.# Don ' t warn about those in case this app is linking against an older# Platform version. We know about them, and they is safe.-dontwarn**

Schematic, compression------------pre-check for obfuscation---4 steps, default optimizations and pre-check are not open

• Confusion Considerations

Avoid confusion generics (Fastjson)

-keepattributes Signature

Exclude reflection, serialization-related classes

Exclude the native method, and the class that Androidmanifest.xml mentions

Ignore warnings



Keep a full package

-keep class com.sogou.appmall.**{*;}

• Debug and Bug tracking

The internal structure of all classes within the 1.dump.txt APK package

Mapping before and after 2.mapping.txt confusion

3.seeds.txt classes and members that are not confused

4.usage.txt listing the code removed from the APK

• Restore Logs

retrace.bat| [-verbose] mapping.txt [<stacktrace_file>]

For example: Retrace.bat-verbose mapping.txt obfuscated_trace.txt

If you need to output a log with a line number, you need to add

-renamesourcefileattribute sourcefile

-keepattributes sourcefile,linenumbertable #输出错误信息行号




3.proguard Brief Grammar Handbook Common anti-compilation tools

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.