def decompileApk(apkPath_, decompileTo_): cmdLogUtils.log("反编译 apk") folderUtils.makeSureDirIsExists(decompileTo_) if os.path.exists(decompileTo_): folderUtils.removeTree(decompileTo_) # 清理缓存的 framework ,确保 apktool 和 释放出的 framework 的一致性 os.system("apktool empty-framework-dir") os.system("apktool d %s -o %s" % (apkPath_, decompileTo_))
def override(self, sourceFolderPath_: str, targetFolderPath_: str, filters_: list): _filePathList = folderUtils.getFilterFilesInPath(sourceFolderPath_, filters_) for _i in range(len(_filePathList)): _shortPath = _filePathList[_i].split(sourceFolderPath_)[1] _tarfilePath = targetFolderPath_ + _shortPath _sourcefilePath = sourceFolderPath_ + _shortPath print(str(_sourcefilePath) + ' -> ' + str(_tarfilePath)) _targetFileLocalFolderPath = os.path.split(_tarfilePath)[0] folderUtils.makeSureDirIsExists(_targetFileLocalFolderPath) shutil.copy(_sourcefilePath, _tarfilePath)
def moveCoreAndUniversalPackages(): # 确保目录存在 folderUtils.makeSureDirIsExists(packagesFolder) # package 缓存列表 _folderList = folderUtils.getFolderListJustOneDepth(packageCacheFolder) for _i in range(len(_folderList)): _packageAndVersion = _folderList[_i] _needMove = False if corePartName in _packageAndVersion or universalPartName in _packageAndVersion: _needMove = True if _needMove: _fromFolder = os.path.join(packageCacheFolder, _packageAndVersion) _package = os.path.basename(_packageAndVersion).split("@")[0] # 去掉版本号 _targetFolder = os.path.join(packagesFolder, _package) print(_fromFolder + " -> " + _targetFolder) shutil.move(_fromFolder, _targetFolder)
def xmlToJsonDictInFolderThenWrite(xmlFolderPath_: str, outputFolderPath_: str): folderUtils.makeSureDirIsExists(outputFolderPath_) _xmlPathToJsonContentDict = xmlToJsonDictInFolder( xmlFolderPath_) # 获取 [路径:JSON内容] 字典 for _xmlPath in _xmlPathToJsonContentDict: _jsonStr = str( json.dumps(_xmlPathToJsonContentDict[_xmlPath], indent=4, sort_keys=False, ensure_ascii=False)) _targetJsonPath = os.path.join( outputFolderPath_, os.path.dirname(_xmlPath.split(xmlFolderPath_)[1]), fileUtils.justName(_xmlPath) + ".json") print(str(_targetJsonPath)) fileUtils.writeFileWithStr(_targetJsonPath, _jsonStr)
def createPuml(csFoderPath_: str, pumlFolderPath_: str): csFoderPath_ = sysUtils.folderPathFixEnd(csFoderPath_) folderUtils.makeSureDirIsExists(pumlFolderPath_) pumlFolderPath_ = sysUtils.folderPathFixEnd(pumlFolderPath_) # 生成 puml 文本文件,cs文件和puml文件一一对应 _umlDocCMD = "puml-gen " + csFoderPath_ + " " + pumlFolderPath_ + " -dir" cmdUtils.doStrAsCmd(_umlDocCMD, pumlFolderPath_, True) # puml-gen 会生成一个 include.puml 文件,用来整合所有的文件 _pumlList = folderUtils.getFileListInFolder(pumlFolderPath_, [".puml"]) # include.puml 的内容格式和最新的plantuml不匹配,我们手动生成一个 _includeContent = "@startuml\n" # 先打印最外层文件 for _i in range(len(_pumlList)): _includeContent += "!include " + _pumlList[_i] + "\n" _includeContent += "@enduml" # 覆盖掉原有的 include.puml fileUtils.writeFileWithStr(os.path.join(pumlFolderPath_, "include.puml"), _includeContent)
def createUML(plantUmlJarPath_: str, pumlPath_: str, umlFolderPath_: str): # 判断其存在性 if not os.path.exists(pumlPath_): print("ERROR : puml文件错误") # 确保文件夹正确性 folderUtils.makeSureDirIsExists(umlFolderPath_) umlFolderPath_ = sysUtils.folderPathFixEnd(umlFolderPath_) # 获取 puml 所在文件夹 _pumlFolderPath = os.path.dirname(pumlPath_) _justName = os.path.splitext(os.path.split(pumlPath_)[1])[0] # 通过 puml 生成 uml 图 _umlPicCMD = "java -jar " + plantUmlJarPath_ + " -tsvg " + pumlPath_ cmdUtils.doStrAsCmd(_umlPicCMD, _pumlFolderPath, True) # 将生成的 puml 转移到指定文件夹内 _umpPath = os.path.join(_pumlFolderPath, _justName + ".svg") if os.path.exists(_umpPath): shutil.copy(_umpPath, os.path.join(umlFolderPath_, _justName + ".svg")) os.remove(pumlPath_) os.remove(_umpPath) else: print("ERROR : UML图创建错误")
def BackupCodesAndPngs(self, dParameters_): _projectFolderPath = sysUtils.folderPathFixEnd(dParameters_["projectFolder"]) _projectName = dParameters_["projectName"] _airAndPyPathList = folderUtils.getFilterFilesInPath(_projectFolderPath, [".air", ".py"]) # 匹配 r"tpl1606022416813.png" 这样的内容 _groupReg = r"r\"(.*)\.png\"" # 要拷贝的png文件名 _pngPathList = [] for _i in range(len(_airAndPyPathList)): _airAndPyPath = _airAndPyPathList[_i] _matchGroupList = regUtils.getMatchGroupStrList(_airAndPyPath, _groupReg) # 得到匹配的group阵列 for _j in range(len(_matchGroupList)): _pngNameWithOutSuffix = _matchGroupList[_j][0] _pngPath = _projectFolderPath + "/" + _pngNameWithOutSuffix + ".png" if not _pngPath in _pngPathList: # 没有记录过,就记录 _pngPathList.append(_pngPath) _tempPicsFolderPath = _projectFolderPath + "tempPics/" print(" 拷贝代码实际使用图片到临时目录 : " + _tempPicsFolderPath) fileCopyUtils.copyFilesToFolder(_pngPathList, _tempPicsFolderPath) _backupProjectFolderPath = str(Path(self.subResPath + "/" + _projectName)) # 在资源文件内备份 print(' 备份位置 : ' + str(_backupProjectFolderPath)) folderUtils.makeSureDirIsExists(_backupProjectFolderPath) print(' 备份代码') fileCopyUtils.copyFilesInFolderTo( [".py", ".air"], _projectFolderPath, _backupProjectFolderPath, "include" ) print(' 备份图片') fileCopyUtils.copyFilesInFolderTo( [".png"], _tempPicsFolderPath, _backupProjectFolderPath, "include" ) print(' 删除临时目录') folderUtils.removeTree(_tempPicsFolderPath)
def recompileApk(decompileTo_, keyStorePath_, keyPassword_, key_, targetApkFolder_, targetApkName_): cmdLogUtils.log("重编译 apk") if not os.path.exists(decompileTo_): cmdLogUtils.err("ERROR : Apk已解压目录不存在 " + decompileTo_) sys.exit(1) folderUtils.makeSureDirIsExists(targetApkFolder_) _tempApkName = "unsigned.apk" # 临时 apk 名称 _tempApkPath = os.path.join(targetApkFolder_, _tempApkName) # 临时文件路径 _targetApkPath = os.path.join(targetApkFolder_, targetApkName_) # 目标APK路径 if os.path.exists(_targetApkPath): os.remove(_targetApkPath) _cmd = "apktool b %s -o %s" % (decompileTo_, _tempApkName) cmdUtils.doStrAsCmd(_cmd, targetApkFolder_, True) if os.path.exists(_tempApkPath): cmdLogUtils.log("重签名") _cmd = "jarsigner -verbose -keystore %s -storepass %s -signedjar %s -digestalg SHA1 -sigalg MD5withRSA %s %s" % ( keyStorePath_, keyPassword_, _targetApkPath, _tempApkPath, key_) os.system(_cmd) os.remove(_tempApkPath) # 移除临时文件 else: cmdLogUtils.err("ERROR : 重编译失败") sys.exit(1)
def exportSpineInFolder(self, spineFolderPath_: str, jsonOutputFolderPath_: str, exportJsonPath_: str, pngFolderPath_: str, altasOutputFolderPath_: str, packJsonPath_: str, altasName_: str): folderUtils.makeSureDirIsExists(jsonOutputFolderPath_) _spineList = folderUtils.getFilterFilesInPath(spineFolderPath_, [".spine"]) # spine 名称队列,用于校验导出骨骼信息是否匹配 _spineJustNameList = [] # 根据配置,导出动画文件 _cmd = self.spineAppPath for _i in range(len(_spineList)): _spinePath = _spineList[_i] _spineJustNameList.append(fileUtils.justName(_spinePath)) _cmd = _cmd + " -i '" + _spinePath + "' -m -o '" + jsonOutputFolderPath_ + "' -e '" + exportJsonPath_ + "' " _pipeLines = cmdUtils.doStrAsCmd(_cmd, spineFolderPath_, False) if not _pipeLines: sys.exit(1) # 发布动画是否和文件名一致,导出的文件是按照动画编辑时的骨骼命名进行的,有可能骨骼和文件的名称不一致,需要提示。 _outputJsonPathList = folderUtils.getFilterFilesInPath( jsonOutputFolderPath_, [".json"]) for _i in range(len(_outputJsonPathList)): _outputJsonPath = _outputJsonPathList[_i] listUtils.findAndRemove(_spineJustNameList, fileUtils.justName(_outputJsonPath)) if len(_spineJustNameList) > 0: print("spine骨骼与Spine文件名不一致") for _i in range(len(_spineJustNameList)): print(" " + _spineJustNameList[_i]) sys.exit(1) # 根据配置,打包图片 _cmd = self.spineAppPath _cmd = _cmd + " -i '" + pngFolderPath_ + "' -o '" + altasOutputFolderPath_ + "' -n '" + altasName_ + "' -p '" + packJsonPath_ + "'" _pipeLines = cmdUtils.doStrAsCmd(_cmd, spineFolderPath_, False) if not _pipeLines: sys.exit(1)