Ejemplo n.º 1
0
def obfuscate():
    """ The main obfuscator function """
    try:
        res_xml = u.load_res_repository()  # Load the 'pulbic.xml' resource repository
    except e.FileNotFound:
        return
    res_root = res_xml.getroot()  # The root of the XML file
    edited_res = set(
        list(change_all_res(res_root)) +
        list(change_meta(u.load_manifest().getroot()))
        )
    u.save_res_repository(res_xml)  # Save the 'pulbic.xml' resource repository back to file
    change_all_res_file(u.load_xml_file(), edited_res)
    change_allfile(u.load_resource_file(), edited_res)
    try:
        res_xml = u.load_res_repository()  # Load the 'pulbic.xml' resource repository
    except e.FileNotFound:
        return
    item_id_list = list(add_id_random_resource(res_root))
    u.save_res_repository(res_xml)  # Save the 'pulbic.xml' resource repository back to file
    ids_xml = fix_ids(u.load_res_id_repository())  # Load the 'ids.xml' resource repository
    ids_root = ids_xml.getroot()  # The root of the XML file
    add_id_random_in_ids(ids_root, item_id_list)
    u.save_ids_repository(ids_xml)  # Save the 'ids.xml' resource repository back to file
    append_defunct_class()
Ejemplo n.º 2
0
def obfuscate():
    """ The main obfuscator function """
    try:
        res_xml = u.load_res_repository(
        )  # Load the 'pulbic.xml' resource repository
    except e.FileNotFound:
        return
    res_root = res_xml.getroot()  # The root of the XML file
    edited_res = set(
        list(change_all_res(res_root)) +
        list(change_meta(u.load_manifest().getroot())))
    u.save_res_repository(
        res_xml)  # Save the 'pulbic.xml' resource repository back to file
    change_all_res_file(u.load_xml_file(), edited_res)
    change_allfile(u.load_resource_file(), edited_res)
    try:
        res_xml = u.load_res_repository(
        )  # Load the 'pulbic.xml' resource repository
    except e.FileNotFound:
        return
    item_id_list = list(add_id_random_resource(res_root))
    u.save_res_repository(
        res_xml)  # Save the 'pulbic.xml' resource repository back to file
    ids_xml = fix_ids(
        u.load_res_id_repository())  # Load the 'ids.xml' resource repository
    ids_root = ids_xml.getroot()  # The root of the XML file
    add_id_random_in_ids(ids_root, item_id_list)
    u.save_ids_repository(
        ids_xml)  # Save the 'ids.xml' resource repository back to file
    append_defunct_class()
Ejemplo n.º 3
0
def obfuscate():
    """ The main obfuscator function """
    init_package_name()
    smali_file_list = u.load_smali_file()  # Load the smali files
    res_file_list = set(list(u.load_xml_file()) +
                        list(smali_file_list))  # Load the XML files
    edited_class = set(find_all_class(smali_file_list))
    change_all_class(edited_class, smali_file_list)
    change_all_res_file(res_file_list, set(get_res_class(edited_class)),
                        package_name)
    manifest_xml = u.load_manifest()  # Load the Manifest file
    task_affinity = 'a' + u.get_random(True, 7) + '.' + 'a' + u.get_random(
        True, 7)
    rename_list = set(
        list(change_package_name(manifest_xml)) +
        list(rename_val(manifest_xml, 'activity', 'label', ['@'], False)) +
        list(rename_val(manifest_xml, 'activity', 'process', ['@'], False)) +
        list(rename_val(manifest_xml, 'application', 'label', ['@'], False)) +
        list(rename_val(manifest_xml, 'provider', 'label', ['@'], False)) +
        list(rename_val(manifest_xml, 'provider', 'process', ['@'], False)) +
        list(rename_val(manifest_xml, 'activity-alias', 'name', ['@'],
                        False)) +
        list(rename_val(manifest_xml, 'activity-alias', 'label', ['@'], False))
        + list(rename_val(manifest_xml, 'service', 'label', ['@'], False)) +
        list(rename_val(manifest_xml, 'service', 'process', ['@'], False)) +
        list(rename_val(manifest_xml, 'receiver', 'label', ['@'], False)) +
        list(rename_val(manifest_xml, 'receiver', 'process', ['@'], False)) +
        list(rename_val(manifest_xml, 'intent-filter', 'label', ['@'], False))
        + list(rename_val(manifest_xml, 'permission', 'label', ['@'], False)) +
        list(
            rename_val(manifest_xml, 'permission', 'description', ['@'], False)
        ) + list(
            rename_val(manifest_xml, 'permission-group', 'label', ['@'],
                       False)) + list(
                           rename_val(manifest_xml, 'permission-group',
                                      'description', ['@'], False)) +
        list(rename_val(manifest_xml, 'permission-tree', 'label', ['@'],
                        False)) +
        list(rename_val(
            manifest_xml, 'instrumentation', 'label', ['@'], False)) + list(
                rename_val(manifest_xml, 'action', 'name',
                           ['@', 'com.android.', 'android.'], False)) +
        list(
            rename_val(manifest_xml, 'activity', 'taskAffinity',
                       ['android.', 'com.android.', '@'], False, 'name',
                       task_affinity)) +
        list(
            rename_val(manifest_xml, 'application', 'taskAffinity',
                       ['android.', 'com.android.', '@'], False, 'name',
                       task_affinity)))
    log_tag_bho(manifest_xml, 'data')
    change_all_res_file_package(res_file_list, rename_list)
    u.save_manifest(manifest_xml)  # Write back the Manifest file'''
    fix_safe_test(smali_file_list)
    change_allfile(smali_file_list)
    change_alldir(u.load_smali_dirs())
