Ejemplo n.º 1
0
def get_apk_data(apk_single):
    # 获取没有拓展名的文件名
    apk_dir = os.path.split(apk_single)[-1].split(".")[0]

    apk_size = utils.get_path_size(apk_single)
    print("apk_single:%s size: %s" % (apk_dir, utils.get_size_in_nice_string(apk_size)))

    # 解压文件夹以便分析
    print("start to unzip apk single")
    utils.surely_rmdir(apk_dir)
    utils.unzip_dir(apk_single, apk_dir)

    print("unzip apk info:")
    check_unzipped_apk(apk_single, apk_dir)

    json_object = get_json_from_file("apk_tree");
    data_string = json.dumps(json_object)
    jdict = json.loads(data_string)

    # 键值对保存要查文件的大小,用于后面对比
    apk_obj = dict();
    method_dict = dict();

    print("")
    print("")
    # 输出其中指定文件的大小
    print("============%s==============" % apk_dir)
    walk_dict(apk_dir, jdict, apk_obj, method_dict, apk_dir)
    print("============%s==============" % apk_dir)

    # 清除临时解压的apk文件夹
    utils.surely_rmdir(apk_dir)
Ejemplo n.º 2
0
def apk_image_check(check_alpha=True, limit=40000, apk=None, ignore9=True, value=255):
    if apk is None:
        print("invalid apk file or name")
        exit()

    utils.check_apk_name_valid(apk)
    print("apk:" + apk)

    # 获取没有拓展名的文件名
    apk_dir = os.path.split(apk)[-1].split(".")[0]


    # 解压文件夹以便分析
    print("start to unzip apk")
    utils.surely_rmdir(apk_dir)
    utils.unzip_dir(apk, apk_dir)

    if limit is not None:
        print("")
        print("============ check size limit ==================");
        check_image_limit(apk, apk_dir, limit)
        print("============ check size limit ==================");

    if check_alpha:
        print("")
        print("")
        print("============ check image alpha ==================");
        check_apk_alpha(apk, apk_dir, ignore9, value)
        print("============ check image alpha ==================");
    print("")

    # 移除分析用的解压出来的文件
    utils.surely_rmdir(apk_dir)
Ejemplo n.º 3
0
def get_method_counts_in_file(filepath):
    if not os.path.isfile(filepath):
        return None
    if ".jar" in filepath:
        abspath = os.path.abspath(filepath)
        # print("abspath:" + abspath)
        filename = os.path.basename(filepath).split(".")[0]
        # print("filename:" + filename)
        floderpath = os.path.split(abspath)[0]
        # print("floderpath:" + floderpath)
        unzippath = os.path.join(floderpath, filename)
        # print("unzippath:" + unzippath)
        utils.unzip_dir(abspath, unzippath)
        dexpath = os.path.join(unzippath, "classes.dex")
        count = get_method_count(dexpath)
        utils.surely_rmdir(unzippath)
        return count
    elif ".dex" in filepath:
        abspath = os.path.abspath(filepath)
        return get_method_count(abspath)
    return None
Ejemplo n.º 4
0
def compare_apk(apk_old, apk_new, top=None):
    # 获取没有拓展名的文件名
    old_apk_dir = os.path.split(apk_old)[-1].split(".")[0]
    new_apk_dir = os.path.split(apk_new)[-1].split(".")[0]
    print("old_apk_dir:" + old_apk_dir)
    print("new_apk_dir:" + new_apk_dir)

    old_size = utils.get_path_size(apk_old)
    new_size = utils.get_path_size(apk_new)
    print("apk_old:%s size: %s" % (apk_old, utils.get_size_in_nice_string(old_size)))
    print("apk_new:%s size: %s" % (apk_new, utils.get_size_in_nice_string(new_size)))
    print("")

    # 解压文件夹以便分析
    utils.surely_rmdir(old_apk_dir)
    utils.surely_rmdir(new_apk_dir)
    print("start to unzip apk old")
    utils.unzip_dir(apk_old, old_apk_dir)
    print("start to unzip apk new")
    utils.unzip_dir(apk_new, new_apk_dir)
    print("")

    print("unzip apk info:")
    check_unzipped_apk(apk_old, old_apk_dir)
    check_unzipped_apk(apk_new, new_apk_dir)

    json_object = get_json_from_file("apk_tree");
    data_string = json.dumps(json_object)
    jdict = json.loads(data_string)

    # 键值对保存要查文件的大小,用于后面对比
    old_apk_obj = dict()
    new_apk_obj = dict()
    # 方法数dict
    new_method_dict = dict()
    old_method_dict = dict()

    print("")
    print("")
    # 输出其中指定文件的大小
    print("============%s==============" % old_apk_dir)
    walk_dict(old_apk_dir, jdict, old_apk_obj, old_method_dict, old_apk_dir)
    print("============%s==============" % old_apk_dir)
    print("")
    print("")
    print("============%s==============" % new_apk_dir)
    walk_dict(new_apk_dir, jdict, new_apk_obj, new_method_dict, new_apk_dir)
    print("============%s==============" % new_apk_dir)
    print("")
    print("")

    print("============compare result==============")
    # compare
    compare_dict(new_apk_obj, old_apk_obj, new_method_dict, old_method_dict)
    print("============compare result==============")
    print("")
    print("")

    # 检查出apk种新添的文件
    # 文件dict,用于检查新文件
    new_file_dict = dict()
    removed_file_dict = dict()
    changed_file_dict = dict()
    dirCompare(old_apk_dir, new_apk_dir, new_file_dict, removed_file_dict, changed_file_dict)
    print_top_dict(new_file_dict, top, "new file")
    print("")
    print("")
    print_top_dict(removed_file_dict, top, "removed file")
    print("")
    print("")
    print_top_dict(changed_file_dict, top, "changed file")

    # 清除临时解压的apk文件夹
    utils.surely_rmdir(old_apk_dir)
    utils.surely_rmdir(new_apk_dir)