一、环境安装
代码脚本需要用到Lua语言,因此,需要自行百度安装配置好Lua的环境。
二、使用步骤
1.运行Lua代码生成C#垃圾代码
Windows在CMD中运行,Mac在终端运行。
命令如下:
lua garbage_code_generater.lua -o output -c 5
参数说明
-h: 帮助
-o: 输出路径, 默认值=“garbate”
-c: 生成类数量, 默认值=400
-mc: 类方法数量, 默认值=30
-pc: 类变量数量, 默认值=30
-ac: 类属性数量, 默认值=30
-verbose: 输出每一个类文件名
-q: 安静模式, 不输出任何东西
2.Lua文件的代码
代码生成后会在Output文件夹下生成5个脚本,Lua的代码如下所示:
local os = os
local math = math
local io = io
math.randomseed(os.time())
local charlist =
{
"Script","Contraller","Select","Game","Manager","Field","Procedure","Print",
"Number","Selected","Want","Window","Message","Dialog","Example","Create","Insert","Related",
"Item","Edit","Marked","Area","Paremeter","Then","Variable","Tab","Up","String","Each","Active",
"Topic","Start","Mode","Selection","Function","Word","Make","Right","Value","Button","Index",
"Without","Appear","Left","Save","Next","Off","Following","Control","Only","User","End","System",
"Contain","Time","Letter","Data","Setting","Desire","Positiion","Down","Task","View","Switch",
"Include","Get","Default","Structure","Into","Path","Blank","Open","Add","Enable"
}
local charlist_length = #charlist
local header_charlist =
{
"Student","Player","Wall","Quality","Compile","Period",
"Number","Selected","Want","Window","Message","Dialog","Example","Create","Insert","Related",
"Item","Edit","Marked","Area","Paremeter","Then","Variable","Tab","Up","String","Each","Active",
"Topic","Start","Mode","Selection","Function","Word","Make","Right","Value","Button","Index",
"Without","Appear","Left","Save","Next","Off","Following","Control","Only","User","End","System",
"Contain","Time","Letter","Data","Setting","Desire","Positiion","Down","Task","View","Switch",
"Include","Get","Default","Structure","Into","Path","Blank","Open","Add","Enable"
}
local header_charlist_length = #header_charlist
local function getChar(chars, charscount, i)
local idx = i ;
return chars[idx];
end
local function getRandomChar()
return getChar(charlist, charlist_length, math.random(1, charlist_length))
end
local function getRandomHChar()
return getChar(header_charlist, header_charlist_length, math.random(1, header_charlist_length))
end
local function getRandomName(l)
local r = getRandomHChar()
for _=2,l do
r = r .. getRandomChar()
end
return r
end
local base_type_and_default = {
["bool"] = "false",
["int"] = "0",
["float"] = "0.0f",
["double"] = "0.0",
["string"] = "null"
}
local base_type_randomfunction =
{
["bool"] = function(a, b, c)
local r = math.random(1, 5)
if r == 1 then
return {
a .. " = " .. b .. " && " .. c ..";"