コード例 #1
0
ファイル: ApkUtils.py プロジェクト: dunmingzhe/Package_py
def generate_r_file(package_name, decompile_dir):
    # check_value_resources(decompile_dir)
    temp_path = os.path.dirname(decompile_dir) + '/temp'
    LogUtils.debug('generate R:the temp path is %s', temp_path)
    if os.path.exists(temp_path):
        Utils.del_file(temp_path)
    os.makedirs(temp_path)
    res_path = decompile_dir + '/res'
    temp_res_path = temp_path + '/res'
    Utils.copy_file(res_path, temp_res_path)
    gen_path = temp_path + '/gen'
    os.makedirs(gen_path)

    aapt_path = Utils.get_full_path('tools/aapt2.exe')
    android_path = Utils.get_full_path('tools/android.jar')
    java = Utils.get_full_path('tools/jdk/bin/java')
    javac = Utils.get_full_path('tools/jdk/bin/javac')

    manifest_path = decompile_dir + '/AndroidManifest.xml'
    res_flat_path = temp_path + "/res_flat.zip"
    cmd = '%s compile -o %s --dir %s' % (aapt_path, res_flat_path,
                                         temp_res_path)
    ret = Utils.exec_cmd(cmd)
    if ret:
        return 1
    cmd = '%s link -o %s --manifest %s -I %s --java %s %s' % (
        aapt_path, temp_path + '/res.apk', manifest_path, android_path,
        gen_path, res_flat_path)
    ret = Utils.exec_cmd(cmd)
    if ret:
        return 1

    LogUtils.info('package_name:%s', package_name)
    r_path = package_name.replace('.', '/')
    r_path = gen_path + '/' + r_path + '/R.java'
    cmd = '%s -source 1.8 -target 1.8 -encoding UTF-8 %s' % (javac, r_path)
    ret = Utils.exec_cmd(cmd)
    if ret:
        return 1
    dex_path = temp_path + '/classes.dex'
    dex_tool_path = Utils.get_full_path('tools/dx.jar')
    cmd = '%s -jar %s --dex --output %s %s' % (java, dex_tool_path, dex_path,
                                               gen_path)
    ret = Utils.exec_cmd(cmd)
    if ret:
        return 1
    smali_path = decompile_dir + '/smali'
    ret = dex2smali(dex_path, smali_path, '')
    if ret:
        return 1
    return 0
コード例 #2
0
ファイル: ApkUtils.py プロジェクト: dunmingzhe/Package_py
def copy_root_ext_files(apk_file, decompile_dir):
    aapt = Utils.get_full_path('tools/aapt2.exe')
    ignore_files = [
        'AndroidManifest.xml', 'apktool.yml', 'smali', 'res', 'original',
        'lib', 'libs', 'build', 'assets', 'unknown', 'kotlin',
        'smali_classes2', 'smali_classes3', 'smali_classes4', 'smali_classes5'
    ]
    ignore_file_paths = []
    for file in ignore_files:
        path = os.path.join(decompile_dir, file)
        ignore_file_paths.append(path)

    add_files = []
    add_files = Utils.list_files(decompile_dir, add_files, ignore_file_paths)
    if len(add_files) <= 0:
        return 0
    cmd = '%s add %s'
    for f in add_files:
        name = f[len(decompile_dir) + 1:]
        cmd = cmd + ' ' + name
    cmd = cmd % (aapt, apk_file)
    curr_path = os.getcwd()
    os.chdir(decompile_dir)
    ret = Utils.exec_cmd(cmd)
    os.chdir(curr_path)
    return ret
コード例 #3
0
ファイル: ApkUtils.py プロジェクト: dunmingzhe/Package_py
def decompile_apk(apk_file, target_dir, frame_work_dir):
    java = Utils.get_full_path('tools/jdk/bin/java')
    apk_tool = Utils.get_full_path('tools/apktool.jar')
    os.makedirs(target_dir)
    os.makedirs(frame_work_dir)
    cmd = "%s -jar %s d %s -o %s -p %s -f" % (java, apk_tool, apk_file,
                                              target_dir, frame_work_dir)
    return Utils.exec_cmd(cmd)
