示例#1
0
        public string ObfuscateVariables(string input)
        {
            string returns = input;

            using (StringReader sr = new StringReader(input))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    bool isVar  = false;
                    bool isFunc = false;
                    if (line.Contains("local"))
                    {
                        isVar = true;
                        string varName = Substring.GetStringBetween(line, "local", "=");
                        varName = varName.Replace(" ", "");
                        Variable var = new Variable();
                        var.oldName = varName;
                        var.newName = getVarName();
                        variables.Insert(varIdx, var);
                        varIdx = varIdx + 1;
                        Regex rgx = new Regex(var.oldName);
                        returns = rgx.Replace(returns, var.newName);
                    }

                    if (line.Contains("\"")) //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                    {
                        string          dumpedstr       = null;
                        MatchCollection allMatchResults = null;
                        var             noob            = "\"";
                        var             regexObj        = new Regex(noob + @"\w*" + noob);
                        allMatchResults = regexObj.Matches(line);
                        foreach (Match m in allMatchResults)
                        {
                            foreach (char ch in m.Value.Replace("\"", ""))
                            {
                                int x = ch;
                                dumpedstr = dumpedstr + "\\" + x.ToString();
                            }
                            string notsocute = m.Value;
                            Regex  rgx       = new Regex(notsocute);
                            returns   = rgx.Replace(returns, "\"" + dumpedstr + "\"");
                            dumpedstr = null;
                        }
                    }

                    if (line.Contains("function"))
                    {
                        if (isVar == false)
                        {
                            isFunc = true;
                            if (line.Contains("="))
                            {
                                string funcName = line;
                                funcName = funcName.Replace("function", "");
                                int index = funcName.LastIndexOf(" =");
                                if (index > 0)
                                {
                                    funcName = funcName.Substring(0, index);
                                }
                                Variable func = new Variable();
                                func.oldName = funcName;
                                func.newName = getVarName();
                                variables.Insert(varIdx, func);
                                varIdx = varIdx + 1;
                                Regex rgx = new Regex(func.oldName);
                                returns = rgx.Replace(returns, func.newName);
                            }
                            else
                            {
                                string funcName = Substring.GetStringBetween(line, "function", "(");
                                funcName = funcName.Replace(" ", "");
                                Variable func = new Variable();
                                func.oldName = funcName;
                                func.newName = getVarName();
                                variables.Insert(varIdx, func);
                                varIdx = varIdx + 1;
                                Regex rgx = new Regex(func.oldName);
                                returns = rgx.Replace(returns, func.newName);
                            }
                        }
                    }
                }
            }
            return(returns);
        }