Пример #1
0
        private static void getFuns(VideoInfo SVD)
        {
            var link = string.Format("https://www.youtube.com{0}", SVD.jsFile);

            var _root = WebHelper.GetPageSouce(link);

            Debug.SaveFile(_root, "jsfile");

            string TryGetDeciphererFuncBody()
            {
                var funcName = Regex.Match(_root, @"(\w+)=function\(\w+\){(\w+)=\2\.split\(\x22{2}\);.*?return\s+\2\.join\(\x22{2}\)}")
                               .Groups[0]
                               .Value;

                return(funcName);
            }

            Debug.SaveFile(TryGetDeciphererFuncBody(), "DeciphererFuncBody");

            string TryGetDeciphererDefinitionBody(string body)
            {
                var objName = Regex.Match(body, "([\\$_\\w]+).\\w+\\(\\w+,\\d+\\);")
                              .Groups[1]
                              .Value;

                var escapedObjName = Regex.Escape(objName);

                return(Regex.Match(_root, $@"var\s+{escapedObjName}=\{{(\w+:function\(\w+(,\w+)?\)\{{(.*?)\}}),?\}};", RegexOptions.Singleline)
                       .Groups[0]
                       .Value);
            }

            Debug.SaveFile(TryGetDeciphererDefinitionBody(TryGetDeciphererFuncBody()), "DeciphererDefinitionBody");

            var deciphererFuncBody =
                TryGetDeciphererFuncBody();

            var deciphererDefinitionBody =
                TryGetDeciphererDefinitionBody(deciphererFuncBody);

            // Analyze statements to determine cipher function names
            foreach (var statement in deciphererFuncBody.Split(";"))
            {
                // Get the name of the function called in this statement
                var calledFuncName = Regex.Match(statement, @"\w+(?:.|\[)(\""?\w+(?:\"")?)\]?\(").Groups[1].Value;
                if (string.IsNullOrWhiteSpace(calledFuncName))
                {
                    continue;
                }

                // Slice
                if (Regex.IsMatch(deciphererDefinitionBody, $@"{Regex.Escape(calledFuncName)}:\bfunction\b\([a],b\).(\breturn\b)?.?\w+\."))
                {
                    var index = Regex.Match(statement, @"\(\w+,(\d+)\)").Groups[1].Value;

                    sol.Add("Splice |" + sol.Count, index);

                    type.Add("Splice");
                    tValue.Add(int.Parse(index));
                }

                // Swap
                else if (Regex.IsMatch(deciphererDefinitionBody, $@"{Regex.Escape(calledFuncName)}:\bfunction\b\(\w+\,\w\).\bvar\b.\bc=a\b"))
                {
                    var index = Regex.Match(statement, @"\(\w+,(\d+)\)").Groups[1].Value;

                    sol.Add("Swap |" + sol.Count, index);

                    type.Add("Swap");
                    tValue.Add(int.Parse(index));
                }

                // Reverse
                else if (Regex.IsMatch(deciphererDefinitionBody, $@"{Regex.Escape(calledFuncName)}:\bfunction\b\(\w+\)"))
                {
                    sol.Add("Reverse |" + sol.Count, "null");

                    type.Add("Reverse");
                    tValue.Add(-1);
                }
            }
        }