【Android 安装包优化】资源混淆 ( 资源混淆效果 | APK 构建流程简介 | 资源 ID 组成 )
文章目錄
- 一、資源混淆效果
- 二、APK 構建流程簡介
- 三、資源 ID 組成
- 四、參考資料
一、資源混淆效果
資源混淆 , 將資源名稱與目錄進行混淆 , 提高了反編譯的難度 , 同時也減小了 APK 文件的大小 ;
下面的 APK 安裝文件就是進行資源混淆 , 其中的 r 文件 , 就是混淆后的資源文件 ;
進入 r 文件內部 , 可以看到很多無意義無規則的目錄 , 這是混淆后的資源文件 ;
二、APK 構建流程簡介
APK 構建流程 官方文檔參考 : https://developer.android.google.cn/studio/build
應用模塊 ( Application Module ) 中包含 :
- 源碼文件 ( Source Code )
- 資源文件 ( Resource Files )
- AIDL 文件 ( AIDL Files )
等 , 還有各種引入的依賴庫 ( Dependencies ) , 包括 :
- Android 依賴庫模塊 ( Library Modules )
- Android 依賴庫包 ( AAR Libraries )
- Java 依賴庫 ( JAR Libraries ) ;
應用模塊 和 依賴庫 放在一起進行編譯 , 先編譯成 class 字節碼文件 , 然后使用 dex 工具 , 編譯成 DEX 文件 , 同時也會對 資源文件 ( Resources ) 進行編譯 , 最后打包成 APK 文件 ;
資源文件在打包時會進行編譯 , 將資源文件編譯成二進制文件 , 直接打開資源文件都是二進制亂碼 ;
三、資源 ID 組成
Android 應用編譯時會生成 R 文件 , 在代碼中 , 也使用 R 文件 , 引用相關的資源 ;
每個資源的值 , 存在子 app\build\intermediates\runtime_symbol_list\debug\R.txt 中 , 現在在 build 目錄中不生成 R.java 了 ;
int anim abc_fade_in 0x7f010000 int anim abc_fade_out 0x7f010001 int anim abc_grow_fade_in_from_bottom 0x7f010002 int anim abc_popup_enter 0x7f010003 int anim abc_popup_exit 0x7f010004 int anim abc_shrink_fade_out_from_bottom 0x7f010005 int anim abc_slide_in_bottom 0x7f010006 int anim abc_slide_in_top 0x7f010007 int anim abc_slide_out_bottom 0x7f010008 int anim abc_slide_out_top 0x7f010009 int anim abc_tooltip_enter 0x7f01000a int anim abc_tooltip_exit 0x7f01000b每個資源都對應著 R 文件中的一個 ID , 以 0x7f010000\rm 0x7f0100000x7f010000 為例 , ID 的格式分為三部分 , 7f | 01 | 0000 ,
- 7f\rm 7f7f 表示包 , 一般的程序的包都會被編譯成 7f\rm 7f7f 開頭 ;
- 010101 對應資源類型 , 動畫類型以 7f01 開頭 ;
- 最后 222 字節 , 按照序號從 000 開始排序即可 ;
四、參考資料
參考官方文檔 :
- 縮減、混淆處理和優化應用 : https://developer.android.google.cn/studio/build/shrink-code
- APK 構建流程 : https://developer.android.google.cn/studio/build
參考之前的博客資源 :
- 【Android 安全】DEX 加密 ( ProGuard 混淆 | -keepclassmembers 混淆效果 | -keepclasseswithmembernames 混淆效果 )
- 【Android 安全】DEX 加密 ( Proguard 混淆 | 混淆后的報錯信息 | Proguard 混淆映射文件 mapping.txt )
- 【Android 安全】DEX 加密 ( Proguard 混淆 | 將混淆后的報錯信息轉為原始報錯信息 | retrace.bat 命令執行目錄 | 暴露更少信息 )
- 【Android 安全】DEX 加密 ( Proguard 混淆 | 混淆后的報錯信息 | Proguard 混淆映射文件 mapping.txt )
博客資源 :
-
GitHub 項目源碼 : https://github.com/han1202012/SVG
-
下載地址 :
總結
以上是生活随笔為你收集整理的【Android 安装包优化】资源混淆 ( 资源混淆效果 | APK 构建流程简介 | 资源 ID 组成 )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Android 安装包优化】开启资源压
- 下一篇: 【Android 安装包优化】资源混淆