# coding:utf8 __author__ = '极无双' import os import logging import xml.dom.minidom import re import shutil import glob ANDROID_NS = 'http://schemas.android.com/apk/res/android' from xml.etree import ElementTree as ET def script(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo): modify_manifest(decompileDir, "com.excelliance.lbsdk.debug.LBSdkCrashReportService", "foregroundServiceType") modify_manifest(decompileDir, "com.excelliance.lbsdk.base.AssistService", "foregroundServiceType") modify_manifest(decompileDir, "com.excelliance.lbsdk.base.BaseService", "foregroundServiceType") modify_manifest(decompileDir, "com.excelliance.lbsdk.main.BGService", "foregroundServiceType") # modify_manifest_common(decompileDir, "dataExtractionRules") def script_last(SDK, decompileDir, channelSdkInfo, new_game_channel_info, gameInfo): # decompile_dir_path = os.path.join(decompileDir ) fix_coolyun_application_getinstance_null_bug(decompileDir) def modify_manifest(decompileDir, serviceName, key): ET.register_namespace('android', ANDROID_NS) xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml') root_node = ET.parse(xmlparse) root = root_node.getroot() name = '{' + ANDROID_NS + '}name' authorities = '{' + ANDROID_NS + '}' + key package_name = root.attrib.get('package') if package_name == None: return providers = root.findall('./application/service') if providers != None: for provider in providers: providerName = provider.attrib.get(name) if serviceName == providerName: try: del provider.attrib[authorities] # del provider.attrib[authoritiesTwo] except: "" root_node.write(xmlparse, 'utf-8') def modify_manifest_common(decompileDir, removeKey): ET.register_namespace('android', ANDROID_NS) xmlparse = os.path.join(decompileDir, 'AndroidManifest.xml') logging.info(xmlparse) root_node = ET.parse(xmlparse) root = root_node.getroot() name = '{' + ANDROID_NS + '}name' authorities = '{' + ANDROID_NS + '}' + removeKey package_name = root.attrib.get('package') if package_name == None: return providers = root.findall('./application') if providers != None: for provider in providers: try: del provider.attrib[authorities] except: "" root_node.write(xmlparse, 'utf-8') def fix_coolyun_application_getinstance_null_bug(decompile_dir): insert_str_list = [ '\n\t.locals 1\n\n', '\tsget-object v0, Lcom/coolyun/framework/CoolYunApplication;->application:Landroid/content/Context;\n\n', '\tcheck-cast v0, Lcom/coolyun/framework/CoolYunApplication;\n\n', '\treturn-object v0\n\n'] for dirpath, dirnames, filenames in os.walk(decompile_dir): if r'com\coolyun\framework' in dirpath and 'CoolYunApplication.smali' in filenames: smali_path = os.path.join(dirpath, 'CoolYunApplication.smali') with open(smali_path, 'r') as f: smali_str_arr = f.readlines() index_str = '.method public static getInstance()Lcom/coolyun/framework/CoolYunApplication;' end_method_str = '.end method' insert_str = ''.join(insert_str_list) on_create_index = 0 insert_index = 0 for line in smali_str_arr: if index_str in line: on_create_index = smali_str_arr.index(line) print('on_create_index', on_create_index, line) break for index, value in enumerate(smali_str_arr): if index > on_create_index and end_method_str in value: insert_index = index print('insert_index', index) break print(on_create_index, insert_index) del smali_str_arr[on_create_index + 1:insert_index] smali_str_arr.insert(on_create_index + 1, insert_str) with open(smali_path, 'w') as f: f.write(''.join(smali_str_arr)) break if __name__ == '__main__': ""