protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
        {
            // intercept the followings to grab resultMsg
            if (request.Url == "https://account.pearlabyss.com/en-US/Launcher/Login/LoginProcess" ||
                request.Url == "https://account.pearlabyss.com/Member/Login/LoginOtpAuth")
            {
                return(CefReturnValue.Continue);
            }

            if (request.Url == "https://launcher.naeu.playblackdesert.com/Default/AuthenticateAccount")
            {
                var postData = new PostData();

                postData.AddData($"macAddr={null}&serverKey={AuthenticationServiceProvider.Region}");

                request.Method   = "POST";
                request.PostData = postData;
                //Set the Content-Type header to whatever suites your requirement
                request.SetHeaderByName("Content-Type", "application/x-www-form-urlencoded", true);
                //Set additional Request headers as required.

                return(CefReturnValue.Continue);
            }

            return(CefReturnValue.Cancel);
        }
Esempio n. 2
0
        protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
        {
            // Блокировка
            var url = request?.Url;

            if (!string.IsNullOrEmpty(url))
            {
                lock (_settings.BlockedUrls)
                {
                    if (_settings.BlockedUrls.Count > 0)
                    {
                        if (_settings.BlockedUrls.Any(o =>
                        {
                            try
                            {
                                var pattern =
                                    new Regex(o,
                                              RegexOptions.Compiled |
                                              RegexOptions.Singleline);

                                return(pattern.IsMatch(url));
                            }
                            catch (ArgumentException)
                            {
                                return(false);
                            }
                        }))
                        {
                            Console.WriteLine($"[BLOCKED] {url}");
                            return(CefReturnValue.Cancel);
                        }
                    }
                }
                Console.WriteLine($"[ALLOWED] {url}");
            }

            // Подмена в POST
            if ("POST".Equals(request?.Method) &&
                !string.IsNullOrEmpty(_settings.PostDataChange.WhatDoINeetToFind) &&
                request.PostData is CefSharp.PostData post &&
                post.Elements.Count > 0)
            {
                var pattern =
                    new Regex(_settings.PostDataChange.WhatDoINeetToFind,
                              RegexOptions.Compiled |
                              RegexOptions.Singleline);

                var postData = new PostData();
                foreach (var element in post.Elements)
                {
                    var postData1 = System.Text.Encoding.UTF8.GetString(element.Bytes);

                    var changed = false;
                    var match   = pattern.Match(postData1);
                    while (match.Success)
                    {
                        postData1 = postData1.Replace(match.Value, _settings.PostDataChange.WhatDoINeetToPaste);
                        match     = pattern.Match(postData1);
                        changed   = true;
                    }

                    if (changed)
                    {
                        postData.AddData(System.Text.Encoding.UTF8.GetBytes(postData1));
                    }
                    else
                    {
                        postData.AddData(element.Bytes);
                    }
                }

                request.PostData = postData;
            }

            return(CefReturnValue.Continue);
        }