android 反编译&防反编译(代码混淆)

作者: yabin小站 | 来源:发表于2016-03-27 23:44 被阅读700次

    一. 反编译工具 (适用于window&ubunt&mac)

    1.apktool :用于反编译资源文件 Apktool官网 apktool下载地址

    Apktool官网查看具体的操作

     apktool d xxx.apk 反编译
     apktool b xxx -o xxx.apk 重新打包
     jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore 签名文件名 -storepass 签名密码 待签名的APK文件名 签名的别名
    

    2.dex2jar :用于将apk的dex反编译为jar dex2jar下载地址
    3.jd-gui :将jar通过jd-gui的方式查看 jd-gui下载地址

    二. 代码混淆,把类名,方法名,属性名混淆.即使反编译后也无法查看具体逻辑

    凡是需要在AndroidManifest.xml中去注册的所有类的类名以及从父类重写的方法名都自动不会被混淆

    # 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
    -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);
    }
    
    -keepclassmembers class * implements android.os.Parcelable {
      public static final android.os.Parcelable$Creator CREATOR;
    }
    
    -keepclassmembers class **.R$* {
        public static <fields>;
    }
    
    # The support library contains references to newer platform versions.
    # Dont 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.**
    
    -dontusemixedcaseclassnames 表示混淆时不使用大小写混合类名。 
    -dontskipnonpubliclibraryclasses 表示不跳过library中的非public的类。 
    -verbose 表示打印混淆的详细信息。 
    -dontoptimize 表示不进行优化,建议使用此选项,因为根据proguard-android-optimize.txt中的描述,优化可能会造成一些潜在风险,不能保证在所有版本的Dalvik上都正常运行。 
    -dontpreverify 表示不进行预校验。这个预校验是作用在Java平台上的,Android平台上不需要这项功能,去掉之后还可以加快混淆速度。 
    -keepattributes *Annotation* 表示对注解中的参数进行保留。
    

    注意

    1. 使用keep关键字后,你会发现代码中所有类的类名都不会被混淆了,因为keep关键字看到class *就认为应该将所有类名进行保留,而不会关心该类中是否含有native方法。当然这样写只会保证类名不会被混淆,类中的成员还是会被混淆的。 
    2. 第三方的仿混淆
    3. jar的混淆
    

    参考

    Android安全攻防战,反编译与混淆技术完全解析(上)
    Android安全攻防战,反编译与混淆技术完全解析(下)
    MAC上反编译android apk---apktool, dex2jar, jd-jui安装使用(含手动签名)

    相关文章

      网友评论

        本文标题:android 反编译&防反编译(代码混淆)

        本文链接:https://www.haomeiwen.com/subject/wedjlttx.html