def mergeValuePublicXML(): global backupPath if (isNeedMergeValues_Public): print("start to merge values/public.xml......") else: print("no need to merge values/public.xml.") return #backing up file backAndroidManifest.xml if (os.path.exists(backupPath + "/public.xml") == 0): print("public.xml is not exists.start backup...") FileUtils.doCopy(gameApkPath + "/res/values/public.xml", backupPath) if (os.path.exists(backupPath + "/public.xml") == 0): print("[error]backup public.xml failed.") return #recover file from backup if (os.path.isfile(gameApkPath + "/res/values/public.xml")): FileUtils.delFile(gameApkPath + "/res/values/public.xml") FileUtils.doCopy(backupPath + "/public.xml", gameApkPath + "/res/values/") gamePublicXMLPath = gameApkPath + "/res/values/public.xml" sdkPublicXMLPath = sdkApkPath + "/res/values/public.xml" core = Core(gamePublicXMLPath, sdkPublicXMLPath) core.run() print("end merge values/public.xml") return
def copyAssets(): if (isNeedCopyAssets): print("start copy assets......") else: print("no need to copy assets.") return FileUtils.doCopy(sdkApkPath + "/assets", gameApkPath + "/assets") print("end copy assets.") return
def copyResCommon(): if (isNeedCopyResCommon): print("start copy resource common......") else: print("no need to copy resource common.") return FileUtils.doCopy(sdkApkPath + "/res", gameApkPath + "/res") print("end copy res common") return
def copySmali(): if (isNeedCopySmali): print("start copy smali......") else: print("no need to copy smali.") return FileUtils.doCopy(sdkApkPath + "/smali", gameApkPath + "/smali") print("end copy smali.") return
def copyUnkown(): if (isNeedCopyUnknown): print("start copy unknown......") else: print("no need to copy unknown.") return FileUtils.doCopy(sdkApkPath + "/unknown", gameApkPath + "/unknown") print("end copy unknown.") return
def copyLibSO(): if (isNeedCopyLibSo): print("start copy lib so......") else: print("no need to copy lib so.") return FileUtils.doCopy(sdkApkPath + "/lib", gameApkPath + "/lib") print("end copy lib so.") return
def mergeValueIds(): global backupPath if (isNeedMergeValues_Ids): print("start to merge values/ids.xml......") else: print("no need to merge values/ids.xml.") return #backing up file ids.xml if (os.path.exists(backupPath + "/ids.xml") == 0): print("ids.xml is not exists.start backup...") FileUtils.doCopy(gameApkPath + "/res/values/ids.xml", backupPath) if (os.path.exists(backupPath + "/ids.xml") == 0): print("[error]backup ids.xml failed.") return #recover file from backup if (os.path.isfile(gameApkPath + "/res/values/ids.xml")): FileUtils.delFile(gameApkPath + "/res/values/ids.xml") FileUtils.doCopy(backupPath + "/ids.xml", gameApkPath + "/res/values/") gameIdsXMLPath = gameApkPath + "/res/values/ids.xml" tempIdsXMLPath = gameApkPath + "/res/values/temp_ids.xml" gameIdsXMLBakPath = gameApkPath + "/res/values/ids.xml.bak" gameIdsList = [] gameIdsXML = open(gameIdsXMLPath) for line in gameIdsXML: gameIdsList.append(line.replace(" ", "")) gameIdsXML.close() sdkIdsList = [] sdkIdsXML = open(sdkApkPath + "/res/values/ids.xml") for line in sdkIdsXML: str = line.replace(" ", "") if (str.__contains__("<itemtype=\"id\"") and not gameIdsList.__contains__(str)): sdkIdsList.append(line) sdkIdsXML.close() mergeFile = open(tempIdsXMLPath, "w+") gameColorsXML = open(gameIdsXMLPath) for line in gameColorsXML: if (line.__contains__("</resources>")): for color in sdkIdsList: mergeFile.write(color) mergeFile.write(line) else: mergeFile.write(line) mergeFile.flush() mergeFile.close() gameColorsXML.close() FileUtils.rename(gameIdsXMLPath, gameIdsXMLBakPath) FileUtils.rename(tempIdsXMLPath, gameIdsXMLPath) FileUtils.delFile(gameIdsXMLBakPath) print("end merge values/ids.xml") return
def mergeValueStyles(): global backupPath if (isNeedMergeValues_Styles): print("start to merge values/styles.xml......") else: print("no need to merge values/styles.xml.") return #backing up file styles.xml if (os.path.exists(backupPath + "/res/values/styles.xml") == 0): print("styles.xml is not exists.start backup...") FileUtils.doCopy(gameApkPath + "/res/values/styles.xml", backupPath) if (os.path.exists(backupPath + "/styles.xml") == 0): print("[error]backup styles.xml failed.") return #recover file from backup if (os.path.isfile(gameApkPath + "/res/values/styles.xml")): FileUtils.delFile(gameApkPath + "/res/values/styles.xml") FileUtils.doCopy(backupPath + "/styles.xml", gameApkPath + "/res/values/") gameStyleXMLPath = gameApkPath + "/res/values/styles.xml" tempStyleXMLPath = gameApkPath + "/res/values/temp_styles.xml" gameStyleXMLBakPath = gameApkPath + "/res/values/styles.xml.bak" sdkStyleXMLPath = sdkApkPath + "/res/values/styles.xml" gameStyleList = [] appendStyleList = [] gameStyleXML = open(gameStyleXMLPath) for line in gameStyleXML: line = line.replace(" ", "") if (line.__contains__("<stylename")): gameStyleList.append(line) gameStyleXML.close() sdkStyleXML = open(sdkStyleXMLPath) appendFlag = False for line in sdkStyleXML: str = line.replace(" ", "") if (str.__contains__("<stylename") and not gameStyleList.__contains__(str)): appendFlag = True appendStyleList.append(line) elif (gameStyleList.__contains__(str)): appendFlag = False elif (str.__contains__("</style>" or str.__contains__("/>"))): if (appendFlag): appendFlag = False appendStyleList.append(line) elif (appendFlag): appendStyleList.append(line) sdkStyleXML.close() mergeFile = open(tempStyleXMLPath, "w+") gameStyleXML = open(gameStyleXMLPath) for line in gameStyleXML: if (line.__contains__("</resources>")): for style in appendStyleList: mergeFile.write(style) mergeFile.write(line) else: mergeFile.write(line) mergeFile.flush() mergeFile.close() gameStyleXML.close() FileUtils.rename(gameStyleXMLPath, gameStyleXMLBakPath) FileUtils.rename(tempStyleXMLPath, gameStyleXMLPath) FileUtils.delFile(gameStyleXMLBakPath) print("end merge values/styles.xml") return
def mergeAndroidManifest(): global configMetaList, backupPath, gameApkPath, configSplashList, isNeedSplash, configProviderList, isNeedProvider if (isNeedCopyAndroidManifest): print("start merge androidManifest.xml......") else: print("no need to merge androidManifest.") return #check folder "bak" whether exists if (os.path.exists(backupPath) == 0): os.mkdir(backupPath) #backing up file backAndroidManifest.xml if (os.path.exists(backupPath + "/AndroidManifest.xml") == 0): print("AndroidManifest.xml is not exists.start backup...") FileUtils.doCopy(gameApkPath + "/AndroidManifest.xml", backupPath) if (os.path.exists(backupPath + "/AndroidManifest.xml") == 0): print("[error]backup AndroidManifest.xml failed.") return #recover file from backup if (os.path.isfile(gameApkPath + "/AndroidManifest.xml")): FileUtils.delFile(gameApkPath + "/AndroidManifest.xml") FileUtils.doCopy(backupPath + "/AndroidManifest.xml", gameApkPath) setPackageName() gameXmlList = [] sdkXmlPermissionList = [] sdkXmlContentList = [] gameXML = open(gameApkPath + "/AndroidManifest.xml") for line in gameXML: gameXmlList.append(line.replace(" ", "")) gameXML.close() print("len of gameXmlList is " + str(gameXmlList.__len__())) sdkXML = open(sdkApkPath + "/AndroidManifest.xml") flagStrPermission = False flagStrActivity = False flagStrService = False flagStrProvider = False flagStrReceiver = False for line in sdkXML: if (line.__contains__("android.intent.action.MAIN") and not isNeedSplash): continue if (flagStrPermission): sdkXmlPermissionList.append(line) if (line.__contains__("/>")): flagStrPermission = False if (line.__contains__("<uses-permission")): if (not gameXmlList.__contains__(line.replace(" ", ""))): sdkXmlPermissionList.append(line) if (not line.__contains__("/>")): flagStrPermission = True if (flagStrActivity): sdkXmlContentList.append(line) if (line.__contains__("</activity>")): flagStrActivity = False if (line.__contains__("<activity")): sdkXmlContentList.append(line) if (not line.__contains__("/>")): flagStrActivity = True if (flagStrService): sdkXmlContentList.append(line) if (line.__contains__("</service>")): flagStrService = False if (line.__contains__("<service")): sdkXmlContentList.append(line) if (not line.__contains__("/>")): flagStrService = True if (flagStrProvider): sdkXmlContentList.append(line) if (line.__contains__("</provider>")): flagStrProvider = False if (line.__contains__("<provider")): sdkXmlContentList.append(line) if (not line.__contains__("/>")): flagStrProvider = True if (flagStrReceiver): sdkXmlContentList.append(line) if (line.__contains__("</receiver>")): flagStrReceiver = False if (line.__contains__("<receiver")): sdkXmlContentList.append(line) if (not line.__contains__("/>")): flagStrReceiver = True elif (line.__contains__("<meta-data")): sdkXmlContentList.append(line) sdkXML.close() for m in configMetaList: sdkXmlContentList.append(m) # start to read gameXML = open(gameApkPath + "/AndroidManifest.xml") mergeFile = open(gameApkPath + "/temp_AndroidManifest.xml", "w+") tagProvider = False for line in gameXML: if (line.__contains__("<application")): for p in sdkXmlPermissionList: mergeFile.write(p) mergeFile.write(line) elif (line.__contains__("</application>")): for c in sdkXmlContentList: if (isNeedProvider): t = str(configProviderList[0]).replace("\n", "") if (c.__contains__("<provider") and c.__contains__(t)): c = c.replace(t, packageName) elif (c.__contains__("<provider")): tagProvider = True elif (tagProvider and c.__contains__(configProviderList[0])): c = c.replace(configProviderList[0], packageName) elif (c.__contains__("/>")): tagProvider = False mergeFile.write(c) mergeFile.write(line) else: if (line.__contains__("android.intent.action.MAIN")): if (isNeedSplash): line = line.replace("android.intent.action.MAIN", configSplashList[0]) if (line.__contains__("android.intent.category.LAUNCHER")): if (isNeedSplash): line = "<category android:name=\"android.intent.category.DEFAULT\" />" mergeFile.write(line) mergeFile.close() gameXML.close() # rename temp_AndroidManifest.xml FileUtils.delFile(gameApkPath + "/AndroidManifest.xml") FileUtils.rename(gameApkPath + "/temp_AndroidManifest.xml", gameApkPath + "/AndroidManifest.xml") print("end merge androidManifest.xml.") return