android反编译原理,保护Android resources文件不被反编译原理分析

本文介绍了如何通过修改Android应用的resources.arsc文件,改变DataType数据类型来防止apktool反编译资源。具体操作包括使用010Editor修改资源数据类型,导致apktool在反编译时出错,然后根据错误信息反推出需要修复的数据类型,最终成功阻止资源被反编译。
摘要由CSDN通过智能技术生成

保护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(为什么这样,因为十六进制搜索需要反过来)

55fd2b2273b5a8b4531f72773c469d6e.gif

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...

Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec: 0x7f000006

at brut.androlib.res.data.ResPackage.getResSpec(ResPackage.java:59)

at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:65)

at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:61)

at brut.androlib.res.data.value.ResReferenceValue.getReferent(ResReferenceValue.java:57)

at brut.androlib.res.data.value.ResReferenceValue.encodeAsResXml(ResReferenceValue.java:47)

at brut.androlib.res.data.value.ResScalarValue.encodeAsResXmlValue(ResScalarValue.java:58)

at brut.androlib.res.data.value.ResScalarValue.serializeToResValuesXml(ResScalarValue.java:75)

at brut.androlib.res.AndrolibResources.generateValuesFile(AndrolibResources.java:502)

at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:252)

at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:136)

at brut.androlib.ApkDecoder.decode(ApkDecoder.java:102)

at brut.apktool.Main.cmdDecode(Main.java:165)

at brut.apktool.Main.main(Main.java:81)

我使用的是最新版本apktool2.0.3版本,关键错误信息:

[AppleScript] 纯文本查看 复制代码Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec: 0x7f000006

0x04修复

手动修复这个错误,也就是根据上面的原理进行反推,看一下错误信息:

[AppleScript] 纯文本查看 复制代码Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec: 0x7f000006

首先使用aapt dump查看apk的资源

[Bash shell] 纯文本查看 复制代码aapt d --values resources test.apk

资源:

[JavaScript] 纯文本查看 复制代码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=0x02 d=0x00000006 (s=0x0008 r=0x00) (PUBLIC)

(attribute) 0x00000006

关键信息:(attribute) 0x00000006 报错 resource spec: 0x7f000006

使用010Editor打开resources.arsc直接搜索06000000

55fd2b2273b5a8b4531f72773c469d6e.gif

2.jpg (230.44 KB, 下载次数: 1)

2016-2-1 21:21 上传

图片描述

直接将DataType数据类型0x02修改为0x03 修改后保存,直接替换resources.arsc到apk中进行反编译测试

[Bash shell] 纯文本查看 复制代码apktool d -f test.apk

测试通过:

[Bash shell] 纯文本查看 复制代码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结尾

本文只是和各位交流,谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值