import xml.etree.ElementTree as ET from V1 import File, apk_utils import os import re from V1.PrintLog import printlog def getLauchActivityName(apkPath): sdkAM = "%s/AndroidManifest.xml" % apkPath namespace = '{http://schemas.android.com/apk/res/android}' ET.register_namespace('android', "http://schemas.android.com/apk/res/android") tree = ET.parse(sdkAM) activitys = tree.getroot().find("application").findall("activity"); for activity in activitys: filters = activity.findall('intent-filter') for filter in filters: categorys = filter.findall('category') for category in categorys: categoryname = category.attrib[namespace + "name"] if (categoryname == "android.intent.category.LAUNCHER"): actname = activity.attrib[namespace + "name"] return actname def getLauchActivityScreenOrientation(apkPath): sdkAM = "%s/AndroidManifest.xml" % apkPath namespace = '{http://schemas.android.com/apk/res/android}' ET.register_namespace('android', "http://schemas.android.com/apk/res/android") tree = ET.parse(sdkAM) activitys = tree.getroot().find("application").findall("activity"); for activity in activitys: filters = activity.findall('intent-filter') for filter in filters: categorys = filter.findall('category') for category in categorys: categoryname = category.attrib[namespace + "name"] if (categoryname == "android.intent.category.LAUNCHER"): screenOrientation = activity.attrib[namespace + "screenOrientation"] return screenOrientation def modifyLauchSmali(apkPath): TAG = "Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V" fc = "invoke-static {p0}, Lcom/yythird/sdk/BDInitAct;->initBD(Landroid/app/Activity;)V" smalipath = getLauchSmaliPath(apkPath) printlog("baidu smalipath: %s" % smalipath) lines = open(smalipath, "r").readlines() f = open(smalipath, "w") for line in lines: if line.find(TAG) != -1: line = line + '\n' + fc + '\n'; f.write(line) f.close() def getLauchSmaliPath(apkPath): sdkAM = "%s/AndroidManifest.xml"%apkPath tree = ET.parse(sdkAM) namespace = '{http://schemas.android.com/apk/res/android}' ET.register_namespace('android',"http://schemas.android.com/apk/res/android") activitys = tree.getroot().find("application").findall("activity"); for activity in activitys: filters = activity.findall('intent-filter') for filter in filters: categorys = filter.findall('category') actions = filter.findall('action') for category in categorys: categoryname = category.attrib[namespace + "name"] if(categoryname =="android.intent.category.LAUNCHER"): actname = activity.attrib[namespace + "name"].replace(".", "/") return "%s/smali/%s.smali"%(apkPath,actname) pass def modifyTTLauchSmali(apkPath): TAG = "invoke-super {p0, p1, p2, p3}, Landroid/app/Activity;->onRequestPermissionsResult(I[Ljava/lang/String;[I)V" TTSmali = "invoke-static {}, Lcom/wett/cooperation/container/TTSDKV2;->getInstance()Lcom/wett/cooperation/container/TTSDKV2;" smalipath = getLauchSmaliPath(apkPath) printlog("TT smalipath: %s" % smalipath) lines = open(smalipath, "r").readlines() if lines.find(TTSmali) != -1: f = open(smalipath, "w") for line in lines: if line.find(TTSmali) != -1: line = line + '\n' + TTSmali + '\n'; f.write(line) f.close() pass def modifyYXFLauchSmali(apkPath): oldText = ".super Landroid/app/Activity;" newText = ".super Lcom/yaoyue/release/YYSplashActivity;" oldActPkg = "Landroid/app/Activity;" newActPkg = "Lcom/yaoyue/release/YYSplashActivity;" smalipath = getLauchSmaliPath(apkPath) printlog("YXF smalipath: %s" % smalipath) lines = open(smalipath, "r").readlines() f = open(smalipath, "w") for line in lines: if line.find(oldText) != -1: line = re.sub(oldText,newText, line) if line.find(oldActPkg) != -1: line = re.sub(oldActPkg,newActPkg, line) f.write(line) f.close() pass def modifyQuickLauchSmali(apkPath): oldText = ".super Landroid/app/Activity;" newText = ".super Lcom/quicksdk/QuickSdkSplashActivity;" oldActPkg = "Landroid/app/Activity;" newActPkg = "Lcom/quicksdk/QuickSdkSplashActivity;" smalipath = getLauchSmaliPath(apkPath) printlog("Quick smalipath: %s" % smalipath) lines = open(smalipath, "r").readlines() f = open(smalipath, "w") for line in lines: if line.find(oldText) != -1: line = re.sub(oldText,newText, line) if line.find(oldActPkg) != -1: line = re.sub(oldActPkg,newActPkg, line) f.write(line) f.close() pass def modifyRfileIdSmali(prj_path,r_path): apkRfilePath = "%s%s" %(prj_path,r_path) publicXml = "%s/res/values/public.xml" % prj_path sdk_jar_dir = apk_utils.getToolsJarHome() jarPath = "%s/MergeSamli.jar" % sdk_jar_dir javaMerCm = 'java -jar %s %s %s' % (jarPath, publicXml, apkRfilePath) printlog("javaMerCm:%s" % javaMerCm) os.system(javaMerCm) pass def replaceSdkV4Smali(prj_path,v4_path): sdk_root_dir = apk_utils.getCutSdkRootHome() pkgV4Path = "%s/smali/android/support/v4" % prj_path printlog("pkgV4Path:%s" % pkgV4Path) sdkV4Path = "%s/%s" % (sdk_root_dir,v4_path) printlog("sdkV4Path:%s" % sdkV4Path) if os.path.exists(pkgV4Path): File.copyAllFile(sdkV4Path, pkgV4Path) pass def modifyJrttV7ResIdSmali(prj_path): pkgV7AttrPath = "%s/smali_classes3/android/support/v7/appcompat/R$attr.smali" % prj_path if os.path.exists(pkgV7AttrPath): pkgV7StyleablePath = r"%s/smali_classes3/android/support/v7/appcompat/R\$styleable.smali" % prj_path data = ["windowActionBar:I", "windowActionBarOverlay:I", "windowActionModeOverlay:I", "windowFixedHeightMajor:I", "windowFixedHeightMinor:I", "windowFixedWidthMajor:I", "windowFixedWidthMinor:I", "windowMinWidthMajor:I", "windowMinWidthMinor:I", "windowNoTitle:I"] with open(pkgV7AttrPath, "r") as f: for line in f.readlines(): if data[0] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f040245/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[1] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f040246/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[2] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f040247/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[3] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f040248/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[4] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f040249/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[5] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f04024a/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[6] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f04024b/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[7] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f04024c/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[8] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f04024d/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) elif data[9] in line: value = line.split("=") replaceShell = 'sed -i "s/0x7f04024e/%s/g" %s' % (value[1].strip(), pkgV7StyleablePath) os.system(replaceShell) pass