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 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 addLibPath(self): if platform.system() == 'Darwin': libPath = file_operate.getToolPath('') os.environ['PATH'] = libPath + ':' + os.environ['PATH'] if os.path.exists('/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/'): libPath = ':' + '/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/' os.environ['PATH'] = libPath + ':' + os.environ['PATH'] elif platform.system() == 'Windows': libPath = file_operate.getToolPath('') libPath = libPath.encode('gbk') os.environ['PATH'] = libPath + ';' + os.environ['PATH'] jrePath = file_operate.getToolPath('jre/bin') jrePath = jrePath.encode('gbk') os.environ['PATH'] = jrePath + ';' + os.environ['PATH']
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 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 alignAPK(tempApkFile, apkFile, outputDir): if not os.path.exists(outputDir): os.makedirs(outputDir) align = file_operate.getToolPath('zipalign') aligncmd = '"%s" -f 4 "%s" "%s"' % (align, tempApkFile, apkFile) ret = file_operate.execFormatCmd(aligncmd) if ret: error_operate.error(250) return 1 return 0
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 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 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 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 produceNewRFile(packName, decompileFullDir, androidManiFest='AndroidManifest.xml'): """ According to the merger of resources to create new R file """ fullPath = decompileFullDir tempPath = os.path.dirname(decompileFullDir) tempPath = tempPath + '/tempRFile' if os.path.exists(tempPath): file_operate.delete_file_folder(tempPath) if not os.path.exists(tempPath): os.makedirs(tempPath) resPath = os.path.join(decompileFullDir, 'res') targetResPath = os.path.join(tempPath, 'res') file_operate.copyFiles(resPath, targetResPath) genPath = os.path.join(tempPath, 'gen') if not os.path.exists(genPath): os.mkdir(genPath) androidPath = file_operate.getToolPath('android.jar') srcManifest = os.path.join(fullPath, androidManiFest) aaptPath = file_operate.getToolPath('aapt') cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % ( aaptPath, genPath, targetResPath, androidPath, srcManifest) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(102) return 1 RPath = packName.replace('.', '/') RPath = os.path.join(genPath, RPath) RFile = os.path.join(RPath, 'R.java') cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % ( file_operate.getJavaBinDir(), RFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(103) return 1 #针对某系渠道通过R。xx来获取资源,在指定包名下添加R文件 try: config = ET.parse(file_operate.getConfigXmlPath()) root = config.getroot() Manifest = root.find("Manifest") num = int(Manifest.get('num')) for i in range(0, num): srcManifest_i = os.path.join( file_operate.getFullPath(constant.tmpPath), 'Manifest/' + str(i) + '/AndroidManifest.xml') cmd = '"%s" p -f -m -J "%s" -S "%s" -I "%s" -M "%s"' % ( aaptPath, genPath, targetResPath, androidPath, srcManifest_i) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(102) return 1 packageNameArray = Manifest.get('packageNameArray') packageNameNode = packageNameArray.split(',')[i] RPath = packageNameNode.replace('.', '/') RPath = os.path.join(genPath, RPath) RFile = os.path.join(RPath, 'R.java') cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % ( file_operate.getJavaBinDir(), RFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(103) return 1 except Exception, e: print e print "Error: cannot parse file: funcellconfig.xml."
RFile = os.path.join(RPath, 'R.java') cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % ( file_operate.getJavaBinDir(), RFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(103) return 1 except Exception, e: print e print "Error: cannot parse file: funcellconfig.xml." ################################ dexPath = os.path.join(tempPath, 'class.dex') if platform.system() == 'Windows': dxTool = file_operate.getToolPath('dx.bat') else: dxTool = file_operate.getToolPath('dx') cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, dexPath, genPath) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(104) return 1 smaliPath = os.path.join(fullPath, 'smali') ret = dexTrans2Smali(dexPath, smaliPath, 10) if ret: return 1 else: return 0
def custom_package_r_file(self, packageName, androidManiFest = 'AndroidManifest.xml'): ''' create custom packageName R file :param packageName: :param androidManiFest: :return: ''' # bMerge = mergeValueXml(decompileFullDir) # if bMerge: # error_operate.error(102) # return 1 fullPath = self.__decompileDir tempPath = os.path.dirname(self.__decompileDir) tempPath = tempPath + '/tempRFile' if os.path.exists(tempPath): file_operate.delete_file_folder(tempPath) if not os.path.exists(tempPath): os.makedirs(tempPath) resPath = os.path.join(self.__decompileDir, 'res') targetResPath = os.path.join(tempPath, 'res') file_operate.copyFiles(resPath, targetResPath) genPath = os.path.join(tempPath, 'gen') if not os.path.exists(genPath): os.mkdir(genPath) androidPath = file_operate.getToolPath('android.jar') srcManifest = os.path.join(fullPath, androidManiFest) aaptPath = file_operate.getToolPath('aapt') cmd = '"%s" p -f -m -J "%s" --custom-package "%s" -S "%s" -I "%s" -M "%s"' % (aaptPath, genPath, packageName, targetResPath, androidPath, srcManifest) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(102) return 1 RPath = packageName.replace('.', '/') RPath = os.path.join(genPath, RPath) RFile = os.path.join(RPath, 'R.java') cmd = '"%sjavac" -source 1.7 -target 1.7 -encoding UTF-8 "%s"' % (file_operate.getJavaBinDir(), RFile) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(103) return 1 dexPath = os.path.join(tempPath, 'class.dex') if platform.system() == 'Windows': dxTool = file_operate.getToolPath('dx.bat') cmd = '"%s" --dex --output="%s" "%s"' % (dxTool, dexPath, genPath) else: dxTool = file_operate.getToolPath('/lib/dx.jar') cmd = 'java -jar -Xms512m -Xmx512m "%s" --dex --output="%s" "%s"' % (dxTool, dexPath, genPath) ret = file_operate.execFormatCmd(cmd) if ret: error_operate.error(104) return 1 smaliPath = os.path.join(fullPath, 'smali') ret = apk_operate.dexTrans2Smali(dexPath, smaliPath, 10, 'baksmali.jar') if ret: return 1 else: return 0 pass