标签:ext 路径 lin 生成器 creat tools 苹果 assets ase
苹果提审中,被4.3重复应用打回来很常见(诸如上马甲包等),而首先一步是面对机审,我们的处理方法是通过写工具生成一些垃圾代码来避开苹果机审,以下是整个实现:
using LuaFramework;
using UnityEditor;
using System;
using System.Text;
using System.IO;
//文件定义:垃圾代码生成器
//一、设计要点:
//1、用当前时间+生成代码序号生成md5字符,用md5字符命名类名、方法名、变量名等
//2、随机一种范式,用生成的类名等作为参数生成该范式代码
//3、生成GarbageCodeManager类调用所有生成的代码
//二、范式生成要点:
//1、用正常c#写代码
//2、用ChangeClassFile2CodeCreateTool.py http://www.cnblogs.com/ChengShuKaiShi/p/7750557.html工具将正常代码转成生成该代码的代码(类名、方法名等已替换为参数)
//三、游戏调用
//1、在main.cs中通过UNITY_IPHONE && SDK宏控制调用GarbageCodeManager.CallAllGarbageCode()调用生成的代码
//作者:青_树
//时间:2017/10/20
public class GarbageCodeTool
{
private const string namespaceName = "LuaFramework"; //生成代码的命名空间
private const string garbageCodeManagerName = "GarbageCodeManager"; //管理所有垃圾代码的文件名
private static string mstCreateCodeFilePath; //生成代码路径
private const int maxFileCount = 100; //垃圾代码个数
private const int tplCount = 1; //生成垃圾代码范式个数
//范式委托:命名空间,类名,入口方法名,入口方法参数1,入口方法参数2,入口方法参数3
private delegate bool GenerateCodeHandle(string namespaceName,string className,string methonName,string param1, string param2, string param3);
private static GenerateCodeHandle[] arrGenerateCodeHandle;
//生成代码
[MenuItem("Tools/GenerateGarbageCode")]
static void GenerateGarbageCode() {
//初始化所有范式
InitAllTpl();
//删除旧目录代码
if (Directory.Exists(mstCreateCodeFilePath))
{
Directory.Delete(mstCreateCodeFilePath, true);
}
AssetDatabase.Refresh();
AssetDatabase.SaveAssets();
//重新创建目录
Directory.CreateDirectory(mstCreateCodeFilePath);
Directory.CreateDirectory(mstCreateCodeFilePath + "/Code");
string timeNow = DateTime.Now.ToLongDateString();
string[] arrClassName = new string[maxFileCount];
string[] arrMethonName = new string[maxFileCount];
//生成代码
for (int i = 0; i < maxFileCount; i++) {
//根据当前时间+i 生成md5值
string md5 = Util.md5(timeNow + i.ToString());
md5 = "_" + md5;
//用md5值生成文件名、方法名、参数名
string className = md5;
string methonName = md5 + "m";
string param1 = md5 + "a";
string param2 = md5 + UnityEngine.Random.Range(0, 100);
string param3 = md5 + "c";
//随机生成一种范式文件
int randNum = UnityEngine.Random.Range(0, tplCount);
if (arrGenerateCodeHandle[randNum] != null)
{
bool isSuccess = arrGenerateCodeHandle[randNum](namespaceName, className, methonName, param1, param2, param3);
if (isSuccess) {
arrClassName[i] = className;
arrMethonName[i] = methonName;
}
}
else
{
Util.LogError("不存在范式,索引:"+ randNum.ToString());
}
}
//根据生成的文件生成调用所有函数的文件
string managerFilePath = Path.Combine(mstCreateCodeFilePath, garbageCodeManagerName + ".cs");
CreateGarbageManagerClass(managerFilePath, garbageCodeManagerName,namespaceName, arrClassName, arrMethonName);
AssetDatabase.Refresh();
AssetDatabase.SaveAssets();
EditorUtility.DisplayDialog("GenerateGarbageCode","生成完毕!", "确定");
}
//初始化所有范式
static void InitAllTpl() {
mstCreateCodeFilePath = UnityEngine.Application.dataPath + "/LuaFramework/Scripts/GarbageCode";
arrGenerateCodeHandle = new GenerateCodeHandle[tplCount];
arrGenerateCodeHandle[0] = CreateTpl1;
}
//生成调用所有生成的范式代码
public static void CreateGarbageManagerClass(string stSaveFilePath, string className1, string stNameSpace,string[] allClassName,string[] allMethonName)
{
if (string.IsNullOrEmpty(stSaveFilePath))
{
return;
}
StringBuilder stringBuilder = new StringBuilder();
if (!string.IsNullOrEmpty(stNameSpace))
{
stringBuilder.AppendFormat(string.Format("namespace {0}\n", stNameSpace));
stringBuilder.AppendLine("{");
}
stringBuilder.AppendLine("using UnityEngine;");
stringBuilder.AppendLine("using System.Collections;");
stringBuilder.AppendLine("");
stringBuilder.AppendLine("namespace LuaFramework {");
stringBuilder.AppendLine(" //垃圾代码管理器");
stringBuilder.AppendFormat("public class {0}\n", className1);
stringBuilder.AppendLine(" {");
stringBuilder.AppendLine(" //调用所有垃圾代码");
stringBuilder.AppendLine(" public static void CallAllGarbageCode() {");
//调用所有垃圾代码
for (int i = 0; i < allClassName.Length; i++) {
string className = allClassName[i];
string methonName = allMethonName[i];
if (className == "" || methonName == "") {
continue;
}
int randa = UnityEngine.Random.Range(0, 1000);
int randb = UnityEngine.Random.Range(0, 1000);
int randc = UnityEngine.Random.Range(0, 1000);
stringBuilder.AppendFormat(" {0} _{1} = new {2}();\n", className, className, className);
if (randc > 500)
{
stringBuilder.AppendFormat(" _{0}.{1}({2},{3});\n", className, methonName, randa, randb);
}
else
{
stringBuilder.AppendFormat(" _{0}.{1}({2},{3},{4});\n", className, methonName, randa, randb,randc);
}
stringBuilder.AppendLine("");
}
stringBuilder.AppendLine(" }");
stringBuilder.AppendLine(" }");
stringBuilder.AppendLine("}");
stringBuilder.AppendLine("");
if (!string.IsNullOrEmpty(stNameSpace))
{
stringBuilder.AppendLine("}");
}
File.WriteAllText(stSaveFilePath, stringBuilder.ToString());
}
//模版1
public static bool CreateTpl1(string namespaceName , string className, string methonName, string param1, string param2, string param3)
{
string fileName = Path.Combine(mstCreateCodeFilePath + "/Code" , className + ".cs");
if (string.IsNullOrEmpty(fileName))
{
return false;
}
StringBuilder stringBuilder = new StringBuilder();
if (!string.IsNullOrEmpty(namespaceName))
{
stringBuilder.AppendFormat(string.Format("namespace {0}\n", namespaceName));
stringBuilder.AppendLine("{");
}
stringBuilder.AppendLine("");
stringBuilder.AppendFormat("public class {0} \n", className);
stringBuilder.AppendLine("{");
stringBuilder.AppendFormat(" public int {0}(int {1},int {2},int {3} = 1) ",methonName, param1, param2, param3);
stringBuilder.AppendLine("{");
stringBuilder.AppendFormat(" int test1 = {0}Add({1}, {2});\n", className, param1, param2);
stringBuilder.AppendFormat(" return {0}Sub(test1, {1});\n", className, param3);
stringBuilder.AppendLine(" }");
stringBuilder.AppendLine("");
stringBuilder.AppendFormat(" int {0}Add(int a{1}b, int b{2}d) ", className, param1, param2);
stringBuilder.AppendLine("{");
stringBuilder.AppendFormat(" a{0}b += UnityEngine.Random.Range(0, 100);", param1);
stringBuilder.AppendFormat(" return a{0}b + b{1}d;", param1, param2);
stringBuilder.AppendLine(" }");
stringBuilder.AppendLine("");
stringBuilder.AppendFormat(" int {0}Sub(int a{1}c, int b{2}e) ", className, param1, param2);
stringBuilder.AppendLine("{");
stringBuilder.AppendFormat(" b{0}e *= 100;", param2);
stringBuilder.AppendFormat(" return a{0}c - b{1}e;", param1, param2);
stringBuilder.AppendLine(" }");
stringBuilder.AppendLine("}");
if (!string.IsNullOrEmpty(namespaceName))
{
stringBuilder.AppendLine("}");
}
File.WriteAllText(fileName, stringBuilder.ToString());
return true;
}
}
标签:ext 路径 lin 生成器 creat tools 苹果 assets ase
原文地址:http://www.cnblogs.com/ChengShuKaiShi/p/7750541.html