Ejemplo n.º 4
0
def build_application(opt):
    """ Builds the application """
    basedir = util.smartpath(opt.appdir)
    projpath = partial(path.join,basedir)
    bld = projpath("build")
    buildpath = partial(path.join,bld)

    if path.exists(bld):
        print("removing build dir")
        shutil.rmtree(bld)
        os.mkdir(bld)
        
    if not path.isdir(basedir):
        raise BuildFailedError("Could not find the project dir") 

    manifest_file = projpath("manifest.yaml")

    if not path.isfile(manifest_file):
        raise BuildFailedError("Could not find manifest file") 

    manifest = util.load_manifest(manifest_file)

    json.dump(manifest,open(buildpath("manifest.json"),"w"))

    tr = util.TemplateRenderer()
    tr.add(manifest)

    #Spotify will compress for us
    scc = scss.Scss(scss_vars=manifest,
                    scss_opts={"compress": False}) 

    
    for filename in source_files(basedir):
        # WAT? - something.HtMl -> [something, .HtMl] -> "html"
        ext = path.splitext(filename)[1][1:].lower()
        
        data = open(projpath(filename)).read()
        
        if ext == "html":
            util.write_file(buildpath(filename),tr.render(data))
            print("[*] Rendered template {}".format(filename))
        elif ext == "scss":
            css = scc.compile(data)
            util.write_file(buildpath(filename),css)
            print("[*] Compiled SCSS {}".format(filename))
        elif ext == "coffee":
            js = util.coffee(data)
            util.write_file(buildpath(filename),js)
            print("[*] Compiled CoffeeScript {}".format(filename))
        else:
            data = open(projpath(filename)).read()
            util.write_file(buildpath(filename),data)            
            print("[*] Copied {}".format(filename))
Ejemplo n.º 5
0
def change_all_res_file(res_file_list):
    """Search in all the resource XML files a resource reference"""
    change_meta(u.load_manifest().getroot())
    for res_file in res_file_list:  # For each XML file
        if u.base_name(res_file) == 'strings.xml':  # Edit only the strings/colors resources
                ori_file_name = res_file
                purge_xml_tag_file(ori_file_name)
                res_file = res_file.replace(u.base_dir(), '')
                res_xml = u.load_xml(res_file)
                res_root = res_xml.getroot()
                change_match_res_string_file(res_root)
                u.save_xml(res_file, res_xml)
        if u.base_name(res_file) == 'arrays.xml' or u.base_name(res_file) == 'plurals.xml':  # Edit only the arrays/plurals resources
                ori_file_name = res_file
                purge_xml_tag_file(ori_file_name)
                res_file = res_file.replace(u.base_dir(), '')
                res_xml = u.load_xml(res_file)
                res_root = res_xml.getroot()
                change_match_res_array_file(res_root)
                u.save_xml(res_file, res_xml)
Ejemplo n.º 6
0
def change_all_res_file(res_file_list):
    """Search in all the resource XML files a resource reference"""
    change_meta(u.load_manifest().getroot())
    for res_file in res_file_list:  # For each XML file
        if u.base_name(
                res_file
        ) == 'strings.xml':  # Edit only the strings/colors resources
            ori_file_name = res_file
            purge_xml_tag_file(ori_file_name)
            res_file = res_file.replace(u.base_dir(), '')
            res_xml = u.load_xml(res_file)
            res_root = res_xml.getroot()
            change_match_res_string_file(res_root)
            u.save_xml(res_file, res_xml)
        if u.base_name(res_file) == 'arrays.xml' or u.base_name(
                res_file
        ) == 'plurals.xml':  # Edit only the arrays/plurals resources
            ori_file_name = res_file
            purge_xml_tag_file(ori_file_name)
            res_file = res_file.replace(u.base_dir(), '')
            res_xml = u.load_xml(res_file)
            res_root = res_xml.getroot()
            change_match_res_array_file(res_root)
            u.save_xml(res_file, res_xml)
Ejemplo n.º 7
0
#!/usr/bin/env python
import util

import os
import sys


if __name__ == '__main__':
    manifest = util.load_manifest("manifest.yaml")
    
    name = manifest["AppName"]["en"]

    url = "spotify:app:{}".format(name.lower())
    cf = "open {}" if sys.platform == "darwin" else "xdg-open {}"
    os.system(cf.format(url))
Ejemplo n.º 8
0
def init_package_name():
    global package_name
    package_name = u.load_manifest().getroot().get('package')