示例#1
0
def exec_generate_r(res_path, manifest_path, gen_path, target_dex_path,
                    new_package_name) -> bool:
    """
    generate R.java for the new_package_name
    """
    if not os.path.exists(res_path):
        return False

    aapt_path = java.get_aapt_shell()
    android_path = FPath.ASSETS_PATH + "/apktool/android.jar"
    shell = "%s p -f -m -J %s -S %s -I %s -M %s" % (
        aapt_path, gen_path, res_path, android_path, manifest_path)
    if not command.exec_command(shell):
        return False

    r_path = new_package_name.replace(".", "/")
    r_path = os.path.join(gen_path, r_path)
    r_path = os.path.join(r_path, "R.java")

    shell = java.get_javac_shell(
    ) + " -source 1.7 -target 1.7 -encoding UTF-8 %s" % (r_path)
    if not command.exec_command(shell):
        return False

    dex_tool_path = FPath.ASSETS_PATH + "/apktool/dx.jar"
    shell = java.get_java_shell(
    ) + " -jar -Xmx2048m -Xms2048m %s --dex --output=%s %s" % (
        dex_tool_path, target_dex_path, gen_path)
    if not command.exec_command(shell):
        return False

    smali_path = os.path.join(FPath.DECOMPILE_PATH, "smali")
    return java.dex2smali(target_dex_path, smali_path)
示例#2
0
def decompile_apk(task: Task) -> bool:
    if use_apktool232(task):
        apktool = FPath.APKTOOL232
    else:
        apktool = FPath.APKTOOL231
    cmd = "%s -jar -Xms2048m -Xmx2048m %s -v d -b -f %s -o %s" % (
        java.get_java_shell(), apktool, FPath.ORIGIN_APK, FPath.DECOMPILE_PATH)
    return command.exec_command(cmd)
示例#3
0
def dex2smali(src_dir: str, dst_dir: str) -> bool:
    baksmali_tool = FPath.BAKSMALI_JAR
    if not os.path.exists(src_dir):
        Flog.i("classes.dex is can not found , where : " + src_dir)
        return False
    if not os.path.exists(dst_dir):
        os.makedirs(dst_dir)

    cmd = get_java_shell() + " -jar %s -o %s %s" % (baksmali_tool, dst_dir,
                                                    src_dir)
    return command.exec_command(cmd)
示例#4
0
def jar2dex(src_dir: str, dst_dir: str) -> bool:
    dx_tool = FPath.DX_JAR
    if os.path.exists(src_dir):
        cmd = get_java_shell(
        ) + " -jar -Xms2048m -Xmx2048m %s --dex --multi-dex --output=%s" % (
            dx_tool, dst_dir)
        for jar_file in os.listdir(src_dir):
            if jar_file.endswith(".jar"):
                cmd = cmd + " " + os.path.join(src_dir, jar_file)
        return command.exec_command(cmd)
    else:
        return False
示例#5
0
def compile_apk(task: Task) -> bool:
    if use_apktool232(task):
        apktool = FPath.APKTOOL232
    else:
        apktool = FPath.APKTOOL231
    if os.path.exists(FPath.COMPILE_PATH):
        cmd = "%s -jar -Xms2048m -Xmx2048m %s -v b -f %s -o %s" % (
            java.get_java_shell(), apktool, FPath.COMPILE_PATH,
            FPath.OUTPUT_APK)
        return command.exec_command(cmd)
    else:
        return False
示例#6
0
def sign(task: Task, new_mode: bool, sigalg: str = "SHA1withRSA") -> bool:
    if new_mode:
        apkfile = FPath.WORKSPACE_PATH + "/new_mode_output.apk"
    else:
        apkfile = FPath.WORKSPACE_PATH + "/output.apk"
    keystore = FPath.WORKSPACE_PATH + "/" + task.keystore_info.keystore_name
    if not os.path.exists(keystore):
        Flog.i("the keystore file is not exists. " + keystore)
        return False
    sign_shell = java.get_jarsigner_shell(
    ) + " -digestalg SHA1 -sigalg %s -keystore %s -storepass %s -keypass %s %s %s" % (
        sigalg, keystore, task.keystore_info.keystore_password,
        task.keystore_info.keystore_alias_password, apkfile,
        task.keystore_info.keystore_alias)

    return command.exec_command(sign_shell)