首先,这只是最初步的Android逆向,没有逆向so文件,有没有什么内存寻址啊之类的高级技术。我就是想告诉小白,可以用这种办法看看Apk的部分代码。
毕竟Mac上国内的免费工具比Windows上少很多
一共3个工具,Apktool,dex2jar,JD-GUI.作用分别是,
Apktool:解析apk包,获取资源文件和smail代码
dex2jar:逆向class.dex文件,得到jar包
JD-GUI:查看jar包文件里的java代码
1.安装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
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" "$@"
复制后,建一个没有后缀的文件,把这些代码放在文件里,可以用sublime text
sublime text
command+s保存到桌面,名字叫apktool
不要后缀!不要后缀!不要后缀!
刚刚下载到的jar包拿到桌面上,改名字叫apktool.jar
两个文件复制剪切到/usr/local/bin文件夹里,这里需要root管理员权限,
我的系统是OS X10.11,默认是隐藏root用户的,这个坑你们自己跳吧,很简单
复制进去后,给那个没有后缀的文件加上执行权限
打开终端,敲命令
$:cd /usr/local/bin
$:chmod +x apktool
要是执行报错的话,说明没有apktool,或者你根本没有权限,去开启root先!
到上面完成,就可以反编译apk了
2.安装dex2jar
点download
得到一只zip包,解压获得文件夹一只。
文件结构
就这样了,你也可以将命令配置到/usr/local/bin下,创建link来启动dex2jar,我懒,就没弄了
3.安装JD-GUI
好多版本啊
这个超简单,把app文件拖到Application文件夹下就搞定了
4.我们来反编译吧
现在桌面上有一个demo.apk文件,我们复制一份,demo副本.apk
将副本文件名的后缀改为zip,即demo副本.zip
获取xml反编译文件和smail代码
启动终端
$:cd /User/zing/Desktop
$:apktool d demo.apk
然后等跑完,里面的资源文件就出来了,还有smail源码,你要是会读的话跟java差不多
不会读的话,我们继续
反编译calss.dex文件
刚刚的demo副本.zip解压获得demo副本文件夹,进入文件夹后拷贝classes.dex
classes.dex文件
回到dex2jar 解压的目录下,将文件复制进去
我的dex2jar文件夹在桌面上
$:cd /User/zing/Desktop/dex2jar-2.0
$:./d2j-dex2jar.sh classes.dex
如果没有执行权限
$:cd /User/zing/Desktop/dex2jar-2.0
$:chmod +x ./*
$:./d2j-dex2jar.sh classes.dex
这个时候文件夹下回多出一个jar文件classes-dex2jar.jar
查看jar文件代码
将classes-dex2jar.jar文件放到桌面上
打开JD-GUI,
这就不用教了吧,打开jar文件
就可以看代码了
上大图
大图!
love&peace,求点赞……