方式 1:
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
#第一步:首先生成一个500位的数组 驼峰类型的元素 用作文件名 eg:AsdfdfGsd
import random
import os,sys
import string
first = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
second = "abcdefghijklmnopqrstuvwxyz"
number = "345"
index = 0
array = [\]
for i in range(500):
final=(random.choice(first))
index = random.randint(3, 5)
for i in range(index):
final+=(random.choice(second))
final += (random.choice(first))
for i in range(index):
final+=(random.choice(second))
array.append(final)
print (array)
#第二步:
#用上边生成的数组来创建对应的.h和.m文件
# -*- coding: utf-8 -*-
import random
import os
import string
#创建.h文件
def text_createH(fileNmae,msg,msg1,propertyNumber,methodArray,msg3):
full_path = sys.path[0] + '/ReplaceDemo/' + fileNmae + '.h'
file = open(full_path, 'w')
file.write('//\n// '+fileNmae+'.h\n// SajiaoShopping\n\n// Created by 某 波 bo on 15/10/23.\n// Copyright ? 2017年 阿里郎. All rights reserved.\n//\n\n')
file.write(msg)
file.write(msg1)
propryNameArray = []
for index in range(1,propertyNumber):
propryNameArray.append(random.choice(array))
propryNameArray = list(set(propryNameArray))
for propertyName in propryNameArray:
file.write('@property(nonatomic,strong)'+random.choice(classArray)+' * '+propertyName+';\n')
file.write('\n\n')
for methodName in methodArray:
file.write('- (void)pushTo'+methodName+'VC:(NSDictionary *)info;\n')
file.write(msg3)
file.close()
print('Done')
#创建.m文件
def text_createM(fileNmae,msg,msg1,methodArray,msg3):
full_path = sys.path[0] + '/ReplaceDemo/' + fileNmae + '.m'
file = open(full_path, 'w')
file.write('//\n// '+fileNmae+'.m\n// SajiaoShopping\n\n// Created by 某 波 bo on 15/10/23.\n// Copyright ? 2017年 阿里郎. All rights reserved.\n//\n\n')
file.write(msg)
file.write(msg1)
for methodName in methodArray:
file.write('- (void)pushTo'+methodName+'VC:(NSDictionary *)info\n{\n\n NSMutableArray *array = [NSMutableArray array];\n')
number = random.randint(3, 10)
for i in range(1,number):
file.write(' [array addObject:@"'+random.choice(array)+'"];\n')
file.write('\n}\n\n')
file.write(msg3)
file.close()
print('Done')
classArray = ['NSString','UILabel','NSDictionary','NSData','UIScrollView','UIView']
array = ['HwxrFvrj', 'QnzduQbtdd', 'PvcrwLtqhf', 'UvdhDbjn', 'SuntmyTxvyzg', 'CvlxwBipbp', 'GzrdyzIbimvz', 'CqsjqMmgsp', 'OxaaeuWjhasc', 'NjiardRvwgbi', 'NcculmLtpljq', 'ApoqQrll', 'GkgokDyvjb', 'EblldkVouplj', 'KfdrFvnw', 'SfhyhObftc', 'SmruByoc', 'YzcccvXmpmit', 'OmqvaHpxat', 'XzytsUyvyd', 'MjforNnnyi', 'ZvjhuIdogs', 'BzfrxzSeahxc', 'PycycwFjtpny', 'XvngtoSedljr', 'DktiaCbucd', 'AqbplNuodc', 'MzkvgZuala', 'KdwzIoej', 'AaynatUpqcfd', 'IyvwhZvtjc', 'UmijGmsy', 'AoayndXxghym']
array = list(set(array))
for name in array:
number = random.randint(3, 10)
methodArray = []
for i in range(1,5):
methodArray.append(random.choice(array))
methodArray = list(set(methodArray))#数组去重
text_createH(name+'ViewController', '#import <UIKit/UIKit.h>\n','@interface '+name+ 'ViewController:'+ 'UIViewController\n\n',number,methodArray,'\n\[email protected]')
text_createM(name+'ViewController', '#import "'+name+'ViewController.h"\n\n' '@interface '+ name+'ViewController()\n\n @end\n\n','@implementation '+name+'ViewController\n\n- (void)viewDidLoad { \n\n [super viewDidLoad];\n\n}\n\n',methodArray,'\n\[email protected]')
full_path 代表垃圾文件生成路径,第一次 file.write 的是类的注释,包含工程名、类名、作者,这种方式生成的内容无意义,所以很可能过不了审核。脚本原文
方式 2:
使用 KLGenerateSpamCode 扫描工程中的代码,生成同等数量的 Category 文件,文件中即是同等方法数量的垃圾代码。
KLGenerateSpamCode 工程 -> Edit scheme -> Run -> Arguments Passed On Launch 添加。
Trash 是放垃圾代码的文件夹,trash 是分类名。
或者用终端执行命令
./GenerateSpamCode /Users/CJ/Desktop/ReplaceDemo/ReplaceDemo -spamCodeOut /Users/CJ/Desktop/Trash trash
第一条路径是马甲包工程,第二条路径是存放垃圾代码目录路径。
两种方式都会自动在指定路径下生成 Trash 文件夹。
原文地址:https://www.cnblogs.com/dins/p/la-ji-dai-ma.html
时间: 2024-10-06 11:38:42