├── README.md ├── RemoveUnityUIWebView ├── RemoveUnityUIWebView.py ├── URLUtility.mm └── readme.txt ├── XcodeprojModify ├── desc.png ├── lib │ ├── pbxprojParser │ │ ├── __init__.cpython-37m-darwin.so │ │ └── pbxprojParser.cpython-37m-darwin.so │ └── xcodeproj.cpython-37m-darwin.so └── start.py ├── bugly符号表自动上传脚本 └── bugly │ ├── bugly_upload.sh │ ├── buglyqq-upload-symbol.jar │ └── bugly上传.md ├── 分割字符串 ├── SplitString.py └── desc.png └── 给文件增加内容修改md5 ├── ModifyMd5.py └── desc.png /README.md: -------------------------------------------------------------------------------- 1 | # PythonToolBox 2 | 脚本工具集合 3 | 4 | # 广告一波 5 | 我的另外一个仓库,求star 6 | 7 | [iOS代码混淆工具](https://github.com/iOSCoda/DiffHelper) 8 | 9 | 10 | ## 1.分割字符串 11 | 12 | ![分割字符串](https://github.com/iOSCoderMaster/PythonToolBox/blob/master/分割字符串/desc.png) 13 | 14 | ## 2.修改文件md5 15 | 16 | 17 | ``` 18 | 给文件增加内容以修改md5,增加的内容可自定义 19 | ``` 20 | 21 | 22 | ![desc.png](https://i.loli.net/2020/02/10/VLclRprYsZbKMu3.png) 23 | 24 | 25 | ## 3.XcodeprojModify 26 | 27 | ``` 28 | 修改xcodeproj文件中的udid 29 | ``` 30 | 31 | ``` 32 | 需要Python 3.7.3(其他版本不行) 33 | ``` 34 | 35 | 需要安装依赖: 36 | ``` 37 | pip3 install future 38 | ``` 39 | 40 | macOS 10.15系统 需要在终端执行以下命令后方可使用 41 | ``` 42 | sudo spctl --master-disable 43 | ``` 44 | 45 | 使用方式见XcodeprojModify文件夹下的图片desc.png 46 | 47 | ![desc.png](https://i.loli.net/2020/02/10/a2lvBPwysgZUc8W.png) 48 | 49 | ## 4.RemoveUnityUIWebView 50 | 移除Unity中libiPhone-lib.a的UIWebView 51 | -------------------------------------------------------------------------------- /RemoveUnityUIWebView/RemoveUnityUIWebView.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | 3 | # https://github.com/iOSCoda/PythonToolBox 4 | # author QQ 2108336019 5 | 6 | import os 7 | import shutil 8 | 9 | parPath = os.path.dirname(os.path.abspath(__file__)) 10 | 11 | kArchesList = ["armv7", "arm64", "armv7s"] 12 | 13 | kLibName = "libiPhone-lib.a" 14 | 15 | # 生成新的.a的名字 16 | kNewLibName = "libiPhone-lib-new.a" 17 | 18 | 19 | def colorPrint(string): 20 | print("\033[0;33;m%s\033[0m" % (str(string))) 21 | 22 | 23 | # 获取libiPhone-lib.a路径 24 | def get_libiPhone_libPath(): 25 | staticLibPath = os.path.join(parPath, kLibName) 26 | if not os.path.exists(staticLibPath): 27 | print("请将需要处理的libiPhone-lib.a放入该脚本同级目录") 28 | os._exit(0) 29 | return staticLibPath 30 | 31 | 32 | # 获取当前所有架构 33 | def getCurArches(): 34 | command = "lipo -info %s" % (get_libiPhone_libPath()) 35 | output = os.popen(command) 36 | content = output.readline() 37 | output.close() 38 | for item in kArchesList[:]: 39 | if item not in content: 40 | kArchesList.remove(item) 41 | return kArchesList 42 | 43 | 44 | # 获取URLUtility.mm路径 45 | def getURLUtilityPath(): 46 | URLUtilityPath = os.path.join(parPath, "URLUtility.mm") 47 | if not os.path.exists(URLUtilityPath): 48 | colorPrint(URLUtilityPath) 49 | colorPrint("不存在") 50 | os._exit(0) 51 | return URLUtilityPath 52 | 53 | 54 | # 获取不同架构对应的文件夹 55 | def getArchTmpPath(arch): 56 | archTmpPath = os.path.join(parPath, arch) 57 | if not os.path.isdir(archTmpPath): 58 | os.mkdir(archTmpPath) 59 | return archTmpPath 60 | 61 | 62 | # 获取不同架构对应的URLUtility.o路径 63 | def getArchURLUtilityOPath(type): 64 | archPath = getArchTmpPath(type) 65 | archOPath = os.path.join(archPath, "URLUtility.o") 66 | return archOPath 67 | 68 | 69 | # 获取不同架构对应的.a路径 70 | def getTargetLibPath(arch): 71 | targetArchPath = getArchTmpPath(arch) 72 | libName = "libiPhone-lib_" + arch + ".a" 73 | targetLibPath = os.path.join(targetArchPath, libName) 74 | return targetLibPath 75 | 76 | 77 | # 获取不同架构对应的URLUtility.o 78 | def createURLUtilityO(arch, URLUtilityOPath): 79 | colorPrint("") 80 | colorPrint("----------开始生成%s URLUtility.o" % (arch)) 81 | URLUtilityPath = getURLUtilityPath() 82 | command = ( 83 | "clang -c %s -arch %s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -o %s" 84 | % (URLUtilityPath, arch, URLUtilityOPath) 85 | ) 86 | os.system(command) 87 | colorPrint("----------结束生成%s URLUtility.o" % (arch)) 88 | 89 | 90 | # 切割框架 91 | def splitArches(arch, archList, targetArchPath): 92 | libName = os.path.basename(targetArchPath) 93 | colorPrint("----------开始生成:%s" % (libName)) 94 | libiPhone_libPath = get_libiPhone_libPath() 95 | if len(archList) > 1: 96 | os.system("lipo %s -thin %s -output %s" % (libiPhone_libPath, arch, targetArchPath)) 97 | else: 98 | shutil.copy(libiPhone_libPath, targetArchPath) 99 | colorPrint("----------结束生成:%s" % (libName)) 100 | 101 | 102 | # 移除URLUtility.o 并且插入新的URLUtility.o 103 | def deleteAndInsert(arch): 104 | libPath = getTargetLibPath(arch) 105 | oObjetPath = getArchURLUtilityOPath(arch) 106 | 107 | colorPrint("----------移除旧的URLUtility.o") 108 | os.system("ar -d %s URLUtility.o" % (libPath)) 109 | 110 | colorPrint("----------插入新的URLUtility.o") 111 | command = "ar -q %s %s" % (libPath, oObjetPath) 112 | os.system(command) 113 | 114 | 115 | # 合并更新后的.a 116 | def mergeLib(archList, archPath): 117 | outputLibPath = os.path.join(parPath, kNewLibName) 118 | if len(archList) > 1: 119 | command = "lipo -create %s -output %s " % (archPath, outputLibPath) 120 | os.system(command) 121 | else: 122 | archPath = archPath.strip() 123 | shutil.copy(archPath, outputLibPath) 124 | colorPrint("") 125 | colorPrint("----------生成的新的libiPhone为:") 126 | colorPrint(outputLibPath) 127 | 128 | 129 | if __name__ == "__main__": 130 | 131 | # 获取当前所有的框架 132 | archList = getCurArches() 133 | colorPrint("当前所有架构:") 134 | colorPrint(str(archList)) 135 | 136 | archesString = "" 137 | for arch in archList: 138 | # 获取不同框架URLUtility.O的路径 139 | URLUtilityOPath = getArchURLUtilityOPath(arch) 140 | 141 | # 生成不同框架的URLUtility.O 142 | createURLUtilityO(arch, URLUtilityOPath) 143 | 144 | # 获取armvx.a的路径 145 | targetLibPath = getTargetLibPath(arch) 146 | 147 | # 生成对应的armvx.a 148 | splitArches(arch, archList, targetLibPath) 149 | 150 | # 删除原本的URLUtility.O,插入上面生成的URLUtility.O 151 | deleteAndInsert(arch) 152 | 153 | # 拼接需要合并的armvx.a路径 154 | archesString += targetLibPath + " " 155 | 156 | # 生成新的多框架二进制 157 | mergeLib(archList, archesString) 158 | 159 | # 清理临时文件 160 | for arch in archList: 161 | archPath = getArchTmpPath(arch) 162 | shutil.rmtree(archPath) 163 | -------------------------------------------------------------------------------- /RemoveUnityUIWebView/URLUtility.mm: -------------------------------------------------------------------------------- 1 | #include 2 | #import 3 | 4 | using namespace std; 5 | namespace core { 6 | template 7 | class StringStorageDefault {}; 8 | template 9 | class basic_string { 10 | public: 11 | char * str; 12 | basic_string( char* arg){ 13 | str = arg; 14 | } 15 | }; 16 | } 17 | 18 | void OpenURLInGame(core::basic_string< char,core::StringStorageDefault > const&arg){} 19 | 20 | void OpenURL(core::basic_string >const &arg){ 21 | const void *arg2 = arg.str; 22 | UIApplication *app = [UIApplication sharedApplication]; 23 | NSString *urlStr = [NSString stringWithUTF8String:(char *)arg2]; 24 | NSURL *url = [NSURL URLWithString:urlStr]; 25 | [app openURL:url]; 26 | } 27 | 28 | 29 | void OpenURL(std::string const &arg){ 30 | UIApplication *app = [UIApplication sharedApplication]; 31 | NSString *urlStr = [NSString stringWithUTF8String:arg.c_str()]; 32 | NSURL *url = [NSURL URLWithString:urlStr]; 33 | [app openURL:url]; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /RemoveUnityUIWebView/readme.txt: -------------------------------------------------------------------------------- 1 | 使用前请确认本机Xcode SDKs所在路径,确认包含以下路径: 2 | /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk 3 | 4 | 如果不是这个路径: 5 | 请将RemoveUnityUIWebView.py中的83行中以上路径改成本机Xcode SDKs所在路径(出现这个问题一般因为本机安装了多个Xcode) 6 | 7 | 8 | 1. 将需要移除UIWebView的libiPhone-lib.a放入该文件夹,名字一定要是libiPhone-lib.a 9 | 2. 执行RemoveUnityUIWebView.py脚本 10 | 打开终端 11 | 输入 python 空格 将RemoveUnityUIWebView.py拖入到空格后面 回车 12 | 3. 执行完成后,脚本会打印生成的libiPhone-lib.a -------------------------------------------------------------------------------- /XcodeprojModify/desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollin0-0/PythonToolBox/30ed334e027669cfcbf47d6bdbce70d75ee06ecb/XcodeprojModify/desc.png -------------------------------------------------------------------------------- /XcodeprojModify/lib/pbxprojParser/__init__.cpython-37m-darwin.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollin0-0/PythonToolBox/30ed334e027669cfcbf47d6bdbce70d75ee06ecb/XcodeprojModify/lib/pbxprojParser/__init__.cpython-37m-darwin.so -------------------------------------------------------------------------------- /XcodeprojModify/lib/pbxprojParser/pbxprojParser.cpython-37m-darwin.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollin0-0/PythonToolBox/30ed334e027669cfcbf47d6bdbce70d75ee06ecb/XcodeprojModify/lib/pbxprojParser/pbxprojParser.cpython-37m-darwin.so -------------------------------------------------------------------------------- /XcodeprojModify/lib/xcodeproj.cpython-37m-darwin.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollin0-0/PythonToolBox/30ed334e027669cfcbf47d6bdbce70d75ee06ecb/XcodeprojModify/lib/xcodeproj.cpython-37m-darwin.so -------------------------------------------------------------------------------- /XcodeprojModify/start.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | 3 | import os 4 | import sys 5 | 6 | toolPath = os.path.join(os.getcwd(), "lib") 7 | sys.path.append(toolPath) 8 | 9 | try: 10 | import xcodeproj 11 | except Exception as exception: 12 | print(exception) 13 | 14 | if __name__ == "__main__": 15 | xcodeproj.inputPath() 16 | 17 | -------------------------------------------------------------------------------- /bugly符号表自动上传脚本/bugly/bugly_upload.sh: -------------------------------------------------------------------------------- 1 | # 需要Java版本 jdk-8u341-macosx-x64.dmg 2 | 3 | # 组装参数 4 | # BUGLY_APP_ID 5 | # BUGLY_APP_KEY 6 | # BUNDLE_IDENTIFIER 7 | # App Version 8 | # platform IOS 9 | # inputSymbol 10 | 11 | if [ $ACTION != install ]; then 12 | echo "Xcode build" 13 | exit 0 14 | fi 15 | 16 | if [ "${CONFIGURATION}" == "Debug" ]; then 17 | echo "Debug模式不继续执行脚本" 18 | exit 0 19 | fi 20 | 21 | # 默认是Release的参数 22 | BUGLY_APP_ID="BUGLY_APP_ID" 23 | BUGLY_APP_KEY="BUGLY_APP_KEY" 24 | if [ "${CONFIGURATION}" != "Release" ]; then 25 | BUGLY_APP_ID="debug_BUGLY_APP_ID" 26 | BUGLY_APP_KEY="debug_BUGLY_APP_KEY" 27 | fi 28 | 29 | echo "当前编译模式: ${CONFIGURATION}" 30 | 31 | echo "--------------Product Name: ${PRODUCT_NAME}" 32 | echo "--------------Bundle Identifier: ${PRODUCT_BUNDLE_IDENTIFIER}" 33 | echo "--------------版本号Version: ${MARKETING_VERSION}" 34 | echo "--------------构建Build: ${CURRENT_PROJECT_VERSION}" 35 | 36 | echo "--------------Bugly App ID: ${BUGLY_APP_ID}" 37 | echo "--------------Bugly App key: ${BUGLY_APP_KEY}" 38 | BUGLY_APP_VERSION="${MARKETING_VERSION}(${CURRENT_PROJECT_VERSION})" 39 | echo "--------------Bugly App Version: ${BUGLY_APP_VERSION}" 40 | 41 | 42 | exitWithMessage() { 43 | echo "--------------------------------" 44 | echo -e "${1}" 45 | echo "--------------------------------" 46 | echo "No upload and exit." 47 | echo "----------------------------------------------------------------" 48 | exit 0 49 | } 50 | 51 | 52 | function uploadDSYM { 53 | 54 | DSYM_SRC="$1" 55 | echo "--------------开始上传" 56 | echo "--------------上传命令: java -jar ${BUGLY_SYMBOL_JAR_PATH} -appid ${BUGLY_APP_ID} -appkey ${BUGLY_APP_KEY} -bundleid ${PRODUCT_BUNDLE_IDENTIFIER} -version ${MARKETING_VERSION} -appBuildNo ${CURRENT_PROJECT_VERSION} -platform IOS -inputSymbol ${DSYM_SRC}" 57 | 58 | (java -jar ${BUGLY_SYMBOL_JAR_PATH} -appid ${BUGLY_APP_ID} -appkey ${BUGLY_APP_KEY} -bundleid ${PRODUCT_BUNDLE_IDENTIFIER} -version ${MARKETING_VERSION} -appBuildNo ${CURRENT_PROJECT_VERSION} -platform IOS -inputSymbol ${DSYM_SRC}) || exitWithMessage "上传符号表失败." 0 59 | } 60 | 61 | 62 | # .dSYM生成的文件夹 63 | echo "--------------dSYM所在的文件路径: ${DWARF_DSYM_FOLDER_PATH}" 64 | 65 | BUGLY_SYMBOL_JAR_PATH="${SRCROOT}/script/bugly/buglyqq-upload-symbol.jar" 66 | 67 | for dsymFile in $(find "${DWARF_DSYM_FOLDER_PATH}" -name '你app的名字.*.dSYM'); do 68 | echo "--------------找到 dSYM file: $dsymFile" 69 | uploadDSYM ${dsymFile} 70 | done 71 | -------------------------------------------------------------------------------- /bugly符号表自动上传脚本/bugly/buglyqq-upload-symbol.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollin0-0/PythonToolBox/30ed334e027669cfcbf47d6bdbce70d75ee06ecb/bugly符号表自动上传脚本/bugly/buglyqq-upload-symbol.jar -------------------------------------------------------------------------------- /bugly符号表自动上传脚本/bugly/bugly上传.md: -------------------------------------------------------------------------------- 1 | # 1.安装Java环境 2 | 3 | ## 需要特定版本: 4 | - jdk-8u341-macosx-x64.dmg 5 | 6 | ## 查看Java安装位置: 7 | 8 | 如果本机存在多个版本,需要干掉其他版本的Java 9 | 10 | ``` 11 | /usr/libexec/java_home -V 12 | ``` 13 | 14 | # 将bugly文件夹复制到项目文件夹: 15 | - script/ 16 | 17 | ## 例如: 18 | 19 | ``` 20 | /Users/ios/project/XcodeProject/script/bugly 21 | ``` 22 | 23 | ## 打开Xcode项目 添加 Run Script配置: 24 | 25 | ``` 26 | ${SRCROOT}/script/bugly/bugly_upload.sh 27 | ``` 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /分割字符串/SplitString.py: -------------------------------------------------------------------------------- 1 | 2 | def getReplaceString(aStr): 3 | aList = list(aStr) 4 | newString = "" 5 | for index, item in enumerate(aList): 6 | if index == 0: 7 | newString += "[@[" 8 | # 替换的时候需要引号 9 | newString += "@\"" + item + "\"," 10 | if index == len(aList) - 1: 11 | newString = newString.rstrip(",") 12 | newString += "] componentsJoinedByString:@\"\"]" 13 | print(newString) 14 | 15 | 16 | 17 | def inputString(): 18 | while(True): 19 | str = input("\n请输入需要拆分的字符串:\n") 20 | getReplaceString(str) 21 | 22 | inputString() -------------------------------------------------------------------------------- /分割字符串/desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollin0-0/PythonToolBox/30ed334e027669cfcbf47d6bdbce70d75ee06ecb/分割字符串/desc.png -------------------------------------------------------------------------------- /给文件增加内容修改md5/ModifyMd5.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | import os 4 | import hashlib 5 | import sys 6 | 7 | # 需要处理的文件类型 8 | fileType = [".h", ".m", ".mm"] 9 | 10 | # 需要在文件中追加的内容 11 | appendContent = "\n" 12 | 13 | 14 | if sys.version_info[0] < 3: 15 | print("请确认在python3环境运行该脚本") 16 | os._exit(1) 17 | 18 | 19 | def fileMd5(file, blockSize=2**20): 20 | hash = hashlib.md5() 21 | with open(file, "rb") as f: 22 | while True: 23 | b = f.read(blockSize) 24 | if not b: 25 | break 26 | hash.update(b) 27 | return hash.hexdigest() 28 | 29 | 30 | # 获取文件后缀(包含.,例如1.png返回.png) 31 | def getFileSuffix(filePath): 32 | return os.path.splitext(filePath)[-1] 33 | 34 | 35 | def modifyFile(filePath): 36 | # 判断文件后缀是否符合要求 37 | if getFileSuffix(filePath) not in fileType: 38 | return 39 | print(filePath) 40 | oldMd5 = fileMd5(filePath) 41 | try: 42 | with open(filePath, "a+") as f: 43 | # 写入需要追加的内容 44 | f.write(appendContent) 45 | print("md5 " + oldMd5 + " 修改为: " + fileMd5(filePath)) 46 | except ValueError: 47 | pass 48 | 49 | 50 | def modify(filePath): 51 | # 处理文件 52 | if os.path.isfile(filePath): 53 | print("处理文件:") 54 | modifyFile(filePath) 55 | # 处理文件夹 56 | elif os.path.isdir(filePath): 57 | print("处理文件夹:") 58 | for root, dirs, files in os.walk(filePath, topdown=False): 59 | # 过滤隐藏文件/文件夹 60 | files = [f for f in files if not f[0] == '.'] 61 | for file in files: 62 | fullPath = os.path.join(root, file) 63 | modifyFile(fullPath) 64 | 65 | 66 | # 输入需要处理的文件夹或者文件 67 | def inputDir(): 68 | dirPath = input("请输入需要处理的文件夹路径或者文件路径:\n") 69 | dirPath = dirPath.rstrip() 70 | while not os.path.exists(dirPath): 71 | dirPath = input("请输入需要处理的文件夹路径或者文件路径:\n") 72 | dirPath = dirPath.rstrip() 73 | modify(dirPath) 74 | 75 | 76 | if __name__ == "__main__": 77 | inputDir() -------------------------------------------------------------------------------- /给文件增加内容修改md5/desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rollin0-0/PythonToolBox/30ed334e027669cfcbf47d6bdbce70d75ee06ecb/给文件增加内容修改md5/desc.png --------------------------------------------------------------------------------