在cpp文件中加入垃圾代码

有的项目因为是二次开发,有一定概率会被ios审核为重复的换皮项目,因而被拒绝.

在程序结尾加入垃圾代码,可改变输出的二进制文件,不是很确定c++在编译的时候,这类没有调用的方法以及声明的变量,会不会加入编译,之前一个被拒的项目,后面使用这个方法提交过两次,但是中间自己做过代码混淆

代码是c#写的,直接在vs新建控制台程序,替换类即可使用:

class Program
    {
        //config
        //随机代码块
        static int _blockCount = 50;
        //声明参数
        static int _argCount = 100;

        static void Main(string[] args)
        {
            string path = "";
            while (true)
            {
                Console.WriteLine("input the cpp file path:");
                path = Console.ReadLine();
                path = path.Trim();
                if(path.Length == 0)
                {
                    continue;
                }
                List<FileInfo> files = GetFilesInDic(path);

                int count = 0;
                foreach (FileInfo file in files)
                {
                    if (file.Extension == ".cpp")
                    {
                        Console.WriteLine("写入:" + file.FullName);
                        StreamWriter sw = new StreamWriter(file.FullName, true);
                        string writeStr = GetMethodAllStr();
                        sw.WriteLine(writeStr);
                        sw.Close();
                        count += writeStr.Length;
                    }
                }
                Console.WriteLine("完成!\r\n" + "共写入:" + count.ToString() + "字");

            }
        }

        static List<FileInfo> GetFilesInDic(string path)
        {
            List<FileInfo> list = new List<FileInfo>();

            DirectoryInfo root = new DirectoryInfo(path);
            FileInfo[] files = root.GetFiles();
            DirectoryInfo[] dics = root.GetDirectories();
            list.AddRange(files);
            foreach(DirectoryInfo info in dics)
            {
                list.AddRange(GetFilesInDic(info.FullName));
            }

            return list;
        }

        static string lineStr = "\r\n";
        static string specialStr = "_";

        static Random rd = new Random();

        static List<string> strList = new List<string>()
        {
            "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
            "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
        };

        static List<string> argTypeList = new List<string>() { "float" , "int" ,"string" };

        static List<string> blockMethod = new List<string>() {
            "if(!true){}",
            "if(!false){}",
            "if(true){}",
            "if(false){}"
        };

        static string GetMethodAllStr()
        {
            string randomType = GetRandomType();

            string str = randomType + " ";
            //方法名
            str += GetName();
            //方法参数
            str += "(" + GetRandomType() + " " + GetName() + " )" + lineStr;
            str += "{" + lineStr;
            //获取随机代码块
            str += GetRandomBlock(GetRandomNum(_blockCount));
            //定义随机变量
            List<string> namelist = new List<string>();
            string argContent = "";
            int argCount = GetRandomNum(_argCount);
            for (int i = 0; i < argCount; ++i)
            {
                argContent += randomType;
                string argName = GetName();
                namelist.Add(argName);
                argContent += (" " + argName + " = ");
                argContent += GetContentByType(randomType);
                argContent += lineStr;
            }
            str += argContent + lineStr;

            string rtnArgName = GetName();
            string headName = randomType + " " + rtnArgName;
            headName += " = ";
            for(int i = 0; i< namelist.Count;++i)
            {
                headName += namelist[i];
                if(i == namelist.Count - 1)
                {
                    headName += ";";
                }
                else
                {
                    headName += "+";
                }
            }
            str += headName;


            str += lineStr;
            str += "return " + rtnArgName + ";";
            str += lineStr;
            str += "}";

            return str;
        }
        //根据类型获取随机内容
        static string GetContentByType(string _type)
        {
            string str = "";
            if(_type == "float")
            {
                str += GetRandomNum(100);
                str += ".";
                str += GetRandomNum(100);
                str += ";";
            }
            else if(_type == "int")
            {
                str += GetRandomNum(1000);
                str += ";";
            }
            else if(_type == "string")
            {
                str += "\"";
                str += GetName();
                str += "\"";
                str += ";";
            }

            return str;
        }
        
        //固定长度特殊字符
        static string GetSpecialStr(int count)
        {
            string str = "";
            for(int i = 0;i< count; ++i)
            {
                str += specialStr;
            }
            return str;
        }
        //随机数
        static int GetRandomNum(int maxNum)
        {
            int rInt = rd.Next();
            return (rInt % maxNum + 1);
        }
        //固定长度随机字符串
        static string GetRandomStr(int length)
        {
            string str = "";
            for(int i = 0; i< length; ++i)
            {
                str += strList[GetRandomNum(strList.Count-1)];
            }
            return str;
        }
        //名字
        static string GetName()
        {
            string str = "";
            str += GetSpecialStr(GetRandomNum(5));
            str += GetRandomStr(GetRandomNum(5));
            return str;
        }
        //参数类型
        static string GetRandomType()
        {
            return argTypeList[GetRandomNum(argTypeList.Count - 1)];
        }
        //指定数量随机代码块
        static string GetRandomBlock(int count)
        {
            string str = "";

            for (int i = 0; i < count; ++i)
            {
                str += blockMethod[GetRandomNum(blockMethod.Count - 1)];
                str += lineStr;
            }

            return str;
        }
    }

 

输出的代码:

 

Gitee地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值