Apktool decompilation tool use detailed explanation

APKTool is an APK compilation tool provided by GOOGLE . It requires a JAVA runtime environment. JDK1.6 or JDK1.7 is recommended .

If you want to modify the APK file, then it is inevitable to use APKTool . There are many posts in the forum about ROM beautification that require you to modify the APK file yourself , such as modifying framework-res.apk , systemUI.apk, etc.

I believe that many of you want to personally revise it after reading it, but the result is that you can't correct it after encountering various errors, and you don't even know where you are.

One. APKTOOL use environment configuration

1. Install JAVA and set environment variables.

The download and installation are very simple, the key is that you need to set the environment variables yourself after installation to facilitate other programs to use JAVA .

Take WIN7 as an example, right-click the computer on the desktop- > Properties- > Advanced System Settings- > Environment Variables- > Create a new variable in the system variables below, the variable name is JAVA_HOM E , the value is JAVA installation Path, for example mine is H: \ ProgramFiles \ Java \ jdk1.6.0_26

two. APKTool installation

1. Actually this is not about installation, but if you want, you can extract the three files ( aapt.exe , apktool.bat , apktool.jar ) from the downloaded APKTOOL to your Windows installation directory for convenience Use the Dos command .

2. There may be an installed bat file in the APKTOOL that some people download , and there are two other convenient bat files. I do n’t recommend you to use these bat files here, although it is very convenient to use (in fact, I do n’t find it convenient ), But it is not convenient to view if an error occurs.

three. APKTool use

1.decode

This command is used to decompile the apk file, the general usage is

apktool d <file.apk> <dir>

<file.apk> represents the path of the apk file to be decompiled , it is best to write an absolute path, such as C: \ MusicPlayer.apk (Note: Do not bring Chinese in the path)

<dir> represents the storage location of the decompiled file, such as C: \ MusicPlayer

If the given <dir> already exists, you will be prompted after entering the command and it cannot be executed. You need to modify the command and add the -f command

apktool d –f <file.apk> <dir>

This will force overwrite the existing file

2.build

This command is used to compile and modify the file. The general usage is

apktool b <dir>

这里的<dir>就是刚才你反编译时输入的<dir>(如C:\MusicPlayer,输入这行命令后,如果一切正常,你会发现C:\MusicPlayer内多了2文件夹builddist,其中分别存储着编译过程中逐个编译的文件以及最终打包的apk文件。

3.install-framework

该命令用于为APKTool安装特定的framework-res.apk文件,以方便进行反编译一些与ROM相互依赖的APK文件。具体情况请看常见问题



四.常见问题

1.关于安装和管理framework文件

以下大部分其实是翻译自http://code.google.com/p/android-apktool/wiki/FrameworkFiles

一般来说,你在使用apktool进行反编译前不需要做其他的事情,然而由于有的厂商,如HTC三星等,他们定制了framework文件并且在他们的系统应用中使用了这些文件,这时,为了能正常的反编译这些apk文件,你就必须从你的设备中拷贝出framework文件并且安装到apktool中。

举一个例子,比如你想反编译HTCHero这款手机中的HtcContacts.apk,当你尝试反编译的时候,你会得到以下错误信息。


 

  1. $ apktool d HtcContacts.apk 
  2. I: Loading resource table...
  3. I: Decoding resources...
  4. I: Loading resource table from file: /home/brutall/apktool/framework/1.apk
  5. W: Could not decode attr value, using undecoded value instead: ns=android, name=drawable, value=0x02020542
  6. ...
  7. W: Could not decode attr value, using undecoded value instead: ns=android, name=icon, value=0x02020520
  8. Can't find framework resources for package of id: 2. You must install proper framework files, see project website for more info.
复制代码

 

这就是在通知你必须先安装HTC定制的framework文件,事实上在修改一些三星的系统应用时也是如此。

以三星的设备来举例,你需要复制两个framework文件来进行安装,framework-res.apktzframework-res.apk,一般来说,这两个文件在手机中的位置应该是system\framework\

使用以下代码进行安装

apktool if C:\framework-res.apk

apktool if C:\tzframework-res.apk

这里假设2个文件都放在C盘根目录


2.直接用build编译后在dist中找到的apk文件无法使用

其实这个问题我也不是特别理解,目前知道的就是,APK文件虽然本质是个zip文件,但是事实上zip包中的文件是按照两种方式压缩的,即XML文件进行deflate压缩,其他文件不进行压缩(使用store存储),而直接编译得到的APK文件对任何的文件都进行了deflate压缩,因此你会发现编译得到的文件比原文件小好多。

同样的,当你使用build文件夹中的文件替换原apk文件中的资源时,请务必确认是使用store存储还是deflate压缩

3.其他错误

其实在编译过程中会遇到很多其他的问题,大多数是由于删除、修改、添加了资源后,没有对应的修改res\values\public.xml文件而造成的,这里我给大家说下修改的原则:

第一,public.xml文件中的资源不能重复定义。

第二,public.xml文件中的任意两个资源的ID不能一样

第三,public.xml文件中定义的资源必须能找到该文件(如果你删除了一些文件,必须要对应的删除public.xml中的该行)

第四,public.xml文件中尽可能全面(如果你添加了某资源,最好确保在public.xml中也添加)

第五,public.xml文件中的资源的ID尽可能连续(当你为添加的文件添加声明时,赋予的ID尽可能是连续的)

发布了6 篇原创文章 · 获赞 4 · 访问量 1万+

Guess you like

Origin blog.csdn.net/sjc53yy/article/details/10026689
Recommended