666

Mac上Apktool、dex2jar、JD-GUI简单安装和使

2019-03-21  本文已影响0人  萌木盖

想做一个简单的安卓逆向,没有壳的情况下。看一下他们的源码。所以下载了一些工具,下面简单介绍下。
一共3个工具,Apktool,dex2jar,JD-GUI.作用分别是:

这里说一点是如果你只是想看java代码。第一个工具不用装。

1.安装APKTOOL

apktool网址

我知道有人不爱看网站上的英文,你们太懒了直接下载文件下载到一个jar包 。

不着急,还要一个启动文件----启动文件原文

代码如下(并加上我的解释)

#!/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" "$@"

复制后,建一个没有后缀的文件,把这些代码放在文件里,可以用sublime text

image
$:cd /usr/local/bin
$:chmod +x apktool

要是执行报错的话,说明没有apktool,或者你根本没有权限,去开启root先!

$:ln -s 你放置的绝对路径/apktool /usr/local/bin/apktool
$:chmod +x /usr/local/bin/apktool

到上面完成,就可以反编译apk了,
下面是纯抄袭。抄袭地址我会放到最下方

2.安装dex2jar

dex2jar官方gitlab
下载地址

image

得到一只zip包,解压获得文件夹一只。

image

就这样了,你也可以将命令配置到/usr/local/bin下,创建link来启动dex2jar,我懒,就没弄了


3.安装JD-GUI

吐槽:图标好丑
官网地址:http://jd.benow.ca/
下载地址:版本-1.4------for OS X

image

这个超简单,把app文件拖到Application文件夹下就搞定了


4.我们来反编译吧

现在桌面上有一个demo.apk文件,我们复制一份,demo副本.apk
将副本文件名的后缀改为zip,即demo副本.zip

$:cd /User/zing/Desktop
$:apktool d demo.apk

然后等跑完,里面的资源文件就出来了,还有smail源码,你要是会读的话跟java差不多
不会读的话,我们继续

image

回到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

打开JD-GUI,

image

就可以看代码了

上大图

image

love&peace,求点赞……
我抄袭的本片博客

上一篇 下一篇

猜你喜欢

热点阅读