最近开始了解一些安卓逆向的知识,希望抽空做一个学习的记录。
1.JADX
JADX是一个很强大的安卓反编译工具。支持的文件类型有apk、dex、jar、zip、class、aar 文件,可以看到 jadx 支持的格式还是挺多的,基本上编译成 Java 虚拟机能识别的字节码,它都可以进行反编译。除了选择一个文件,还可以直接将 apk 文件,拖拽进去,由于我的是Mac,所以主要介绍在Mac上的安装笔记。Mac安装Jadx很简单:
mkdir jadx #创建 jadx目录
git clone https://github.com/skylot/jadx.git #将存储库克隆到目录
cd jadx # 进入 jadx目录
./gradlew dist
复制代码
最后一步经常会断掉,我开始安装的一直报SSL Exception,但是删除重新安装就好了(玄学)。
直接打开就可以使用图形化界面了,如果APK比较大,也可以使用命令行的方式。
2.Apktool
首先先下载jar包,链接如下:
下载链接
之后复制这段unix脚本,并命名为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}"`
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
# 判断系统,我得是mac根本就不走这段代码
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 -Djava.awt.headless=true -jar "$jarpath" "$@"
复制代码
需要把这个脚本和jar包移动到/usr/local/bin
下,或者通过软链接的方式:
ln -s 你放置的绝对路径/apktool /usr/local/bin/apktool
chmod +x /usr/local/bin/apktool
复制代码
然后给与这个脚本可执行的权限:
chmod +x /usr/local/bin/apktool
OR
chmod +x 你放置的绝对路径/apktool
复制代码
apktool –version,就已经可以啦~
常用的就两个命令:
# 反编译
apktool d test.apk
# 重新打包
apktool b test
复制代码
这样在目标文件夹下就会有打包完成的一个由apktool打包的apk了,但是这样的还是不可以安装的,因为没有签名。
3.keytool & jarsigner
这两个工具是java的jdk自带的,因此只要安装了jdk即可。
# 1.生成证书
keytool -genkey -keystore my-release-key.keystore -alias my_alias -keyalg RSA -keysize 4096 -validity 10000
# 2.用证书给apk签名 android_signed.apk是签名后的apk android.apk是签名前的apk
jarsigner -sigalg MD5withRSA -digestalg SHA1 -keystore my-release-key.keystore -signedjar android_signed.apk android.apk my_alias
复制代码
未签名APK不能在安卓手机上安装。可以用这两个命令找到是否jdk安装成功。
where keytool
where jarsigner
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END