zoukankan      html  css  js  c++  java
  • Mac下ApkTool Android反编译

    1.所需文件下载
    apktool工具包下载地址:
    https://code.google.com/p/android-apktool/downloads/list
    需要下载一个apktool的jar包以及 dependencies(辅助工具,分别有Windows,OSX,Linux版本)

    2.安装操作
    将apktool.jar放到辅助工具目录下,也就是和apktool、aapt放到一起.进入apktool-install-macosx-r05-ibot目录下,在终端输入sh apktool:
    HuangdeMacBook-Pro:apktool-install-macosx-r05-ibot huangxufeng$ sh apktool
    显示结果:
    Apktool v1.5.2 - a tool for reengineering Android apk files
    Copyright 2010 Ryszard Wiśniewski <brut.alll@gmail.com>
    with smali v1.4.1, and baksmali v1.4.1
    Updated by @iBotPeaches <connor.tumbleson@gmail.com>
    Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

    Usage: apktool [-q|--quiet OR -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.
    -b, --no-debug-info
    Baksmali -- don't write out debug info (.local, .param, .line, etc.)
    -f, --force
    Force delete destination directory.
    -t <tag>, --frame-tag <tag>
    Try to use framework files tagged by <tag>.
    --frame-path <dir>
    Use the specified directory for framework files
    --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.
    -a, --aapt
    Loads aapt from specified location.

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

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

    3.decode命令

    将需要反编译的Apk包放到apktool-install-macosx-r05-ibot文件夹下,在终端中进入apktool-install-macosx-r05-ibot目录下,

    输入 ./apk d 你要反编译的Apk名  ,回车完成后,在该文件夹下就会生成一个与Apk同名的文件夹,里面既为反编译出来的Smali和各种资源文件。

    4.build命令

    修改完反编译文件,需要重新打包回Apk,和decode一样,需要在apktool-install-macosx-r05-ibot目录下,

    输入 ./apk b 你要打包成Apk的反编译文件夹(即刚用decode生成的文件夹,与Apk同名)  

    5.Apk签名-创建.keystore文件

    build生成的Apk是不含Android应用签名的,只有含有合法有效的应用签名的Apk才能在Android上安装。

    Mac下可以使用keytool生成.keystore文件

    终端输入:

    keytool -genkey -keystore hxf.keystore -keyalg RSA -validity 10000 -alias hxf.keystore

    这里hxf.keystore是生成的Keystore证书文件名,-alias是别名。

    接下来在终端下根据流程输入如下信息

    输入密钥库口令:
    再次输入新口令:
    您的名字与姓氏是什么?
    [Unknown]: kyokuhuang
    您的组织单位名称是什么?
    [Unknown]: ssdut
    您的组织名称是什么?
    [Unknown]: dlut
    您所在的城市或区域名称是什么?
    [Unknown]: Dalian
    您所在的省/市/自治区名称是什么?
    [Unknown]: Liaoning
    该单位的双字母国家/地区代码是什么?
    [Unknown]: CN
    CN=huangxufeng, OU=dlut, O=ssdut, L=dalian, ST=liaoning, C=china是否正确?
    [否]: y

    至此,安全证书生成。

    6.为Apk签名

    Mac下使用jarsigner签名应用

    终端输入:jarsigner -verbose -keystore hxf.keystore -signedjar 签名后的应用名.apk -digestalg SHA1 -sigalg MD5withRSA  签名前的应用名.apk  hxf.keystore。

    注意这边最后一个hxf.keystore是安全证书别名,应和上面创建证书的 -alias 后面的参数保持一致。

    这样,jarsigner会使用你生成好的证书hxf.keystore对应用进行签名。

    至此,你的应用已经可以在Android上正常安装并运行。

    7.zipalign对齐,如果你的应用需要上传GooglePlayStore,则必须对齐。

    终端命令:zipalign -v 4 输入文件名.apk 输出文件名.apk

    附:Dalvik字节码和smali文件相关内容推荐看一下这篇文章,写得很全 

    http://blog.csdn.net/lpohvbe/article/details/7981386

  • 相关阅读:
    mybatis关键查询
    智能标签
    mybatis注解基础使用
    myBatis基础知识点
    Mybatis框架模糊查询
    python(7):sympy模块
    anaconda中的包如何传到pycharm中使用?
    python(6):Scipy之pandas
    python(5):scipy之numpy介绍
    python(4): regular expression正则表达式/re库/爬虫基础
  • 原文地址:https://www.cnblogs.com/kyokuhuang/p/4188096.html
Copyright © 2011-2022 走看看