odex & disassemble APK
今天邮件列表中讨论了一个东西,虽然没有看懂,但还是记录下
参考:http://passport.cnblogs.com/login.aspx?ReturnUrl=http%3a%2f%2fwww.cnblogs.com%2f
For the more geeky amongst us, Android OS uses a Java-based virtual machine for running applications, called the Dalvik Virtual Machine. A deodexed, or .dex file contains the cache used by this virtual machine (referred to as Dalvik-cache) for a program, and it is stored inside the APK. An .odex file, on the other hand, is an optimized version of this same .dex file that is stored next to the APK as opposed to inside it. Android applies this technique by default to all the system applications.
Now, when an Android-based system is booting, the davlik cache for the Davlik VM is built using these.odex files, allowing the OS to learn in advance what applications will be loaded, and thus speeds up the booting process.
By deodexing these APKs, a developer actually puts the .odex files back inside their respective APK packages. Since all code is now contained within the APK itself, it becomes possible to modify any application package without conflicting with the operating system’s execution environment.
"Optimizing" a DEX file speeds up its execution but also ties it to the hardware platform on which the optimization was performed. ODEX optimization relies on unsafe bytecode instructions. Unsafe instructions are much faster to execute, on the other hand, malicious use of these instructions can crash the virtual machine.
ADVANTAGES & DISADVANTAGES
The advantage of deodexing is in modification possibilities. This is most widely used in custom ROMs and themes. A developer building a custom ROM would almost always choose to deodex the ROM package first, since that would not only allow him to modify various APKs, but also leave room for post-install theming.
On the other hand, since the .odex files were supposed to quickly build the dalvik cache, removing them would mean longer initial boot times. However, this is true only for the first ever boot after deodexing, since the cache would still get built over time as applications are used. Longer boot times may only be seen again if the dalvik cache is wiped for some reason.
odex在android上的使能,是在device目录里的BoadConfig.mk里定义如下宏即可:
WITH_DEXPREOPT := true
==============================
参考:http://www.kanxue.com/android/decompilers.htm
引述出一个问题:如何修改APK?
思路:APK:java + xml + resource.
java : class : dex; xml + resouce : xml + resource
1. 获取jar文件
http://code.google.com/p/dex2jar/downloads/list
./dex2jar.sh xxx.apk
2.解压jar文件获得class文件,而后再获得java文件:
方法一:用jad或DJ Java Decompiler反编译工具将.class文件反编译成.java文件
方法二:
./jd-gui xxx_dex2jar.jar
3.获得xml文件
http://code.google.com/p/android-apktool/downloads/list
Usage: apktool [-q|--quiet OR -v|--verbose] COMMAND [...] COMMANDs are: d[ecode] [OPTS] <file.apk> [<dir>] b[uild] [OPTS] [<app_path>] [<out_file>] ./apktool d xxx.apk src/ Deassemble the xxx.apk to src/ Change the smali code. ./apktool b src/ _xxx.apk Rebuild the _xxx.apk with src/
4. using java + xml + resouce to rebuild a apk.
5. 有时可能因为某些检查机制不能运行重新生成的apk(本人并不会开发apk,但是有时需要从apk分析一些东西),此时
Certificate error when installing the rebuild APK; Change the return value of collectCertificates() in frameworks/base/core/java/android/content/pm/PackageParser.java; Rebuild framework/base and install the APK;
注意:
- 未实践
- 以上资源已下载到本地: 返回上一级 | 全部文件 > software > android_ide > disassemble (823)