现在,许多Android手机的ROM包在生成过程中都启用优化,把jar文件抽空,生成odex/oat和vdex文件,以在运行时省掉编译时间。如果想对这些jar进行修改,就要修改它们所对应的odex或者oat文件。本文以/system/framework/oat/arm64/am.odex为例,讲解它的反编译和回编译过程
本文用到的工具:baksmali.jar和smali.jar
下载地址:
https://bitbucket.org/JesusFreke/smali/downloads
将odex/oat反编译
在执行反编译前,先将odex/oat和它的依赖复制到同一目录下。如果在反编译odex/oat的时候,没有找到依赖,就会报类似于下面的错误:
Exception in thread "main" org.jf.dexlib2.DexFileFactory$DexFileNotFoundException: Could not locate the embedded dex file /system/framework/am.jar. Is the vdex file missing?
at org.jf.dexlib2.dexbacked.OatFile$OatDexEntry.getDexFile(OatFile.java:586)
at org.jf.dexlib2.dexbacked.OatFile$OatDexEntry.getDexFile(OatFile.java:567)
at org.jf.baksmali.DexInputCommand.loadDexFile(DexInputCommand.java:158)
at org.jf.baksmali.DisassembleCommand.run(DisassembleComman