コード例 #4
0
ファイル: ApkUtils.py プロジェクト: dunmingzhe/Package_py
def sign_apk(game, apk_file):
    key_path = Utils.get_full_path('games/' + game['id'] + '/keystore/' +
                                   game['keystore'])
    if not os.path.exists(key_path):
        LogUtils.info('the keystore file not exists: %s', key_path)
        return 1
    LogUtils.info('the keystore file is %s', key_path)
    aapt = Utils.get_full_path('tools/aapt.exe')
    lcmd = "%s list %s" % (aapt, apk_file)
    out = Utils.exec_cmd2(lcmd)
    if out is not None and len(out) > 0:
        for filename in out.split('\n'):
            if filename.find('META-INF') == 0:
                rmcmd = "%s remove %s %s" % (aapt, apk_file, filename)
                Utils.exec_cmd(rmcmd)
    jar_signer = Utils.get_full_path('tools/jdk/bin/jarsigner')
    sign_cmd = "%s -keystore %s -storepass %s -keypass %s %s %s -sigalg  SHA1withRSA -digestalg SHA1" % (
        jar_signer, key_path, game['keypwd'], game['aliaspwd'], apk_file,
        game['alias'])
    return Utils.exec_cmd(sign_cmd)
コード例 #5
0
ファイル: ApkUtils.py プロジェクト: dunmingzhe/Package_py
def dex2smali(dex_file, target_dir, path):
    """
        Transfer the dex to smali.
    """
    if not os.path.exists(dex_file):
        LogUtils.error('the dexfile is not exists. path:%s', dex_file)
        return 1
    if not os.path.exists(target_dir):
        os.makedirs(target_dir)
    smali_tool = Utils.get_full_path('tools/baksmali.jar')
    java = Utils.get_full_path('tools/jdk/bin/java')
    cmd = '%s -jar %s -o %s %s' % (java, smali_tool, target_dir, dex_file)
    return Utils.exec_cmd(cmd)
コード例 #6
0
ファイル: ApkUtils.py プロジェクト: dunmingzhe/Package_py
def jar2dex(src_dir, dex_path):
    """
        compile jar files to dex.
    """
    dex_tool_path = Utils.get_full_path('tools/dx.jar')
    java = Utils.get_full_path('tools/jdk/bin/java')
    cmd = '%s -jar %s --dex --output %s' % (java, dex_tool_path, dex_path)

    for f in os.listdir(src_dir):
        if f.endswith('.jar'):
            cmd = cmd + ' ' + os.path.join(src_dir, f)

    for f in os.listdir(os.path.join(src_dir, 'libs')):
        if f.endswith('.jar'):
            cmd = cmd + ' ' + os.path.join(src_dir, 'libs', f)
    return Utils.exec_cmd(cmd)
コード例 #7
0
ファイル: ApkUtils.py プロジェクト: dunmingzhe/Package_py
def align_apk(apk_file, target_file):
    align = Utils.get_full_path('tools/zipalign.exe')
    cmd = '%s -f 4 %s %s' % (align, apk_file, target_file)
    return Utils.exec_cmd(cmd)
コード例 #8
0
ファイル: ApkUtils.py プロジェクト: dunmingzhe/Package_py
def recompile_apk(source_folder, apk_file, frame_work_dir):
    java = Utils.get_full_path('tools/jdk/bin/java')
    apk_tool = Utils.get_full_path('tools/apktool.jar')
    cmd = "%s -jar %s b %s -o %s -p %s" % (java, apk_tool, source_folder,
                                           apk_file, frame_work_dir)
    return Utils.exec_cmd(cmd)