首先,這只是最初步的Android逆向,沒有逆向so文件,有沒有什么內(nèi)存尋址啊之類的高級(jí)技術(shù)。我就是想告訴小白,可以用這種辦法看看Apk的部分代碼。
畢竟Mac上國(guó)內(nèi)的免費(fèi)工具比Windows上少很多
一共3個(gè)工具,Apktool,dex2jar,JD-GUI.作用分別是,
- Apktool:解析apk包,獲取資源文件和smail代碼
- dex2jar:逆向class.dex文件,得到j(luò)ar包
- JD-GUI:查看jar包文件里的java代碼
1.安裝APKTOOL
我知道有人不愛看網(wǎng)站上的英文,你們太懶了直接下載文件下載到一個(gè)jar包 。
不著急,還要一個(gè)啟動(dòng)文件----啟動(dòng)文件原文
代碼如下
#!/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" "$@"
復(fù)制后,建一個(gè)沒有后綴的文件,把這些代碼放在文件里,可以用sublime text

command+s保存到桌面,名字叫apktool
不要后綴!不要后綴!不要后綴!
剛剛下載到的jar包拿到桌面上,改名字叫apktool.jar
兩個(gè)文件復(fù)制剪切到/usr/local/bin文件夾里,這里需要root管理員權(quán)限,
我的系統(tǒng)是OS X10.11,默認(rèn)是隱藏root用戶的,這個(gè)坑你們自己跳吧,很簡(jiǎn)單
復(fù)制進(jìn)去后,給那個(gè)沒有后綴的文件加上執(zhí)行權(quán)限
打開終端,敲命令
$:cd /usr/local/bin
$:chmod +x apktool
要是執(zhí)行報(bào)錯(cuò)的話,說明沒有apktool,或者你根本沒有權(quán)限,去開啟root先!
到上面完成,就可以反編譯apk了
2.安裝dex2jar

得到一只zip包,解壓獲得文件夾一只。

就這樣了,你也可以將命令配置到/usr/local/bin下,創(chuàng)建link來啟動(dòng)dex2jar,我懶,就沒弄了
3.安裝JD-GUI
吐槽:圖標(biāo)好丑
官網(wǎng)地址:http://jd.benow.ca/
下載地址:版本-1.4------for OS X

這個(gè)超簡(jiǎn)單,把a(bǔ)pp文件拖到Application文件夾下就搞定了
4.我們來反編譯吧
現(xiàn)在桌面上有一個(gè)demo.apk文件,我們復(fù)制一份,demo副本.apk
將副本文件名的后綴改為zip,即demo副本.zip
-
獲取xml反編譯文件和smail代碼
啟動(dòng)終端
$:cd /User/zing/Desktop
$:apktool d demo.apk
然后等跑完,里面的資源文件就出來了,還有smail源碼,你要是會(huì)讀的話跟java差不多
不會(huì)讀的話,我們繼續(xù)
- 反編譯
calss.dex文件
剛剛的demo副本.zip解壓獲得demo副本文件夾,進(jìn)入文件夾后拷貝classes.dex

回到dex2jar 解壓的目錄下,將文件復(fù)制進(jìn)去
我的dex2jar文件夾在桌面上
$:cd /User/zing/Desktop/dex2jar-2.0
$:./d2j-dex2jar.sh classes.dex
如果沒有執(zhí)行權(quán)限
$:cd /User/zing/Desktop/dex2jar-2.0
$:chmod +x ./*
$:./d2j-dex2jar.sh classes.dex
這個(gè)時(shí)候文件夾下回多出一個(gè)jar文件classes-dex2jar.jar
- 查看jar文件代碼
將classes-dex2jar.jar文件放到桌面上
打開JD-GUI,

就可以看代碼了
上大圖

love&peace,求點(diǎn)贊……