天天看點

android反編譯原理,保護Android resources檔案不被反編譯原理分析

保護Android resources檔案不被反編譯原理分析

0x00前言

本人新手,文章寫的如果有不正确的地方煩請各路大神指點

0x01工具

010 Editor

apktool

aapt

文本編輯器

0x02原理

主要是通過HEX修改resources.arsc DataType資料類型來促使apktool無法直接反編譯資源檔案,進而保護資源檔案。

首先我們需要了解一下appt dump resources的基本格式。

resource:/: t= d= (s= r=)

Resource ID R.java中的資源ID

Package Name 資源所在的的包

Type 資源的類型

Name 資源名稱

DataType 資料類型,按照以下枚舉類型取值

Data 資源的值,根據dataType進行解釋

Size 一直為0x0008

Res0 固定為0x00

通過aapt dump檢視apk的資源

[Bash shell] 純文字檢視 複制代碼aapt d --values resources test.apk

[AppleScript] 純文字檢視 複制代碼Package Groups (1)

Package Group 0 id=0x7f packageCount=1 name=com.example.myapp

Package 0 id=0x7f name=com.example.myapp

type 1 configCount=4 entryCount=1

spec resource 0x7f020000 com.example.myapp:drawable/ic_launcher: flags=0x40000100

config ldpi-v4:

resource 0x7f020000 com.example.myapp:drawable/ic_launcher: t=0x03 d=0x00000001 (s=0x0008 r=0x00) (PUBLIC)

(string8) "res/drawable-ldpi-v4/ic_launcher.png"

config mdpi-v4:

resource 0x7f020000 com.example.myapp:drawable/ic_launcher: t=0x03 d=0x00000002 (s=0x0008 r=0x00) (PUBLIC)

(string8) "res/drawable-mdpi-v4/ic_launcher.png"

config hdpi-v4:

resource 0x7f020000 com.example.myapp:drawable/ic_launcher: t=0x03 d=0x00000003 (s=0x0008 r=0x00) (PUBLIC)

(string8) "res/drawable-hdpi-v4/ic_launcher.png"

config xhdpi-v4:

resource 0x7f020000 com.example.myapp:drawable/ic_launcher: t=0x03 d=0x00000004 (s=0x0008 r=0x00) (PUBLIC)

(string8) "res/drawable-xhdpi-v4/ic_launcher.png"

type 2 configCount=1 entryCount=1

spec resource 0x7f030000 com.example.myapp:layout/main: flags=0x40000000

config (default):

resource 0x7f030000 com.example.myapp:layout/main: t=0x03 d=0x00000000 (s=0x0008 r=0x00) (PUBLIC)

(string8) "res/layout/main.xml"

type 3 configCount=1 entryCount=2

spec resource 0x7f040000 com.example.myapp:string/app_name: flags=0x40000000

spec resource 0x7f040001 com.example.myapp:string/hex_test: flags=0x40000000

config (default):

resource 0x7f040000 com.example.myapp:string/app_name: t=0x03 d=0x00000005 (s=0x0008 r=0x00) (PUBLIC)

(string8) "myapp"

resource 0x7f040001 com.example.myapp:string/hex_test: t=0x03 d=0x00000006 (s=0x0008 r=0x00) (PUBLIC)

(string8) "hex"

string/hex_test這個值在APP裡面不起任何作用,專門用于修改保護資源使用,string值不要使用APP内部調用的資源,如果用正常使用的值修改後會無法正常使用

resource 0x7f040001 即 string/hex_test 的ID t=0x03 DataType資料類型 d=0x00000006 Data 資源值 s=0x0008 r=0x00 Size和Res0

下面就使用010Editor修改t=0x03 0x03修改為0x02或0x01都可以,我修改0x02

用010Editor打開resources.arsc

直接搜尋0306000000(為什麼這樣,因為十六進制搜尋需要反過來)

android反編譯原理,保護Android resources檔案不被反編譯原理分析

1.png (346.76 KB, 下載下傳次數: 0)

2016-2-1 21:21 上傳

DataType資料類型

直接修改03為02儲存,直接替換resources.arsc到apk中

0x03示範

使用apktool反編譯進行測試

[Bash shell] 純文字檢視 複制代碼apktool d -f test.apk

直接報錯資訊如下:

[JavaScript] 純文字檢視 複制代碼I: Using Apktool 2.0.3 on test.apk

I: Loading resource table...

I: Decoding AndroidManifest.xml with resources...

I: Loading resource table from file: /Users/pwelyn/Library/apktool/framework/1.apk

I: Regular manifest package...

I: Decoding file-resources...

I: Decoding values ** XMLs...

I: Baksmaling classes.dex...

I: Copying assets and libs...

I: Copying unknown files...

I: Copying original files...

0x05結尾

本文隻是和各位交流,謝謝。