android 反編譯 混淆過程中注意事項

來源:互聯網
上載者:User

標籤:android   style   blog   http   java   color   

此文源自組內成員分享的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常見反編譯工具

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.