示例#1
0
        private string encodeKeywords(string script)
        {
            // escape high-ascii values already in the script (i.e. in strings)
            if (Encoding == PackerEncoding.HighAscii) script = escape95(script);
            // create the parser
            ParseMaster parser = new ParseMaster();
            EncodeMethod encode = getEncoder(Encoding);

            // for high-ascii, don't encode single character low-ascii
            Regex regex = new Regex(
                    (Encoding == PackerEncoding.HighAscii) ? "\\w\\w+" : "\\w+"
                );
            // build the word list
            encodingLookup = analyze(script, regex, encode);

            // encode
            parser.Add((Encoding == PackerEncoding.HighAscii) ? "\\w\\w+" : "\\w+",
                new ParseMaster.MatchGroupEvaluator(encodeWithLookup));

            // if encoded, wrap the script in a decoding function
            return (script == string.Empty) ? "" : bootStrap(parser.Exec(script), encodingLookup);
        }
示例#2
0
 //zero encoding - just removal of whitespace and comments
 private string basicCompression(string script)
 {
     // ReSharper disable UseObjectOrCollectionInitializer
     ParseMaster parser = new ParseMaster();
     // ReSharper restore UseObjectOrCollectionInitializer
     // make safe
     parser.EscapeChar = '\\';
     // protect strings
     parser.Add("'[^'\\n\\r]*'", IGNORE);
     parser.Add("\"[^\"\\n\\r]*\"", IGNORE);
     // remove comments
     parser.Add("\\/\\/[^\\n\\r]*[\\n\\r]");
     parser.Add("\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\/");
     // protect regular expressions
     parser.Add("\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)", "$2");
     parser.Add("[^\\w\\$\\/'\"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?", IGNORE);
     // remove: ;;; doSomething();
     if (SpecialChars)
         parser.Add(";;[^\\n\\r]+[\\n\\r]");
     // remove redundant semi-colons
     parser.Add(";+\\s*([};])", "$2");
     // remove white-space
     parser.Add("(\\b|\\$)\\s+(\\b|\\$)", "$2 $3");
     parser.Add("([+\\-])\\s+([+\\-])", "$2 $3");
     parser.Add("\\s+");
     // done
     return parser.Exec(script);
 }
示例#3
0
        private string encodeSpecialChars(string script)
        {
            ParseMaster parser = new ParseMaster();
            // replace: $name -> n, $$name -> na
            parser.Add("((\\$+)([a-zA-Z\\$_]+))(\\d*)",
                new ParseMaster.MatchGroupEvaluator(encodeLocalVars));

            // replace: _name -> _0, double-underscore (__name) is ignored
            Regex regex = new Regex("\\b_[A-Za-z\\d]\\w*");

            // build the word list
            encodingLookup = analyze(script, regex, encodePrivate);

            parser.Add("\\b_[A-Za-z\\d]\\w*", new ParseMaster.MatchGroupEvaluator(encodeWithLookup));

            script = parser.Exec(script);
            return script;
        }