示例#1
0
def modify_manifest(channel, decompile_dir, package_name):
    manifest_file = decompile_dir + '/AndroidManifest.xml'
    ET.register_namespace('android', androidNS)
    tree = ET.parse(manifest_file)
    root = tree.getroot()
    app_node = root.find('application')
    # 修改游戏名称
    if len(channel['gameName']) > 0:
        label = app_node.get('{' + androidNS + '}label')
        if label.find('@string/') == 0:
            app_name = label[8:len(label)]
        else:
            app_name = 'app_name'
            app_node.set('{' + androidNS + '}label', '@string/' + app_name)
        activity_node_lst = app_node.findall('activity')
        for activity_node in activity_node_lst:
            if activity_node.get('{' + androidNS + '}label') is not None:
                activity_node.set('{' + androidNS + '}label',
                                  '@string/' + app_name)
        string_file = decompile_dir + '/res/values/strings.xml'
        string_tree = ET.parse(string_file)
        strings = string_tree.getroot().findall('string')
        for string in strings:
            if string.get('name') == app_name:
                string_tree.getroot().remove(string)
                break
        string_node = SubElement(string_tree.getroot(), 'string',
                                 {'name': app_name})
        string_node.text = channel['gameName']
        string_tree.write(string_file,
                          xml_declaration=True,
                          encoding='utf-8',
                          method='xml')
        LogUtils.info('modify game name: %s', channel['gameName'])
    # 写入meta-data
    key = '{' + androidNS + '}name'
    val = '{' + androidNS + '}value'
    meta_data_list = app_node.findall('meta-data')
    if meta_data_list is not None:
        for metaDataNode in meta_data_list:
            key_name = metaDataNode.attrib[key]
            for child in channel['sdkParams']:
                if key_name == child['name'] and child['writeIn'] == '1':
                    LogUtils.warning(
                        'the meta-data node %s repeated. remove it .',
                        key_name)
                    app_node.remove(metaDataNode)
    for child in channel['sdkParams']:
        if child['writeIn'] is not None and child['writeIn'] == '1':
            meta_node = SubElement(app_node, 'meta-data')
            meta_node.set(key, child['name'])
            meta_node.set(val, child['value'])
            LogUtils.info('writeIn meta-data: %s=%s', child['name'],
                          child['value'])
    # 修改替换包名占位符
    xml_str = ET.tostring(root, 'utf-8').decode('utf-8')
    if xml_str.find('NEW_PACKAGE_NAME') != -1:
        LogUtils.info('modify package name: %s', package_name)
        xml_str = xml_str.replace('NEW_PACKAGE_NAME', package_name)
        root = ET.fromstring(xml_str)

    Utils.indent(root)
    tree = ET.ElementTree(root)
    tree.write(manifest_file,
               xml_declaration=True,
               encoding='utf-8',
               method='xml')
    LogUtils.info('The manifestFile modify successfully')
示例#2
0
def copy_ext_res(game, decompile_dir):
    ext_res_path = 'games/' + game['id'] + '/ext'
    ext_res_path = Utils.get_full_path(ext_res_path)
    if os.path.exists(ext_res_path):
        LogUtils.warning('the game ext res path: %s', ext_res_path)
        Utils.copy_file(ext_res_path, decompile_dir)