Пример #1
0
def dex2jar(f):
    # 如果操作的是apk,则将apk中全部的dex转换为jar文件输出到在apk同级目录下
    if f.endswith('.apk'):
        output_jar_prefix = os.path.splitext(f)[0] + '_'
        temp_dex_dir = PathManager.get_temp_dir_path()
        ZipManager.unzip_dexFile_to_dest(f, temp_dex_dir)
        filenames = os.listdir(temp_dex_dir)
        for dex_name in filenames:
            if dex_name.endswith('.dex'):
                dex_file_path = os.path.join(temp_dex_dir, dex_name)
                jar_file = output_jar_prefix + os.path.splitext(
                    dex_name)[0] + '.jar'
                retcode, msg = star.runcmd2([
                    PathManager.get_dex2jar_path(), dex_file_path, '-f', '-o',
                    jar_file
                ])
                if retcode == 0:
                    star.run_cmd_asyn([PathManager.get_jdgui_path(), jar_file])
                    print('dex2jar ok')
        shutil.rmtree(temp_dex_dir)
        return retcode, msg
    elif f.endswith('.dex'):
        jarFile = os.path.splitext(f)[0] + '.jar'
        retcode, msg = star.runcmd2(
            [PathManager.get_dex2jar_path(), f, '-f', '-o', jarFile])
        if retcode == 0:
            star.run_cmd_asyn([PathManager.get_jdgui_path(), jarFile])
            print('dex2jar ok')
        return retcode, msg
    else:
        print(u'选择文件不合法,文件格式需要是apk或者dex格式')
        os.system("pause")
        return 0, None