/// <summary> /// Filters out JavaScript fromCharCode input /// </summary> /// <param name="input">The input</param> /// <returns>The re-encoded input</returns> internal static string convertFromJSCharcode(string input) { string retval = string.Empty; if (!input.Contains(",")) { return string.Empty; } //Clean the input CleanCharcode(ref input); Regex re = new Regex(string.Format(@" {0} # Match first opening delimiter (?<inner> (?> {0} (?<LEVEL>) # On opening delimiter push level | {1} (?<-LEVEL>) # On closing delimiter pop level | (?! {0} | {1} ) . # Match any char unless the opening )+ # or closing delimiters are in the lookahead string (?(LEVEL)(?!)) # If level exists then fail ) {1} # Match last closing delimiter ", "\\(", "\\)"), RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); MatchCollection mc = re.Matches(input); foreach (Match m in mc) { if (m.Success) { string converted = ""; string[] toconvert = m.Groups["inner"].Value.Split(','); foreach (string charcode in toconvert) { string sCharCode = charcode; //Convert hex ConvertHex(ref sCharCode); //Convert octal ConvertOctal(ref sCharCode); try { ExpressionParser.RPNParser rpn = new ExpressionParser.RPNParser(); Int64 iCharCode = (Int64)rpn.EvaluateExpression(sCharCode, Type.GetType("System.Int64"), false, null); converted += (char)iCharCode; } catch (Exception) { //Put the original input back in converted += sCharCode; } } retval += "[" + converted + "]"; } } return retval; }
/// <summary> /// Filters out JavaScript fromCharCode input /// </summary> /// <param name="input">The input</param> /// <returns>The re-encoded input</returns> internal static string convertFromJSCharcode(string input) { string retval = string.Empty; if (!input.Contains(",")) { return(string.Empty); } //Clean the input CleanCharcode(ref input); Regex re = new Regex(string.Format(@" {0} # Match first opening delimiter (?<inner> (?> {0} (?<LEVEL>) # On opening delimiter push level | {1} (?<-LEVEL>) # On closing delimiter pop level | (?! {0} | {1} ) . # Match any char unless the opening )+ # or closing delimiters are in the lookahead string (?(LEVEL)(?!)) # If level exists then fail ) {1} # Match last closing delimiter ", "\\(", "\\)"), RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); MatchCollection mc = re.Matches(input); foreach (Match m in mc) { if (m.Success) { string converted = ""; string[] toconvert = m.Groups["inner"].Value.Split(','); foreach (string charcode in toconvert) { string sCharCode = charcode; //Convert hex ConvertHex(ref sCharCode); //Convert octal ConvertOctal(ref sCharCode); try { ExpressionParser.RPNParser rpn = new ExpressionParser.RPNParser(); Int64 iCharCode = (Int64)rpn.EvaluateExpression(sCharCode, Type.GetType("System.Int64"), false, null); converted += (char)iCharCode; } catch (Exception) { //Put the original input back in converted += sCharCode; } } retval += "[" + converted + "]"; } } return(retval); }