android-apktool工具在Windows平台使用

来源:互联网 发布:js中如何格式化日期 编辑:程序博客网 时间:2024/04/30 18:09

http://blog.csdn.net/fancsxx/article/details/7022808

android-apktool工具在Windows平台使用


官方网站地址:http://code.google.com/p/android-apktool/

安装过程

1.下载apktool1.4.1.tar.bz2和apktool-install-windows-r04-brut1.tar.bz2
2.把两个文件都解压放在同一个目录,共三个文件
aapt.exe
apktool.bat
apktool.jar用于解包,apktool.jar和aapt.exe联合用于打包。
3.如果你经常使用,建议你把这三个文件直接copy到windows目录下面,这样在任何地方都可以直接使用了;

apktool的使用方法:
Apktool v1.4.1 - a tool for reengineering Android apk files
Copyright 2010 Ryszard Wi?niewski <brut.alll@gmail.com>
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

Usage: apktool [-v|--verbose] COMMAND [...]


COMMANDs are:


    d[ecode] [OPTS] <file.apk> [<dir>]
        Decode <file.apk> to <dir>.


        OPTS:


        -s, --no-src
            Do not decode sources.
        -r, --no-res
            Do not decode resources.
        -d, --debug
Decode in debug mode. Check project page for more info.
        -f, --force
            Force delete destination directory.
        -t <tag>, --frame-tag <tag>
            Try to use framework files tagged by <tag>.
        --keep-broken-res
            Use if there was an error and some resources were dropped, e.g.
            "Invalid config flags detected. Dropping resources", but you
            want to decode them anyway, even with errors. You will have to
            fix them manually before building.
    b[uild] [OPTS] [<app_path>] [<out_file>]
        Build an apk from already decoded application located in <app_path>


        It will automatically detect, whether files was changed and perform
        needed steps only.


        If you omit <app_path> then current directory will be used.
        If you omit <out_file> then <app_path>/dist/<name_of_original.apk>
        will be used.


        OPTS:


        -f, --force-all
            Skip changes detection and build all files.
        -d, --debug
            Build in debug mode. Check project page for more info.


    if|install-framework <framework.apk> [<tag>]
        Install framework file to your system.


For additional info, see: http://code.google.com/p/android-apktool/

反编译游戏APK文件
C:\Users\7>apktool d d:\sanguo.apk d:\sanguo    (apktool d 要反编译的apk 输出文件夹)
I: Baksmaling...
I: Loading resource table...
I: Loaded.
I: Loading resource table from file: C:\Users\7\apktool\framework\1.apk
I: Loaded.
I: Decoding file-resources...
I: Decoding values*/* XMLs...
I: Done.
I: Copying assets and libs...

打包APK文件
C:\Users\7>apktool b d:\sanguo                 (apktool b 要把包的文件夹)
I: Checking whether sources has changed...
I: Smaling...
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...
打包后生成的目标位置:D:\sanguo\dist\sanguo.apk

签名APK文件
最简单的是使用AndroidResEdit工具签名就可以了。


参考APK简介

APK是Android Package的缩写,即即Android application package文件或Android安装包。每个要安装到Android平台的应用都要被编译打包为一个单独的文件,后缀名为.apk。APK文件是用专业软件eclipse编译生成的文件包,其中包含了应用的二进制代码、资源、配置文件等。通过将APK文件直接传到Android手机中执行即可安装。APK文件其实就是zip格式,但其扩展名被改为apk,用解压软件可以直接打开。通过WinRAR或UnZip解压后,你会看到有几个文件和文件夹。一个典型的APK文件通常有下列内容组成:
AndroidManifest.xml 程序全局配置文件
classes.dex    Dalvik字节码
resources.arsc    编译后的二进制资源文件
META-INF\ 该目录下存放的是签名信息
res\  该目录存放资源文件
assets\ 该目录可以存放一些配置文件


下面对这些文件和目录做些基本的注释和介绍。
• AndroidManifest.xml
该文件是每个应用程序都必须定义和包含的文件,它描述了应用程序的名字、版本、权限、引用的库文件等等信息。需要解包后才能加以阅读。
• classes.dex文件
classes.dex是java源码编译后生成的java字节码文件。dex是Dalvik VM executes的全称,即Android Dalvik执行程序,并非Java ME的字节码而是Dalvik字节码。
• resources.arsc
编译后的二进制资源文件。
• META-INF目录
META-INF目录下存放的是签名信息,用来保证apk包的完整性和系统的安全。在eclipse编译生成一个apk包时,会对所有要打包的文件做一个校验计算,并把计算结果放在META-INF目录下。这就保证了apk包里的文件不能被随意替换。比如拿到一个apk包后,如果想要替换里面的一幅图片,一段代码, 或一段版权信息,想直接解压缩、替换再重新打包,基本是不可能的。如此一来就给病毒感染和恶意修改增加了难度,有助于保护系统的安全。
• res目录
res目录存放资源文件。包括图片,字符串等等。
解包后,几乎所有可能的修改和编辑工作基本都在这里。
• assets目录
assets目录可以存放一些配置文件,这些文件的内容在程序运行过程中可以通过相关的API获得。

 

0 0
原创粉丝点击