def signApk(apkFile, keyStore, storepassword, keyalias, aliaspassword): if not os.path.exists(keyStore): print keyStore return 0 apkFile = file_operate.getFullPath(apkFile) keyStore = file_operate.getFullPath(keyStore) aapt = file_operate.getToolPath('aapt') listcmd = '%s list %s' % (aapt, apkFile) listcmd = listcmd.encode('gb2312') output = os.popen(listcmd).read() for filename in output.split('\n'): if filename.find('META-INF') == 0: rmcmd = '"%s" remove "%s" "%s"' % (aapt, apkFile, filename) bReturn = file_operate.execFormatCmd(rmcmd) jarsingnCmd = '"%sjarsigner" -keystore "%s" -storepass "%s" -keypass "%s" "%s" "%s" -sigalg SHA1withRSA -digestalg SHA1' % ( file_operate.getJavaBinDir(), keyStore, storepassword, aliaspassword, apkFile, keyalias) print jarsingnCmd ret = file_operate.execFormatCmd(jarsingnCmd) if ret: error_operate.error(140) return 1 return 0
def processAdvertising(channel, checkBox_2_isChecked, comboBox_6_currentText): if not checkBox_2_isChecked: return advertisingPath = file_operate.getAdvertisingPath() thirdAdvertisingName = comboBox_6_currentText thirdAdvertisingPath = advertisingPath + '/' + str(thirdAdvertisingName) print "..........", thirdAdvertisingPath file_operate.copyFiles(thirdAdvertisingPath + "/jar", constant.tmpPath + '/' + channel + "/jar") if platform.system() == 'Windows': dxTool = file_operate.getToolPath('dx.bat') else: dxTool = file_operate.getToolPath('dx') # cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath+'/'+channel+"/classes.dex"), file_operate.getFullPath(constant.tmpPath+'/'+channel+"/jar")) #合并jar cmd = '"%s" --multi-dex --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath + '/' + channel), file_operate.getFullPath(constant.tmpPath + '/' + channel + "/jar")) # 合并jar print "cmd" + cmd ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(104) return if (os.path.exists(thirdAdvertisingPath + "/advertisingScript.pyc")): file_operate.copyFile(thirdAdvertisingPath + "/advertisingScript.pyc", file_operate.getFullPath(constant.tmpPath + '/' + channel) + "/advertisingScript.pyc") # 合并ForManifest.xml manifestFile = file_operate.getFullPath(constant.tmpPath + '/' + channel + "/ForManifest.xml") ET.register_namespace('android', constant.androidNS) targetTree = ET.parse(manifestFile) targetRoot = targetTree.getroot() haveChanged = modifyManifest.doModifyForManifest(manifestFile, thirdAdvertisingPath + "/ForManifest.xml", targetRoot) if haveChanged: targetTree.write(manifestFile, 'UTF-8')
def CreateTmpFolder(channel): tmp = file_operate.getFullPath(constant.tmpPath) if not os.path.exists(tmp): os.makedirs(tmp) tmp_channel = file_operate.getFullPath(constant.tmpPath + '/' + channel) if os.path.exists(tmp_channel): file_operate.delete_file_folder(tmp_channel) if not os.path.exists(tmp_channel): os.makedirs(tmp_channel)
def GetSplashImage(self, url, channel): DownloadDir = file_operate.getFullPath("Download/") response = urllib2.urlopen(url, timeout=60) img_buff = StringIO(response.read()) img = Image.open(img_buff) if not os.path.exists(DownloadDir + 'Splash/' + channel): os.makedirs(DownloadDir + 'Splash/' + channel) icon = img.resize((495, 280), Image.ANTIALIAS) icon.save( file_operate.getFullPath(DownloadDir + 'Splash/' + channel + '/fun_plugin_splash.png'))
def processMedia(channel, checkBox_voice_isChecked, comboBox_voice_currentText): print"----------begin processMedia--------------" if not checkBox_voice_isChecked: return print"----------select path--------------" mediaPath = file_operate.getMediaPath() print "path= "+comboBox_voice_currentText thirdMediaName = unicode(comboBox_voice_currentText) thirdMediaPath = mediaPath + '/' + thirdMediaName print "thirdMediaPath= "+thirdMediaPath file_operate.copyFiles(thirdMediaPath + "/jar", constant.tmpPath + '/' + channel + "/jar") print"----------select windows--------------" if platform.system() == 'Windows': dxTool = file_operate.getToolPath('dx.bat') else: dxTool = file_operate.getToolPath('dx') # cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath+'/'+channel+"/classes.dex"), file_operate.getFullPath(constant.tmpPath+'/'+channel+"/jar")) #合并jar cmd = '"%s" --multi-dex --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath + '/' + channel), file_operate.getFullPath(constant.tmpPath + '/' + channel + "/jar")) # 合并jar ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(104) return print"-----------copy libs-------------" # copy libs targetDir = file_operate.getFullPath(constant.tmpPath + '/' + channel) oldApkDir = targetDir + "/oldApkDir" if os.path.exists(thirdMediaPath + "/ForLibs"): if os.path.exists(oldApkDir + "/lib/armeabi") and os.path.exists(thirdMediaPath + "/ForLibs/armeabi"): operate.copyResToApk(thirdMediaPath + "/ForLibs/armeabi", oldApkDir + "/lib/armeabi") if os.path.exists(oldApkDir + "/lib/armeabi-v7a") and os.path.exists(thirdMediaPath + "/ForLibs/armeabi-v7a"): operate.copyResToApk(thirdMediaPath + "/ForLibs/armeabi-v7a", oldApkDir + "/lib/armeabi-v7a") if os.path.exists(oldApkDir + "/lib/x86") and os.path.exists(thirdMediaPath + "/ForLibs/x86"): operate.copyResToApk(thirdMediaPath + "/ForLibs/x86", oldApkDir + "/lib/x86") print"-----------copy res-------------" # copy res if os.path.exists(thirdMediaPath + "/ForRes"): operate.copyResToApk(thirdMediaPath + "/ForRes", oldApkDir + "/res") print"-----------copy pushScript-------------" # copy pushScript file_operate.copyFile(thirdMediaPath + "/pushScript.pyc", targetDir + "/pushScript.pyc") print"----------- ForManifest-------------" # 合并ForManifest.xml manifestFile = file_operate.getFullPath(constant.tmpPath + '/' + channel + "/ForManifest.xml") ET.register_namespace('android', constant.androidNS) targetTree = ET.parse(manifestFile) targetRoot = targetTree.getroot() print"-----------write-------------" haveChanged = modifyManifest.doModifyForManifest(manifestFile, thirdMediaPath + "/ForManifest.xml", targetRoot) if haveChanged: targetTree.write(manifestFile, 'UTF-8') print"-----------comeplete-------------"
def DownloadChannelIcon2ChannelDir(self, url, channel): response = urllib2.urlopen(url) img_buff = StringIO(response.read()) img = Image.open(img_buff) if not os.path.exists( file_operate.getFullPath(constant.sdkRelatePath + channel + '/icon')): os.makedirs( file_operate.getFullPath(constant.sdkRelatePath + channel + '/icon')) img.save( file_operate.getFullPath(constant.sdkRelatePath + channel + '/icon/icon.png'))
def smaliTrans2dex(smaliDir, targetFile): smaliDir = file_operate.getFullPath(smaliDir) targetFile = file_operate.getFullPath(targetFile) smaliFile = file_operate.getToolPath('smali.jar') cmd = '"%s" -jar -Xms512m -Xmx512m "%s" "%s" -o "%s"' % ( file_operate.getJava(), smaliFile, smaliDir, targetFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(50) return 1 else: file_operate.delete_file_folder('file/smali') return 0
def packResIntoApk(SDKWorkDir, SDK, decompileDir, packageName, usrSDKConfig): SDKDir = SDKWorkDir + SDK['SDKName'] for child in SDK['operateLs']: if child['name'] == 'modifyManifest': modifyFrom = child['from'] modifyTo = child['to'] if modifyFrom == None and modifyTo == None: file_operate.printf( 'Operate error, Please check your config in funcellconfig.xml' ) error_operate.error(100) return 1 modifyFrom = None.path.join(SDKDir, modifyFrom) modifyTo = os.path.join(decompileDir, modifyTo) modifyFrom = file_operate.getFullPath(modifyFrom) modifyTo = file_operate.getFullPath(modifyTo) modifyManifest.modify(modifyTo, modifyFrom, SDK['SDKName'], usrSDKConfig) continue if child['name'] == 'copy': copyFrom = child['from'] copyTo = child['to'] if copyFrom == None and copyTo == None: file_operate.printf( 'Operate error, Please check your config in funcellconfig.xml' ) error_operate.error(101) return 1 copyFrom = None.path.join(SDKDir, copyFrom) copyFrom = file_operate.getFullPath(copyFrom) copyTo = os.path.join(decompileDir, copyTo) copyTo = file_operate.getFullPath(copyTo) copyResToApk(copyFrom, copyTo) if child['to'] == 'lib': armPath = os.path.join(copyFrom, 'armeabi') armv7To = os.path.join(copyTo, 'armeabi-v7a') if os.path.exists(armPath) and os.path.exists(armv7To): copyResToApk(armPath, armv7To) if child['name'] == 'script': scriptPath = SDKDir + '/script.pyc' if os.path.exists(scriptPath): sys.path.append(SDKDir) import script script.script(SDK, decompileDir, packageName, usrSDKConfig) del sys.modules['script'] sys.path.remove(SDKDir) return 0
def processStatistics(channel, checkBox_isChecked, comboBox_4_currentText): if not checkBox_isChecked: return statisticsPath = file_operate.getStatisticsPath() thirdStatisticsName = comboBox_4_currentText thirdStatisticsPath = statisticsPath + '/' + str(thirdStatisticsName) print "..........", thirdStatisticsPath file_operate.copyFiles(thirdStatisticsPath + "/jar", constant.tmpPath + '/' + channel + "/jar") if platform.system() == 'Windows': dxTool = file_operate.getToolPath('dx.bat') else: dxTool = file_operate.getToolPath('dx') # cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath+'/'+channel+"/classes.dex"), file_operate.getFullPath(constant.tmpPath+'/'+channel+"/jar")) #合并jar cmd = '"%s" --multi-dex --dex --output="%s" "%s"' % (dxTool, file_operate.getFullPath(constant.tmpPath + '/' + channel), file_operate.getFullPath(constant.tmpPath + '/' + channel + "/jar")) # 合并jar print "cmd" + cmd ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(104) return # copy libs targetDir = file_operate.getFullPath(constant.tmpPath + '/' + channel) oldApkDir = targetDir + "/oldApkDir" if os.path.exists(statisticsPath + "/ForLibs"): if os.path.exists(oldApkDir + "/lib/armeabi") and os.path.exists(statisticsPath + "/ForLibs/armeabi"): operate.copyResToApk(statisticsPath + "/ForLibs/armeabi", oldApkDir + "/lib/armeabi") if os.path.exists(oldApkDir + "/lib/armeabi-v7a") and os.path.exists(statisticsPath + "/ForLibs/armeabi-v7a"): operate.copyResToApk(statisticsPath + "/ForLibs/armeabi-v7a", oldApkDir + "/lib/armeabi-v7a") if os.path.exists(oldApkDir + "/lib/x86") and os.path.exists(statisticsPath + "/ForLibs/x86"): operate.copyResToApk(statisticsPath + "/ForLibs/x86", oldApkDir + "/lib/x86") # copy res if os.path.exists(statisticsPath + "/ForRes"): operate.copyResToApk(statisticsPath + "/ForRes", oldApkDir + "/res") if (os.path.exists(thirdStatisticsPath + "/statisticsScript.pyc")): file_operate.copyFile(thirdStatisticsPath + "/statisticsScript.pyc", file_operate.getFullPath(constant.tmpPath + '/' + channel) + "/statisticsScript.pyc") # 合并ForManifest.xml manifestFile = file_operate.getFullPath(constant.tmpPath + '/' + channel + "/ForManifest.xml") ET.register_namespace('android', constant.androidNS) targetTree = ET.parse(manifestFile) targetRoot = targetTree.getroot() haveChanged = modifyManifest.doModifyForManifest(manifestFile, thirdStatisticsPath + "/ForManifest.xml", targetRoot) if haveChanged: targetTree.write(manifestFile, 'UTF-8')
def downloadExe(self, url, md5): UpdateDir = file_operate.getFullPath("Update/") if not os.path.exists(UpdateDir): os.makedirs(UpdateDir) # f = urllib2.urlopen(url) # data = f.read() # with open(UpdateDir+'FuncellSDKTool.exe', "wb") as code: # code.write(data) #此步骤为判断当前请求链接是否有效 try: res = urllib2.urlopen(urllib2.Request(url), timeout=60) code = res.getcode() res.close() print 'code:', code if code != 200: file_operate.reportError( "", "", 'url:%s 下载失败,请检查当前网络... Exception:%s' % (url)) return False except Exception, e: print 'e:', e file_operate.reportError( "", "", 'url:%s 下载失败,请检查当前网络... Exception:%s' % (url, e)) return False
def readConfig(self, type): """ read config from config/user.xml @param type: 1:apk src 2:out dir 3:user name """ configPath = '../config/user.xml' configPath = file_operate.getFullPath(configPath) if not os.path.exists(configPath): return targetTree = ET.parse(configPath) targetRoot = targetTree.getroot() if targetRoot is None: return dataLsNode = targetRoot.findall('data') if dataLsNode is None: return for dataNode in dataLsNode: dictTemp = {} dictTemp['type'] = dataNode.get('type') dictTemp['data1'] = dataNode.get('data1') dictTemp['data2'] = dataNode.get('data2') dictTemp['data3'] = dataNode.get('data3') dictTemp['data4'] = dataNode.get('data4') dictTemp['data5'] = dataNode.get('data5') dictTemp['desc'] = dataNode.get('desc') if dictTemp['type'] is not None and int(dictTemp['type']) == type: return dictTemp
def GetChannelIcon(self, url, channel): # img_buff = urllib.urlopen(url).read() # urllib.urlretrieve(img_buff[0],file_operate.getFullPath(constant.sdkRelatePath+'/icon/icon.png')) channel = channel.split('_')[0] + '/' + channel.split('_')[1] # print 'channel:%s \r' %channel DownloadDir = file_operate.getFullPath("Download/") response = urllib2.urlopen(url, timeout=60) img_buff = StringIO(response.read()) img = Image.open(img_buff) # utils.taskManagerModule.taskManager.shareInstance().getIconLock().acquire() if not os.path.exists( file_operate.getFullPath(DownloadDir + 'Icon/' + channel + '/server')): os.makedirs( file_operate.getFullPath(DownloadDir + 'Icon/' + channel + '/server')) img.save( file_operate.getFullPath(DownloadDir + 'Icon/' + channel + '/server' + '/icon.png')) if os.path.exists( file_operate.getFullPath('Download/Icon/' + channel + '/server' + '/icon.png')): img = Image.open( file_operate.getFullPath('Download/Icon/' + channel + '/server' + '/icon.png')) icon = img.resize((60, 60), Image.ANTIALIAS) icon.save( file_operate.getFullPath('Download/Icon/' + channel + '/server' + '/channel.png'))
def recompileApk(srcFolder, apkFile, apkTool='apktool2.jar'): """ recompile Apk after decompile apk. """ os.chdir(file_operate.curDir) apkFile = file_operate.getFullPath(apkFile) srcFolder = file_operate.getFullPath(srcFolder) apkTool = file_operate.getToolPath(apkTool) print "apkTool" + apkTool print "java" + file_operate.getJava() if os.path.exists(srcFolder): cmd = '"%s" -jar -Xms512m -Xmx512m "%s" -q b -f "%s" -o "%s"' % ( file_operate.getJava(), apkTool, srcFolder, apkFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(130) return 1 else: return 0
def decompileApk(apkFile, targetDir, apkTool='apktool2.jar'): """ Decompile apk """ apkFile = file_operate.getFullPath(apkFile) targetDir = file_operate.getFullPath(targetDir) apkTool = file_operate.getToolPath(apkTool) if os.path.exists(targetDir): file_operate.delete_file_folder(targetDir) if not os.path.exists(targetDir): os.makedirs(targetDir) cmd = '"%s" -jar -Xms512m -Xmx512m "%s" -q d -b -f "%s" -o "%s"' % ( file_operate.getJava(), apkTool, apkFile, targetDir) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(80) return 1 else: return 0
def backupApk(source, channel): outputDir = constant.tmpPath backupName = '%s/%s/common.apk' % (outputDir, channel) backupName = file_operate.getFullPath(backupName) print "backupname" + backupName if os.path.exists(backupName): os.remove(backupName) print "source " + source file_operate.copyFile(source, backupName)
def modify(manifestFile, sourceCfgFile, pluginName, usrSDKConfig): manifestFile = file_operate.getFullPath(manifestFile) sourceXml = sourceCfgFile sourceXml = file_operate.getFullPath(sourceXml) if not os.path.exists(sourceXml): ForManifestDir = os.path.dirname(sourceXml) screenOrientation = getOrientation(manifestFile, usrSDKConfig) if screenOrientation == 'landscape' or screenOrientation == 'auto': sourceXml = ForManifestDir + '/ForManifestLandscape.xml' else: sourceXml = ForManifestDir + '/ForManifestPortrait.xml' if not os.path.exists(sourceXml): return ET.register_namespace('android', androidNS) targetTree = ET.parse(manifestFile) targetRoot = targetTree.getroot() haveChanged = doModify(manifestFile, sourceXml, targetRoot) if haveChanged: file_operate.printf('Modify AndroidManifest.xml for plugin ' + pluginName) targetTree.write(manifestFile, 'UTF-8')
def DownloadChannelSplash2ChannelDir(self, url, horizontal, channel_type): channelDir = file_operate.getFullPath(constant.sdkRelatePath + channel_type) ForSplashDir = channelDir + '/ForSplash' if horizontal: dir = ForSplashDir + '/landscape' drawableSize = (480, 320) hdpiSize = (800, 480) ldpiSize = (320, 240) mdpiSize = (480, 320) xhdpiSize = (1280, 720) else: dir = ForSplashDir + '/portrait' drawableSize = (320, 480) hdpiSize = (480, 800) ldpiSize = (240, 320) mdpiSize = (320, 480) xhdpiSize = (720, 1280) drawable = dir + '/drawable' drawablehdpi = dir + '/drawable-hdpi' drawableldpi = dir + '/drawable-ldpi' drawablemdpi = dir + '/drawable-mdpi' drawablexhdpi = dir + '/drawable-xhdpi' if not os.path.exists(drawable): os.makedirs(drawable) if not os.path.exists(drawablehdpi): os.makedirs(drawablehdpi) if not os.path.exists(drawableldpi): os.makedirs(drawableldpi) if not os.path.exists(drawablemdpi): os.makedirs(drawablemdpi) if not os.path.exists(drawablexhdpi): os.makedirs(drawablexhdpi) response = urllib2.urlopen(url, timeout=60) img_buff = StringIO(response.read()) img = Image.open(img_buff) drawableIcon = img.resize(drawableSize, Image.ANTIALIAS) hdpiIcon = img.resize(hdpiSize, Image.ANTIALIAS) ldpiIcon = img.resize(ldpiSize, Image.ANTIALIAS) mdpiIcon = img.resize(mdpiSize, Image.ANTIALIAS) xhdpiIcon = img.resize(xhdpiSize, Image.ANTIALIAS) splashIconName = 'fun_plugin_splash.png' drawableIcon.save(os.path.join(drawable, splashIconName), 'PNG') hdpiIcon.save(os.path.join(drawablehdpi, splashIconName), 'PNG') ldpiIcon.save(os.path.join(drawableldpi, splashIconName), 'PNG') mdpiIcon.save(os.path.join(drawablemdpi, splashIconName), 'PNG') xhdpiIcon.save(os.path.join(drawablexhdpi, splashIconName), 'PNG')
def dexTrans2Smali(dexFile, targetDir, step, baksmali='baksmali.jar'): if not os.path.exists(targetDir): os.mkdir(targetDir) if os.path.exists(dexFile): dexFile = file_operate.getFullPath(dexFile) smaliFile = file_operate.getToolPath(baksmali) targetDir = file_operate.getFullPath(targetDir) cmd = '"%s" -jar -Xms512m -Xmx512m "%s" -o "%s" "%s"' % ( file_operate.getJava(), smaliFile, targetDir, dexFile) ret = file_operate.execFormatCmd(cmd) if ret: if step == 3: error_operate.error(30) return 1 elif step == 4: error_operate.error(40) return 1 else: error_operate.error(105) return 1 else: return 0
def modify(manifestFile, sourceCfgFile, pluginName): manifestFile = file_operate.getFullPath(manifestFile) sourceXml = sourceCfgFile sourceXml = file_operate.getFullPath(sourceXml) file_operate.printf("modify source xml:%s manifestFile:%s" %(sourceXml, manifestFile)) if not os.path.exists(sourceXml): ForManifestDir = os.path.dirname(sourceXml) screenOrientation = getStartActivityOrientation(manifestFile) file_operate("screenOrientation:%s"%(screenOrientation,)) if screenOrientation == 'portrait': sourceXml = ForManifestDir + '/ForManifestPortrait.xml' else: sourceXml = ForManifestDir + '/ForManifestLandscape.xml' if not os.path.exists(sourceXml): return ET.register_namespace('android', androidNS) targetTree = ET.parse(manifestFile) targetRoot = targetTree.getroot() haveChanged = doModify(manifestFile, sourceXml, targetRoot) if haveChanged: file_operate.printf('Modify AndroidManifest.xml for plugin ' + pluginName) targetTree.write(manifestFile, 'UTF-8')
def addFileToApk(srcfile, apkFile): if os.path.exists(srcfile) and os.path.exists(apkFile): apkFile = file_operate.getFullPath(apkFile) aapt = file_operate.getToolPath('aapt') rmcmd = '"%s" remove "%s" "%s"' % (aapt, apkFile, 'classes.dex') bReturn = file_operate.execFormatCmd(rmcmd) if bReturn: error_operate.error(70) return 1 f = zipfile.ZipFile(apkFile, 'a') f.write(srcfile, 'classes.dex') f.close() file_operate.printf('add file:' + srcfile) return 0
def entry(packageFile): sourceApkFile = file_operate.getFullPath(packageFile) channelsFile = file_operate.getFullPath("channels.txt") if not os.path.exists(channelsFile): file_operate.printF("The channels.txt file is not exists.") return f = open(channelsFile) channelLines = f.readlines() f.close() channels = [] if channelLines != None and len(channelLines) > 0: for line in channelLines: targetChannel = line.strip() channels.append(targetChannel) else: file_operate.printF("There is no channel configed in channels.txt") modify(channels, sourceApkFile)
def updateExeFlag(self): dictTemp = {} result = utils.http_manager.httpManager.shareInstance( ).downloadUpdateFile() if result == False: return False UpdateDir = file_operate.getFullPath("Update/") new_updateFile = file_operate.getFullPath(UpdateDir + 'UpdateFile/update.xml') old_updateFile = file_operate.getFullPath('update.xml') config = ET.parse(new_updateFile) root = config.getroot() self.__dictTemp_new['version'] = root.find('version').text self.__dictTemp_new['force'] = root.find('force').text self.__dictTemp_new['url'] = root.find('url').text self.__dictTemp_new['md5'] = root.find('md5').text self.__dictTemp_new['date'] = root.find('date').text self.__dictTemp_new['descript'] = root.find('descript').text config = ET.parse(old_updateFile) root = config.getroot() self.__dictTemp_old['version'] = root.find('version').text self.__dictTemp_old['force'] = root.find('force').text self.__dictTemp_old['url'] = root.find('url').text self.__dictTemp_old['md5'] = root.find('md5').text self.__dictTemp_old['date'] = root.find('date').text self.__dictTemp_old['descript'] = root.find('descript').text if self.__dictTemp_new.get('version') == self.__dictTemp_old.get( 'version'): dictTemp['updateflag'] = False else: dictTemp['updateflag'] = True dictTemp['force'] = self.__dictTemp_new.get('force') return dictTemp
def generateNewChannelApk(sourceApkFile, empty_file, channelID): file_operate.printF("Now to generate channel %s", channelID) targetFolder = file_operate.getFullPath("channels") if not os.path.exists(targetFolder): os.makedirs(targetFolder) targetApk = os.path.join(targetFolder, "u8-"+channelID+".apk") file_operate.copy_file(sourceApkFile, targetApk) zipped = zipfile.ZipFile(targetApk, 'a', zipfile.ZIP_DEFLATED) emptyChannelFile = "META-INF/u8channel_{channel}".format(channel=channelID) zipped.write(empty_file, emptyChannelFile) zipped.close()
def getProductCode(self): productcode = "" GameFile = file_operate.getFullPath("Log/GameFile.log") if os.path.exists(GameFile): f = open(GameFile, 'a+') data = str(f.read()) f.close() if len(data) > 0 and data.find('|') != -1: logFile = codecs.open(GameFile, 'a+', 'utf-8') for line in logFile.readlines(): line = line.rstrip("\r\n") Info = line.split('|') productcode = Info[0] return productcode
def generateNewChannelApk(sourceApkFile, empty_file, channelID): file_operate.printF("Now to generate channel %s", channelID) targetFolder = file_operate.getFullPath("channels") if not os.path.exists(targetFolder): os.makedirs(targetFolder) targetApk = os.path.join(targetFolder, "u8-" + channelID + ".apk") file_operate.copy_file(sourceApkFile, targetApk) zipped = zipfile.ZipFile(targetApk, 'a', zipfile.ZIP_DEFLATED) emptyChannelFile = "META-INF/u8channel_{channel}".format(channel=channelID) zipped.write(empty_file, emptyChannelFile) zipped.close()
def findApplicationClass(decompileDir): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_operate.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}name' tree = ET.parse(manifestFile) root = tree.getroot() applicationNode = root.find('application') if applicationNode is None: return None applicationClassName = applicationNode.get(key) return applicationClassName
def modify(channels, sourceApkFile): sourceApkFile = sourceApkFile.replace('\\', '/') if not os.path.exists(sourceApkFile): file_operate.printF("The source apk file is not exists") return tempFolder = file_operate.getFullPath('temp') if not os.path.exists(tempFolder): os.makedirs(tempFolder) empty_file = os.path.join(tempFolder, "temp.txt") f = open(empty_file, 'w') f.close() for channel in channels: generateNewChannelApk(sourceApkFile, empty_file, channel) file_operate.del_file_folder(tempFolder)
def appendChannelIconMark(iconName, decompileDir): """ 自动给游戏图标加上渠道SDK的角标 """ # gameIconPath = file_operate.getFullPath(constant.sdkRelatePath+ConfigParse.shareInstance().getChannelName()) + '/icon/icon.png' gameIconPath = file_operate.getFullPath( constant.sdkRelatePath) + '/game_icon/icon.png' if not os.path.exists(gameIconPath): return 1 useMark = True try: config = ET.parse(file_operate.getConfigXmlPath()) root = config.getroot() icon = root.find("icon") markType = icon.get("markType") except Exception, e: print e useMark = False
def downloadUpdateFile(self): # url = "http://sdk.funcell123.com/upload/tool/update.xml" url = "http://553.cdn.553.com/federation/tool/update.xml" UpdateDir = file_operate.getFullPath("Update/") if not os.path.exists(UpdateDir + 'UpdateFile'): os.makedirs(UpdateDir + 'UpdateFile') try: res = urllib2.urlopen(urllib2.Request(url)) code = res.getcode() res.close() print 'downloadUpdateFile code:', code if code != 200: file_operate.reportError( "", "", 'url:%s 下载失败,请检查当前网络... Exception:%s' % (url)) return False except Exception, e: print 'e:', e file_operate.reportError( "", "", 'url:%s 下载失败,请检查当前网络... Exception:%s' % (url, e)) return False
def renameApkPackage(smaliFolder='file/decompile/smali', manifest='file/decompile/AndroidManifest.xml', newPackageName="com.zzw.noName"): """ rename apk package name. """ manifest = file_operate.getFullPath(manifest) ET.register_namespace('android', androidNS) targetTree = ET.parse(manifest) root = targetTree.getroot() bRet = False package = root.attrib.get('package') old_package = package applicationNode = root.find('application') if applicationNode != None: activityLs = applicationNode.findall('activity') key = '{' + androidNS + '}name' if activityLs != None and len(activityLs) > 0: for node in activityLs: activityName = node.attrib[key] if activityName[0:1] == '.': activityName = old_package + activityName elif activityName.find('.') == -1: activityName = old_package + '.' + activityName node.attrib[key] = activityName serviceLs = applicationNode.findall('service') key = '{' + androidNS + '}name' if serviceLs != None and len(serviceLs) > 0: for node in serviceLs: serviceName = node.attrib[key] if serviceName[0:1] == '.': serviceName = old_package + serviceName elif serviceName.find('.') == -1: serviceName = old_package + '.' + serviceName node.attrib[key] = serviceName root.attrib['package'] = newPackageName targetTree.write(manifest, 'UTF-8') return newPackageName
def downloadZip(self, channel, url, md5value): DownloadDir = file_operate.getFullPath("Download/") print 'DownloadDir:', DownloadDir if not os.path.exists(DownloadDir): os.makedirs(DownloadDir) #此步骤为判断当前请求链接是否有效 try: res = urllib2.urlopen(urllib2.Request(url), timeout=60) code = res.getcode() res.close() print 'code:', code if code != 200: str_error = 'download url:%s download failed.Please check the current network. Network status code:%s' % ( url, str(code)) file_operate.reportError("", "", str_error) return False except Exception, e: print 'e:', e str_error = "download url:%s download failed.Please check the current network Exception:%s" % ( url, str(e.message)) file_operate.reportError("", "", str_error) return False
def split_apk(db_name, game_id, id_channel, parent_apk_path, sub_apk_path, sub_channel_id): reload(sys) sys.setdefaultencoding('utf8') log_dir = '%s/%s/%s' % (db_name, game_id, id_channel) ConfigParse.shareInstance().set_log_dir(log_dir) if not os.path.exists(parent_apk_path): logError('parent apk not exist', log_dir) print '{"ret":"fail","msg":"parent apk not exist"}' return middle_dir = '%s/%s' % (db_name, sub_channel_id) split_work_dir = file_operate.get_server_dir( ) + '/split_workspace/%s' % middle_dir print 'split_work_dir:' + split_work_dir if os.path.exists(split_work_dir): file_operate.delete_file_folder(split_work_dir) os.makedirs(split_work_dir) split_decompile_dir = split_work_dir + '/decompile' os.mkdir(split_decompile_dir) channel_temp_apk_dir = split_work_dir + '/temp' os.mkdir(channel_temp_apk_dir) channel_temp_apk = channel_temp_apk_dir + '/temp.apk' file_operate.copyFile(parent_apk_path, channel_temp_apk) ret = apk_operate.decompileApk(channel_temp_apk, split_decompile_dir, None) if ret: logError('decompileApk parent apk fail', log_dir) print '{"ret":"fail","msg":"decompileApk parent apk fail"}' return ConfigParse.shareInstance().readUserConfig(0) sub_channel_config = ConfigParse.shareInstance().get_sub_channel_config() sub_channel_icon_url = None display_name = None sub_app_id = '' sub_num = '' if len(sub_channel_config) > 0: for r in sub_channel_config: if int(id_channel) != int(r['p_channel_id']): logError('param channel id is not right', log_dir) print '{"ret":"fail","msg":"param channel id is not right"}' return if int(game_id) != int(r['game_id']): logError('param game id is not right', log_dir) print '{"ret":"fail","msg":"param game id is not right"}' return if r['r_channel_game_icon'] is None: sub_channel_icon_url = '' else: sub_channel_icon_url = r['r_channel_game_icon'] if r['display_name'] is None: display_name = '' else: display_name = r['display_name'].encode('utf-8') sub_app_id = str(r['sub_app_id']) print 'sub_app_id: %s' % sub_app_id sub_num = str(r['sub_num']) else: logError('sub channel config is empty', log_dir) print '{"ret":"fail","msg":"sub channel config is empty"}' return if sub_app_id == 0 or sub_num == 0: log_info = 'ret:fail,msg:sub_app_id and sub_num == 0' logError(log_info, log_dir) return if display_name != '' and display_name is not None: apk_operate.doModifyAppName(split_decompile_dir, display_name) if sub_channel_icon_url != '' and sub_channel_icon_url is not None: channel_icon_dir = split_work_dir + '/icon/' os.mkdir(channel_icon_dir) urllib.urlretrieve(sub_channel_icon_url, channel_icon_dir + 'icon.png') ret = apk_operate.pushIconIntoApk(channel_icon_dir, split_decompile_dir) if ret: logError('pushIconIntoApk error', log_dir) return ret = encode_operate.decodeXmlFiles(split_decompile_dir) if ret: logError('decodeXmlFiles error', log_dir) return channel = ConfigParse.shareInstance().findChannel(int(id_channel)) sdk_dir = split_work_dir + '/sdk/' for channel_sdk in channel['sdkLs']: id_sdk = channel_sdk['idSDK'] SDK = ConfigParse.shareInstance().findSDK(id_sdk) if SDK is None: continue split_script_src_dir = file_operate.get_server_dir( ) + '/config/sdk/' + SDK['SDKName'] + '/specialsplit_script.pyc' split_script_src_dir = file_operate.getFullPath(split_script_src_dir) if not os.path.exists(split_script_src_dir): continue split_script_dest_dir = sdk_dir + SDK[ 'SDKName'] + '/specialsplit_script.pyc' file_operate.copyFiles(split_script_src_dir, split_script_dest_dir) SDKDir = sdk_dir + SDK['SDKName'] sys.path.append(SDKDir) import specialsplit_script print 'sub_app_id:' + sub_app_id ret = specialsplit_script.script(split_decompile_dir, sub_app_id, sub_num) del sys.modules['specialsplit_script'] sys.path.remove(SDKDir) if ret: logError("error do Special Operate", log_dir) print "error do Special Operate" return ret = change_develop_id(split_decompile_dir, sub_app_id, sub_num) print 'change_develop_id ret:%s' % ret if ret: logError('change develop id error', log_dir) return encode_operate.encodeXmlFiles(split_decompile_dir) channel_unsign_apk = channel_temp_apk_dir + '/channel_temp_apk.apk' ret = apk_operate.recompileApk(split_decompile_dir, channel_unsign_apk) if ret: logError("recompileApk fail", log_dir) print "recompileApk fail" return game = ConfigParse.shareInstance().getCurrentGame() if game is None: print 'game is none' logError('game is none', log_dir) return ret = apk_operate.signApkAuto(channel_unsign_apk, game, channel, middle_dir) if ret: print 'signApkAuto fail' logError('signApkAuto fail', log_dir) return out_put_dir = os.path.dirname(sub_apk_path) ret = apk_operate.alignAPK(channel_unsign_apk, sub_apk_path, out_put_dir) if ret: print 'alignAPK fail' logError('alignAPK fail', log_dir) return print '{"ret":"success","msg":"run pack success"}' file_operate.delete_file_folder(split_work_dir)
def execute(channel, pluginInfo, decompileDir, packageName): manifestFile = decompileDir + "/AndroidManifest.xml" manifestFile = file_operate.getFullPath(manifestFile) ET.register_namespace('android', androidNS) key = '{' + androidNS + '}launchMode' tree = ET.parse(manifestFile) root = tree.getroot() package = root.attrib.get('package') applicationNode = root.find('application') if applicationNode is None: return 1 key = '{'+androidNS+'}name' receiverNodeList = applicationNode.findall('receiver') if receiverNodeList != None: for node in receiverNodeList: if node.attrib[key] == 'com.umeng.message.UmengBroadcastReceiver': intentNodeLst = node.findall('intent-filter') if intentNodeLst is None: break for intentNode in intentNodeLst: actionNodeList = intentNode.findall('action') if actionNodeList is None: break for actionNode in actionNodeList: if actionNode.attrib[key] == '.intent.action.COMMAND': newVal = package + actionNode.attrib[key] actionNode.set(key, newVal) serviceNodeList = applicationNode.findall('service') if serviceNodeList != None: for node in serviceNodeList: if node.attrib[key] == 'com.umeng.message.UmengService': intentNodeLst = node.findall('intent-filter') if intentNodeLst is None: break for intentNode in intentNodeLst: actionNodeList = intentNode.findall('action') if actionNodeList is None: break for actionNode in actionNodeList: if actionNode.attrib[key] == '.intent.action.START': newVal = package + actionNode.attrib[key] actionNode.set(key, newVal) if actionNode.attrib[key] == '.intent.action.COCKROACH': newVal = package + actionNode.attrib[key] actionNode.set(key, newVal) tree.write(manifestFile, 'UTF-8') return 0