最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android應(yīng)用開(kāi)發(fā)之代碼混淆

 更新時(shí)間:2014年07月23日 11:22:20   投稿:hebedich  
Android項(xiàng)目中的混淆很easy,之所以寫(xiě)這篇總結(jié)是由于近期發(fā)現(xiàn)公司的代碼居然沒(méi)有混淆,反編譯后代碼隨手可得。很震驚。

混淆器(ProGuard)

混淆器通過(guò)刪除從未用過(guò)的代碼和使用晦澀名字重命名類(lèi)、字段和方法,對(duì)代碼進(jìn)行壓縮,優(yōu)化和混淆。結(jié)果是一個(gè)比較小的.apk文件,該文件比較難進(jìn)行逆向project。因此,當(dāng)你的應(yīng)用程序?qū)Π踩舾校ㄒ蟾撸?,比如?dāng)你授權(quán)應(yīng)用程序的時(shí)候,混淆器是一種重要的保護(hù)手段。   

混淆器被集成在android 構(gòu)建系統(tǒng)中,所以你不必手動(dòng)調(diào)用它。同一時(shí)候混淆器僅在公布模式下進(jìn)行構(gòu)建應(yīng)用程序的時(shí)候才會(huì)執(zhí)行起來(lái),所以在調(diào)試模式下構(gòu)建程序時(shí),你不必處理混淆代碼。讓混淆器執(zhí)行起來(lái)是可選擇的,可是推薦選上。

1. 改動(dòng)project.properties

  # This file is automatically generated by Android Tools.
  # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
  #
  # This file must be checked in Version Control Systems.
  #
  # To customize properties used by the Ant build system edit
  # "ant.properties", and override values to adapt the script to your
  # project structure.
  #
  # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
  #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

  # Project target.
  target=android-19

    將proguard.config前面的凝視去掉

2. 改動(dòng)proguard-project.txt

  # To enable ProGuard in your project, edit project.properties
  # to define the proguard.config property as described in that file.
  #
  # Add project specific ProGuard rules here.
  # By default, the flags in this file are appended to flags specified
  # in ${sdk.dir}/tools/proguard/proguard-android.txt
  # You can edit the include path and order by changing the ProGuard
  # include property in project.properties.
  #
  # For more details, see
  #  http://developer.android.com/guide/developing/tools/proguard.html

  # Add any project specific keep options here:

  # If your project uses WebView with JS, uncomment the following
  # and specify the fully qualified class name to the JavaScript interface
  # class:
  #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  #  public *;
  #}

    假設(shè)在程序中使用了第三方的`jar`包,在混淆后導(dǎo)致出錯(cuò),這時(shí)我們須要在proguard-project.txt中去進(jìn)行對(duì)應(yīng)的配置,來(lái)讓其在混淆時(shí)不要混淆對(duì)應(yīng)的jar包。對(duì)改配置文件里的相關(guān)配置解釋例如以下:

```java
  -keep public class * extends android.app.Activity  【不進(jìn)行混淆類(lèi)名的類(lèi),保持其原類(lèi)名和包名】

  -keep public abstract interface com.asqw.android.Listener{
  public protected <methods>; 【全部public protected的方法名不進(jìn)行混淆】
  }
  -keep public class com.asqw.android{
  public void Start(java.lang.String); 【對(duì)該方法不進(jìn)行混淆】
  }
  -keepclasseswithmembernames class * { 【對(duì)全部類(lèi)的native方法名不進(jìn)行混淆】
  native <methods>;
  }
  -keepclasseswithmembers class * { 【對(duì)全部類(lèi)的指定方法的方法名不進(jìn)行混淆】
  public <init>(android.content.Context, android.util.AttributeSet);
  }
  -keepclassmembers class * extends android.app.Activity {【對(duì)全部類(lèi)的指定方法的方法名不進(jìn)行混淆】
  public void *(android.view.View);
  }
  -keepclassmembers enum * {【對(duì)枚舉類(lèi)型enum的全部類(lèi)的下面指定方法的方法名不進(jìn)行混淆】
  public static **[] values();
  public static ** valueOf(java.lang.String);
  }
  -keep class * implements android.os.Parcelable {【對(duì)實(shí)現(xiàn)了Parcelable接口的全部類(lèi)的類(lèi)名不進(jìn)行混淆,對(duì)其成員變量為Parcelable$Creator類(lèi)型的成員變量的變量名不進(jìn)行混淆】
  public static final android.os.Parcelable$Creator *;
  }
  -keepclasseswithmembers class org.jboss.netty.util.internal.LinkedTransferQueue {【對(duì)指定類(lèi)的指定變量的變量名不進(jìn)行混淆】
    volatile transient org.jboss.netty.util.internal.LinkedTransferQueue$Node head;
    volatile transient org.jboss.netty.util.internal.LinkedTransferQueue$Node tail;
    volatile transient int sweepVotes;

  }
  -keep public class com.unionpay.** {*; }【對(duì)com.unionpay包下全部的類(lèi)都不進(jìn)行混淆,即不混淆類(lèi)名,也不混淆方法名和變量名】
```    

經(jīng)過(guò)上面這兩部之后反編譯后就能混淆了,可是四大組件還在,為什么四大組件還在呢,由于四大組件是在清單文件里進(jìn)行配置的,假設(shè)混淆后就不能依據(jù)清單文件的配置去尋找了。    

假設(shè)對(duì)于一些自己的代碼中要想提供出來(lái)讓別人通過(guò)反射調(diào)用的方法時(shí),我們不想讓部分代碼被混淆,或者是我們使用別人提供的第三方j(luò)ar包,由于第三方的jar包一般都是已經(jīng)混淆過(guò)的,我們要是再混淆就會(huì)報(bào)錯(cuò)了,所以我們要保證這些內(nèi)容不用混淆,這里我們僅僅需改動(dòng)這個(gè)文件,然后加上后面的一句話(huà),他就不會(huì)混淆我們給出的內(nèi)容   

-keepattributes *Annotation*     
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgent
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
-keep public class com.android.vending.licensing.ILicensingService
-keep class com.itheima.mobilesafe.engine.AppInfoProvider
-keep class net.youmi.android.** {
*;
}

相關(guān)文章

最新評(píng)論

青阳县| 永宁县| 富裕县| 博乐市| 米泉市| 太仆寺旗| 吴川市| 宕昌县| 江西省| 龙门县| 邮箱| 巴里| 临漳县| 阳曲县| 四子王旗| 南乐县| 安远县| 鄂伦春自治旗| 长兴县| 枝江市| 鲁甸县| 大名县| 彝良县| 万安县| 林西县| 永胜县| 浏阳市| 虹口区| 昂仁县| 高密市| 棋牌| 海丰县| 南康市| 大荔县| 三原县| 台安县| 东安县| 秦皇岛市| 隆安县| 南宫市| 新乡市|