From ab2311f972489b6f3bfbb2b0cb0b9cc9711e7aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=AF=E7=A3=8A?= Date: Fri, 31 Aug 2018 16:52:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8A=A5=E2=80=9C?= =?UTF-8?q?=E7=BC=BA=E5=B0=91=E5=9E=83=E5=9C=BE=E4=BB=A3=E7=A0=81=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=B0=83=E7=94=A8=E5=90=8D=E2=80=9D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20#35=20#33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ KLGenerateSpamCode/main.m | 10 ++-------- 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 KLGenerateSpamCode.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/KLGenerateSpamCode.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/KLGenerateSpamCode.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/KLGenerateSpamCode.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/KLGenerateSpamCode/main.m b/KLGenerateSpamCode/main.m index 82b1f6c..05326c3 100644 --- a/KLGenerateSpamCode/main.m +++ b/KLGenerateSpamCode/main.m @@ -248,9 +248,6 @@ int main(int argc, const char * argv[]) { printf("缺少垃圾代码函数调用名,或参数名\"%s\"不合法(需要字母开头)\n", [gSpamCodeFuncationCallName UTF8String]); return 1; } - } else { - printf("缺少垃圾代码函数调用名\n"); - return 1; } i++; @@ -261,9 +258,6 @@ int main(int argc, const char * argv[]) { printf("缺少 NewClass 代码函数调用名,或参数名\"%s\"不合法(需要字母开头)\n", [gNewClassFuncationCallName UTF8String]); return 1; } - } else { - printf("缺少 NewClass 代码函数调用名\n"); - return 1; } continue; } @@ -504,7 +498,7 @@ void generateSpamCodeFile(NSString *outDirectory, NSString *mFilePath, GSCSource [mFileMethodsString appendString:@"}\n"]; if (methodCallName.length > 0) { - if (categoryCallFuncString.length <= 0) { + if (gSpamCodeFuncationCallName && categoryCallFuncString.length <= 0) { [categoryCallFuncString appendFormat:@"static inline NSInteger %@() {\nNSInteger ret = 0;\n", gSpamCodeFuncationCallName]; } [categoryCallFuncString appendFormat:@"ret += [%@ %@:%u] ? 1 : 0;\n", className, methodCallName, arc4random_uniform(100)]; @@ -520,7 +514,7 @@ void generateSpamCodeFile(NSString *outDirectory, NSString *mFilePath, GSCSource } if (newClassMethodCallName.length > 0) { - if (newClassCallFuncString.length <= 0) { + if (gNewClassFuncationCallName && newClassCallFuncString.length <= 0) { [newClassCallFuncString appendFormat:@"static inline NSInteger %@() {\nNSInteger ret = 0;\n", gNewClassFuncationCallName]; } [newClassCallFuncString appendFormat:@"ret += [%@ %@:%u] ? 1 : 0;\n", newClassName, newClassMethodCallName, arc4random_uniform(100)]; From 31677dd515054d947f8e1835ddf239bffc79ae38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=AF=E7=A3=8A?= Date: Fri, 31 Aug 2018 16:52:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e787fb9..5c7d6bb 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ $ ./GenerateSpamCode \ - *(必填)* **源码文件夹绝对路径**(如:`/Users/kelei/Documents/work/git/projectName/source`) - **-modifyProjectName [原名称]>[新名称]** 修改工程名。程序会修改`原名称-Swift.h`、`Podfile`、`原名称-Bridging-Header.h`、`源码文件夹绝对路径`、`原名称.xcodeproj`和`原名称.xcworkspace`的名称和内容。*`Podfile`被修改后需要手动`pod install`* - **-modifyClassNamePrefix [工程文件 xcodeproj 绝对路径] [原前缀]>[新前缀]** 修改源代码类名前缀。程序会扫描`源码文件夹绝对路径`下的 .h .swift 文件,修改文件名,修改使用该类名的代码,修改`工程文件`中的文件名。文件名有`原前缀`的会修改成`新前缀`,如:`原前缀ViewController`变成`新前缀ViewController`;没有`原前缀`的会增加`新前缀`,如:`ViewController`变成`新前缀ViewController`。 -- **-spamCodeOut [垃圾代码文件输出目录] [垃圾代码方法增加的参数名]** 生成垃圾代码。程序会扫描`源码文件夹绝对路径`下的 .m .swift 文件中的类和方法,并生成`category`和`extension`文件,文件中的方法是在代码原方法的基础上增加`垃圾代码方法增加的参数名`参数。如:`-spamCodeOut /dir AppLog`,`- (void)setupKeys {}`>`- (void)setupKeysAppLog:(NSString *)appLog {}`,`- (void)foo:(NSString *)str {}`>`- (void)foo:(NSString *)str appLog:(NSString *)appLog {}` -- **-ignoreDirNames [忽略文件夹名称字符串]** 忽略这些文件夹,对`-modifyClassNamePrefix`和`-spamCodeOut`参数有效。目前只会忽略`源码文件夹绝对路径`下一级的这些目录。如:`/p/s -ignoreDirNames categorys`,那么`/p/s/categorys`会被忽略,但`/p/s/viewControllers/categorys`不会忽略。 +- **-spamCodeOut [垃圾代码文件输出目录] [垃圾代码方法增加的参数名]** 生成垃圾代码。程序会扫描`源码文件夹绝对路径`下的 .m .swift 文件中的类和方法,并生成`category`和`extension`文件,文件中的方法是在代码原方法的基础上增加`垃圾代码方法增加的参数名`参数。如:`-spamCodeOut /dir AppLog `,会将`- (void)setupKeys {}`生成为`+ (BOOL)setupKeysAppLog:(NSInteger)AppLog { return AppLog % 20 == 0; }`,会将`- (void)foo:(NSString *)str {}`生成为`+ (BOOL)fooAppLog:(NSInteger)AppLog { return AppLog % 23 == 0; }` +- **-ignoreDirNames [忽略文件夹名称字符串]** 忽略这些文件夹,对`-modifyClassNamePrefix`、`-spamCodeOut`和`-deleteComments`参数有效。目前只会忽略`源码文件夹绝对路径`下一级的这些目录。如:`/p/s -ignoreDirNames categorys`,那么`/p/s/categorys`会被忽略,但`/p/s/viewControllers/categorys`不会忽略。 - **-handleXcassets** 修改`xxx.xcassets`文件夹中的 png 资源文件名,同时也`Contents.json`文件中的关联名称,不会影响代码中使用图片。 - **-deleteComments** 删除工程目录下 .h .m .swift 文件中的注释和空行。 From fe4d578fee802aa0ebe8a5c61f10097038360dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Czhengqizhong=E2=80=9D?= Date: Tue, 4 Dec 2018 20:55:40 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=89=8D=E7=BC=80?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=98=AFcategory=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KLGenerateSpamCode/main.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/KLGenerateSpamCode/main.m b/KLGenerateSpamCode/main.m index 05326c3..a0f6b28 100644 --- a/KLGenerateSpamCode/main.m +++ b/KLGenerateSpamCode/main.m @@ -900,7 +900,15 @@ void modifyClassNamePrefix(NSMutableString *projectContent, NSString *sourceCode if ([fileName hasPrefix:oldName]) { newClassName = [newName stringByAppendingString:[fileName substringFromIndex:oldName.length]]; } else { - newClassName = [newName stringByAppendingString:fileName]; + //处理是category的情况。当是category时,修改+号后面的类名前缀 + NSString *oldNamePlus = [NSString stringWithFormat:@"+%@",oldName]; + if ([fileName containsString:oldNamePlus]) { + NSMutableString *fileNameStr = [[NSMutableString alloc] initWithString:fileName]; + [fileNameStr replaceCharactersInRange:[fileName rangeOfString:oldNamePlus] withString:[NSString stringWithFormat:@"+%@",newName]]; + newClassName = fileNameStr; + }else{ + newClassName = [newName stringByAppendingString:fileName]; + } } // 文件名 Const.ext > DDConst.ext From 7357742a0e632ee7c4b892d6a6344b6dde942529 Mon Sep 17 00:00:00 2001 From: ranajagveer <48042866+ranajagveer@users.noreply.github.com> Date: Tue, 26 Mar 2019 19:39:57 +0530 Subject: [PATCH 4/4] Translated in English --- ReadMeEnglish | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 ReadMeEnglish diff --git a/ReadMeEnglish b/ReadMeEnglish new file mode 100644 index 0000000..649bbb5 --- /dev/null +++ b/ReadMeEnglish @@ -0,0 +1,55 @@ +KLGenerateSpamCode junk code generator +This tool is used to respond to Apple's review of duplicate applications (Guideline 4.3 Design Spam) to avoid the probability of Apple machine detection. + +The main function +Modify project name +Modify the class name prefix +Scan the code in the project to generate an equal number of Category files, and the same amount of garbage code in the file. +Modify the png resource file name in the xxx.xcassets folder. +Remove all comments and blank lines from the code. +use +Use source code +Download the source code. +Open the project with Xcode and configure the parameters. As shown + + +run +Execute GenerateSpamCode in the terminal using a binary file +$ ./GenerateSpamCode \ +/Users/kelei/Documents/work/git/projectName/source \ +-deleteComments + + +Parameter Description + +-(Required) Absolute path to the source folder (eg: /Users/kelei/Documents/work/git/projectName/source) + +-modifyProjectName [Original Name]>[New Name] Modify the project name. The program will modify the original name - Swift.h, Podfile, the original name - Bridging-Header.h, the absolute path of the source folder, the original name .xcodeproj and the name and content of the original name .xcworkspace. Podfile needs to be manually pop installed after being modified + +-modifyClassNamePrefix [project file xcodeproj absolute path] [original prefix]>[new prefix] Modify the source code class name prefix. The program will scan the .h .swift file in the absolute path of the source folder, modify the file name, modify the code using the class name, and modify the file name in the project file. If the file name has the original prefix, it will be modified into a new prefix. For example, the original prefix ViewController becomes the new prefix ViewController; if there is no original prefix, a new prefix will be added, such as: ViewController becomes the new prefix ViewController. + +-spamCodeOut [junk code file output directory] [parameter name added by junk code method] Generate garbage code. The program will scan the classes and methods in the .m .swift file in the absolute path of the source folder, and generate the category and extension files. The method in the file is to add the parameter name parameter added by the garbage code method based on the original code method. For example: -spamCodeOut /dir AppLog will generate - (void)setupKeys {} as + (BOOL)setupKeysAppLog:(NSInteger)AppLog { return AppLog % 20 == 0; }, will - (void)foo:(NSString *)str {} is generated as + (BOOL)fooAppLog:(NSInteger)AppLog { return AppLog % 23 == 0; } + +-ignoreDirNames [Ignore folder name strings] Ignore these folders, valid for the -modifyClassNamePrefix, -spamCodeOut, and -deleteComments parameters. Currently only these directories under the absolute path of the source folder are ignored. For example: /p/s -ignoreDirNames categorys, then /p/s/categorys will be ignored, but /p/s/viewControllers/categorys will not be ignored. + +-handleXcassets Modify the png resource file name in the xxx.xcassets folder, as well as the associated name in the Contents.json file, without affecting the use of images in the code. +-deleteComments Deletes comments and blank lines in the .h .m .swift file in the project directory. + + +Also modify the image hash value method +Use ImageMagick to do light compression on png images without losing image quality, and change the image file hash value. method: + +Install ImageMagick, brew install imagemagick +Compress all png files in the project directory, find . -iname "*.png" -exec echo {} \; -exec convert {} {} \; + +Experience +As far as my submission in 2017-11 months is concerned, I only need to make the following changes to get on the vest. + +Modify project name +Modify the class name prefix +Modify image file Hash value +Modify the image file name in .xcassets +Packed with another computer +Known issue +The generated garbage code file may be a private class implemented in the .m file. The compiled garbage code may report an error, delete the garbage code .h .m file and can. +