参照: Android APK反编译详解(附图)http://blog.csdn.net/sunboy_2050/article/details/6727581学习了下怎么样反编译APK。发现这个工具用起来不是很方便。要手动做很多步骤才能搞定。用起来是在有点不爽。
这几天敲好在学习写python脚本。所以就当是联系下自己的python吧!决定把这几个步骤都用脚本实现连接起来。总结了下反编译就只有一下几个步骤:
#         1.将apk重命名为zip
#         2.通过解压zip得到classes.dex
#         3.通过dex2jar工具将classes.dex文件转为jar文件
#         4.将得到的jar文件重命名为和apk文件同名的jar文件
#         5.通过工具查看jar文件。鼠标点来点去太麻烦了。只有用脚本实现上面的1-4步骤就可以了。废话不多少下面是脚本源码。
#!/usr/bin/python
#author : [email protected]
#功能:将制定APK文件反编译成jar文件
#操作步骤:
#         1.将apk重命名为zip
#         2.通过解压得到classes.dex
#         3.通过dex2jar工具将classes.dex文件转为jar文件
#         4.将得到的jar文件重命名为何apk文件批评的jar文件
import sys
import zipfile
import os
import subprocess
import time
import shutildef GetDexFile(zipFile):
    source_zip = zipFile
    target_dir = './tmp/'
  
    myzip = zipfile.ZipFile(source_zip)
    myfilelist = myzip.namelist()
    count_file = len(myfilelist)
    i = 0
    for i in range( 0, count_file):
        if myfilelist[i] == 'classes.dex':
            f_handle = open(target_dir + myfilelist[i], "wb")
            f_handle.write(myzip.read(myfilelist[i]))
            f_handle.close()
            break
    myzip.close()def Dex2Jar(dexFile):
    subprocess.call(['dex2jar.bat', dexFile])def Clean():
    os.remove("./tmp/classes.dex")
    os.remove("./classess.dex")
def Init(jarfile):
    target_dir = './tmp/'
    if not os.path.exists(target_dir):
        os.mkdir(target_dir)
    print("remove temp file")
    if os.path.isfile("./tmp/classes.dex"):
        os.remove("./tmp/classes.dex")
    if os.path.isfile("./tmp/tmp.zip"):
        os.remove("./tmp/tmp.zip")
    if os.path.isfile("./classes.dex"):
        os.remove("./classes.dex")
    if os.path.isfile(jarfile):
        os.remove(jarfile)def main(apkfile):
    jarFile = apkfile[:-4] + '.jar'
    Init(jarFile)
   #subprocess.call(['cp', apkfile, './tmp/tmp.zip'])
    shutil.copy(apkfile, './tmp/tmp.zip')
    zipfile = './tmp/tmp.zip'
    print(zipfile)
    GetDexFile(zipfile)
    if os.path.isfile("./classes.dex"):
        os.remove("./classes.dex")    #subprocess.call(['cp', './tmp/classes.dex', './classes.dex'])
    shutil.copy('./tmp/classes.dex', './classes.dex')    Dex2Jar('./classes.dex')
    os.rename('./classes_dex2jar.jar', jarFile)
    print('Done')
if __name__ == '__main__':
    main(sys.argv[1])把这个代码写好就叫apk2jar.py把。把这个文件放到dex2jar-0.0.9.8目录下面。要反编译的时候直接执行:
python apk2jar.py _target.apk
成功以后就会生成 _target.jar
ps:_target.apk是指你的目标这个就不用细说了,没有写死。
附件还是把所有的东西都打包好给大家分享下吧!
没有找打怎么上传附件。大家就到http://blog.csdn.net/sunboy_2050/article/details/6727581自己下载下攻击。脚本上面的复制就可以啦!!!