保护Android resources文件不被反编译原理分析
2016-02-01 18:53
507 查看
保护Android resources文件不被反编译原理分析
0x00前言
本人新手,文章写的如果有不正确的地方烦请各路大神指点
0x01工具
010 Editor
apktool
aapt
文本编辑器
0x02原理
主要是通过HEX修改resources.arsc DataType数据类型来促使apktool无法直接反编译资源文件,从而保护资源文件。
首先我们需要了解一下appt dump resources的基本格式。
通过aapt dump查看apk的资源
string/hex_test这个值在APP里面不起任何作用,专门用于修改保护资源使用,string值不要使用APP内部调用的资源,如果用正常使用的值修改后会无法正常使用
下面就使用010Editor修改
用010Editor打开resources.arsc
直接搜索
直接修改03为02保存,直接替换resources.arsc到apk中
0x03演示
使用apktool反编译进行测试
直接报错信息如下:
我使用的是最新版本apktool2.0.3版本,关键错误信息:
0x04修复
手动修复这个错误,也就是根据上面的原理进行反推,看一下错误信息:
首先使用aapt dump查看apk的资源
资源:
关键信息:
使用010Editor打开resources.arsc直接搜索
直接将DataType数据类型
测试通过:
0x05结尾
本文只是和各位交流,谢谢。
0x00前言
本人新手,文章写的如果有不正确的地方烦请各路大神指点
0x01工具
010 Editor
apktool
aapt
文本编辑器
0x02原理
主要是通过HEX修改resources.arsc DataType数据类型来促使apktool无法直接反编译资源文件,从而保护资源文件。
首先我们需要了解一下appt dump resources的基本格式。
resource<Resource ID> <Package Name>:<Type>/<Name>: t=<DataType> d=<Data> (s=<Size> r=<Res0>) Resource ID R.java中的资源ID Package Name 资源所在的的包 Type 资源的类型 Name 资源名称 DataType 数据类型,按照以下枚举类型取值 Data 资源的值,根据dataType进行解释 Size 一直为0x0008 Res0 固定为0x00
通过aapt dump查看apk的资源
aapt d --values resources test.apk
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=0x03DataType数据类型
d=0x00000006Data 资源值
s=0x0008 r=0x00Size和Res0
下面就使用010Editor修改
t=0x030x03修改为0x02或0x01都可以,我修改0x02
用010Editor打开resources.arsc
直接搜索
0306000000(为什么这样,因为十六进制搜索需要反过来)
直接修改03为02保存,直接替换resources.arsc到apk中
0x03演示
使用apktool反编译进行测试
apktool d -f test.apk
直接报错信息如下:
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版本,关键错误信息:
Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec: 0x7f000006
0x04修复
手动修复这个错误,也就是根据上面的原理进行反推,看一下错误信息:
Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec: 0x7f000006
首先使用aapt dump查看apk的资源
aapt d --values resources test.apk
资源:
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
直接将DataType数据类型
0x02修改为
0x03修改后保存,直接替换resources.arsc到apk中进行反编译测试
apktool d -f test.apk
测试通过:
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结尾
本文只是和各位交流,谢谢。
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories