此文源自组内成员分享的PPT,其他成员的文档由于没有得到授权,暂不公开。

本文命令如果没有特殊注明,均为windows 7环境。

本文只涉及大概的知识点,不涉及具体的细节,需要注意。

反编译

  apktool

    可反编译资源文件(xml,点九图)以及代码为smali代码

    使用命令:apktool d xxx.apk output_filepath

  dex2jar

    反编译dex文件(解压apk获得的classes.dex)为jar

    使用命令:dex2jar xxx.dex

  jd-gui

    查看jar文件代码

    使用方法,直接打开jar文件即可

  AXMLPrinter2 单个xml文件

    java -jar AXMLPrinter2.jar xxx.xml >output.xml

反编译的应对

  •代码混淆

  •增加会引起反编译器异常的代码

  •关键代码使用NDK

  •软件加壳(如UPX)

  •检测模拟器、调试器对抗动态调试

  •检查签名、检验保护(classes.dex hash值)防止重编译

混淆

  •混淆原理

    在应用程序保持语句含义不变的前提下从程序P转换到了P'。

    混淆技术是指对拟发布的应用程序进行保持语义的变换,使得变换后的程序和原来的程序在功能上相同或相近,但是更难以被逆向工程所攻击。

  •常见方法

    代码外形混淆(改名)

    控制命令混淆(改变程序判断条件或者增加可控制条件以及其他对程序的结构以及流程进行调整)

    内部数据混淆(数据结构的变换,变量的分裂、合并,数据结构变换,静态数据动态生成,类继承转换)

    预防混淆(增加某些特定反编译反编译时会出错的代码)

  •评价指标

    强度,混淆算法对程序增加的复杂度

    弹性,混淆后程序的抗机器攻击能力

    开销,由代码转换带来的额外开销

Proguard

  •代码外形混淆

  •sdkpath\tools\proguard \proguard-android.txt

  •项目proguard-project.txt

    

 # This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html -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 that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file. -keepattributes *Annotation* #保护注解
-keep public class com.google.vending.licensing.ILicensingService #保护指定的类
-keep public class com.android.vending.licensing.ILicensingService # For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
#不混淆jni方法
-keepclasseswithmembernames class * {
native <methods>;
} # keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
} # We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
} # For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#不混淆Parcelable的子类,防止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 are safe.
-dontwarn android.support.**

  原理图,经过压缩->优化->混淆->预校验4个步骤,默认优化以及预校验是没有打开的

  •混淆注意事项

    避免混淆泛型(fastjson)

      -keepattributes Signature

    排除反射、序列化相关的类

    排除native方法,以及AndroidManifest.xml提到的类

    忽略警告

      -ignorewarnings

      -dontwarn android.support.**

    保留一个完整的包

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

  •调试与bug追踪

    1.dump.txt apk包内所有class的内部结构

    2.mapping.txt 混淆前后的映射

    3.seeds.txt 未混淆的类和成员

    4.usage.txt 列出从apk中删除的代码

  •还原日志

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

    比如:retrace.bat -verbose mapping.txt obfuscated_trace.txt

    如果需要输出的日志有行号,需要添加

      -renamesourcefileattribute SourceFile

      -keepattributes SourceFile,LineNumberTable #输出错误信息行号

更多

  •1. http://proguard.sourceforge.net/

  •2.http://developer.android.com/tools/help/proguard.html

  •3.Proguard简要语法手册

  •4.Android常见反编译工具

【Android】Android程序保护与破解浅析的更多相关文章

  1. 微信5.0 Android版飞机大战破解无敌模式手记

    微信5.0 Android版飞机大战破解无敌模式手记 转载: http://www.blogjava.net/zh-weir/archive/2013/08/14/402821.html 微信5.0 ...

  2. Android 4.0 ICS SystemUI浅析——StatusBar结构分析

    Android 4.0 ICS SystemUI浅析——StatusBar结构分析 分类: Android2012-06-30 14:45 23687人阅读 评论(8) 收藏 举报 androidsi ...

  3. Android开发学习之对话框浅析

    对话框式程序运行中弹出的窗口.Android系统中有四种默认的对话框:警告对话框AlertDialog.进度对话框ProgressDialog.日期选择对话框DatePickerDialog以及时间选 ...

  4. Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder

    Stack Overflow 排错翻译  - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder 转自:ht ...

  5. [Android]Android端ORM框架——RapidORM(v2.1)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/6020412.html [Android]Android端ORM ...

  6. [Android]Android端ORM框架——RapidORM(v2.0)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5626716.html [Android]Android端ORM ...

  7. Android android:gravity属性介绍及效果图

    转自: http://blog.csdn.net/aminfo/article/details/7784229 Android:gravity的属性官方说明如下: public static fina ...

  8. [转][Android][Android Studio] *.jar 与 *.aar 的生成与*.aar导入项目方法

     转自:http://blog.csdn.net/qiujuer/article/details/39754517?utm_source=tuicool [Android][Android Studi ...

  9. 图解Android - Android GUI 系统 (1) - 概论

    Android的GUI系统是Android最重要也最复杂的系统之一.它包括以下部分: 窗口和图形系统 - Window and View Manager System. 显示合成系统 - Surfac ...

随机推荐

  1. php 一维数组排序,保留key值

    function sort_with_keyName($arr,$orderby='desc'){ //在内存的另一处 $a 复制内容与 $arr 一样的数组 foreach($arr as $key ...

  2. H5 App设计者需要注意的21条禁忌

    我们通常在做H5 APP设计的过程中,遇到很多看似很小,且很容易被忽略的问题,正是这些小问题,一次次的撩拨用户的耐心,让用户对你的APP心生怨念.现在WeX5君呕血为大家整理出H5 APP设计的21条 ...

  3. iOS之内存管理浅谈

    1.何为ARC ARC是automatic reference counting自动引用计数,在程序编译时自动加入retain/release.在对象被创建时retain count+1,在对象被re ...

  4. python偏函数(functool.partail)

    functool.partail 方法可以为一个函数生成偏函数 import functools def f(a,b,c,d): print a,b,c,d a='a' b='b' f1=functo ...

  5. 使用memcache(thinkphp框架学习)

    $memcache = new Memcache; $memcache->connect("localhost",11211); $memcache->set('sxt ...

  6. 闲谈前端编码解码、C#编码解码。

    最近做项目,出现中文乱码的问题,特地研究一下. GB2312,指的是中文 UTF8,指的是国标,包含中文.英文. 但是通过JQuery.ajax的Get.Post,如果直接传递中文或者特殊字符的特使字 ...

  7. Python创建list

    Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可以用一个list表示: >>> ['Mic ...

  8. 安装ubuntu12.04LTS卡住以及花屏问题

    昨天在XP下用grub4dos安装了ubuntu12.04LTS,总体上还算比较顺利,中途有碰到两个异常问题,解决了记录一下. 问题一:安装过程中读取ISO镜像文件时,卡在"checking ...

  9. 在asp.net中如何自己编写highcharts图表导出到自己的服务器上来

    1.准备工作:网上下载highcharts导出的关键dll.      1).Svg.dll:因为highcharts的格式其实就是一个xml,采用svg的方式画图:      2).itextsha ...

  10. C语言预处理运算符

    转自C语言预处理运算符 预处理还需要运算符?有没有搞错? ^_^, 没有搞错,预处理是有运算符,而且还不止一个: #(单井号)    -- 字符串化运算符. ##(双井号 )-- 连接运算符 #@   ...