反编译APK 我们可以通过解压缩的方式去使用某些apk中res/drawable,res/raw,assets目录下的相关多媒体资源和字体文件等,但是想要同时临摹动画、布局等xml资源却无能为力,因为res/raw和assets文件夹来存放不需要系统编译成二进制的文件,而其他文件在打包的过程会编译成二进制文件。那么此时我们该怎么办呢? Google Code上为我们提供了对apk进行反编译的工具包-apktool,当前最新的版本是2.0.0 RC4,2015-02-12由iBotPeaches上传在https://bitbucket.org/iBotPeaches/apktool/downloads(由于google将要关闭google code服务,所有版本的apktool将会在Bitbucket上发布),当然我们也可以从Google Code中搜索到该入口。 我们通过apktool对apk进行反编译操作,从而得到apk应用中的源代码和图片、XML配置、语言资源等文件。那么如何使用apktool呢,下面我们简单的介绍一下(这里参考Google Code上提供的文档,查看原文档请移步https://code.google.com/p/android-apktool/wiki/ApktoolOptions): 1.apktool下载 通过上面的下载连接我们可以得到名为apktool_2.0.0rc4.jar的jar包,那么我们该如何使用它呢? 1>重命名 将apktool_2.0.0rc4.jar修改为apktool.jar; 2>适配不同的操作系统 windows下 将下面脚本内容保存在apktool.bat文件中 @Echo off set PATH=%CD%;%PATH%; java -jar -Duser.language=en "%~dp0\apktool.jar" %1 %2 %3 %4 %5 %6 %7 %8 %9 linux下: 将下面脚本内容保存为apktool文件 #!/bin/bash # # Copyright (C) 2007 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # This script is a wrapper for smali.jar, so you can simply call "smali", # instead of java -jar smali.jar. It is heavily based on the "dx" script # from the Android SDK # Set up prog to be the path of this script, including following symlinks, # and set up progdir to be the fully-qualified pathname of its directory. prog="$0" while [ -h "${prog}" ]; do newProg=`/bin/ls -ld "${prog}"` echo ${newProg} newProg=`expr "${newProg}" : ".* -> \(.*\)$"` if expr "x${newProg}" : 'x/' >/dev/null; then prog="${newProg}" else progdir=`dirname "${prog}"` prog="${progdir}/${newProg}" fi done oldwd=`pwd` progdir=`dirname "${prog}"` cd "${progdir}" progdir=`pwd` prog="${progdir}"/`basename "${prog}"` cd "${oldwd}" jarfile=apktool.jar libdir="$progdir" if [ ! -r "$libdir/$jarfile" ] then echo `basename "$prog"`": can't find $jarfile" exit 1 fi javaOpts="" # If you want DX to have more memory when executing, uncomment the following # line and adjust the value accordingly. Use "java -X" for a list of options # you can pass here. # javaOpts="-Xmx512M" # Alternatively, this will extract any parameter "-Jxxx" from the command line # and pass them to Java (instead of to dx). This makes it possible for you to # add a command-line parameter such as "-JXmx256M" in your ant scripts, for # example. while expr "x$1" : 'x-J' >/dev/null; do opt=`expr "$1" : '-J\(.*\)'` javaOpts="${javaOpts} -${opt}" shift done if [ "$OSTYPE" = "cygwin" ] ; then jarpath=`cygpath -w "$libdir/$jarfile"` else jarpath="$libdir/$jarfile" fi # add current location to path for aapt PATH=$PATH:`pwd`; export PATH; exec java $javaOpts -jar "$jarpath" "$@" 3>设置环境变量 将apktool.jar和apktoo.bat所在的文件夹添加到系统环境变量中或者拷贝到系统文件夹中C://Windows,Linux下拷贝到/usr/local/bin (root needed)中,并且要记得修改文件权限(chmod +x) 实用选项 -version, --version 输出当前版本。 -v, --verbose 详细输出,该命令在所有其他命令之前。 -q, --quiet 静态输出. 该命令在所有其他命令之前。 -advance, --advanced 打印高级选项。 反编译选项 --api <API> 生成smali文件的api版本。(eg 14 for ICS). -b, --no-debug-info 不打印log信息. -d, --debug 启动debug模式 --debug-line-prefix <prefix> Smali line prefix when decoding in debug mode. Default "a=0;//" -f, --force 如果反编译后生成的文件目录已经存在,则强制覆盖。 --keep-broken-res 如果反编译过程正发生错误,需手动修复。 -m, --match-original 最大可能保持文件接近原始文件,防止重建,通常用于分析。 -o, --output <dir> 指定输出路径. -p, --frame-path <dir> 指定framework路径. -r, --no-res 防止重新编译资源文件。 -s, --no src 防止重新编译源文件. -t, --frame-tag <tag> 使用framework文件标记. 如何反编译? 反编译之前, 必须保证frameworks已经安装。有关Frameworks可以访问https://code.google.com/p/android-apktool/wiki/FrameworkFiles。如果已安装了frameworks,可以运行如下命令进行反编译: apktool d name_of_apk.apk 重建选项 -a, --aapt <file> 从指定的路径总载入aapt,如果找不到相关目录则会执行回滚操作. -c, --copy-original 拷贝 AndroidManifest.xml 和 META-INF 文件夹到重建的apk中. -d, --debug 启动debug模式。 -f, --force-all 重建过程中覆盖已存在的文件. -o, --output <dir> 指定输出路径. -p, --frame-path <dir> 指定framework files的路径. 如何重建一个项目? apktool b folder_of_decoded_apk 那么通过apktool d xx.apk,我们将apk文件反编译之后我们就可以使用编辑工具查看一些xml配置文件了,但是源文件对于我们来说还是未解之谜。因为apktool将Android字节码文件转换为smali文件。 smali是将Android字节码用可阅读的字符串形式表现出来的一种语言,可以称之为Android字节码的反汇编语言。使用baksmali或apktool可以将Android应用程序包(apk或jar)反编译为smali代码。 那么我们接下来要做的就是把smali文件反编译为java文件 反编译smali smali2java是一个将smali代码反编译成java代码的工具,是基于apktool v1.5.0(baksmali v1.3.4)生成的smali文件,依赖于smali文件中的代码行数(.line关键字)和变量别名(.local关键字)等信息,可以最大程度还原原始的java代码。还原出的java代码将具有原始的变量命名,代码的顺序也与原始的java代码保持一致。查看回复
如何隐藏磁盘驱动器 在[开始]-->[运行]-->键入[Regedit]-->[HKEY_CURRENT_USER]-->[Software]-->[Microsoft]-->[Windows]-->[CurrentVersion]-->[Policies]-->[Explorer]-->增加一个 DWORD 值[NoDrives]的数值数据请使用十进制及如下设定:隐藏 A 盘为[1],隐藏 B 盘为 A 盘的一倍即[2],隐藏 C 盘为 B 盘的一倍即[4],如此类推,如全部隐藏则为[67108863]。 另在[HKEY_LOCAL_MACHINE]-->[Software]-->[Microsoft]-->[Windows]-->[CurrentVersion]-->[Policies]-->[Explorer]-->增加一个 DWORD 值,[NoDrives]的数值数据请使用十进制及如下设定:隐藏 A 盘为[1],隐藏 B 盘为 A 盘的一倍即[2],隐藏 C 盘为 B 盘的一倍即[4],如此类推,如全部隐藏则为[67108863]。查看回复