internal static CaptchaWindow PrepareCaptchaWindowForMouseMoveAbsolute(CaptchaWindow captcha)
        {
            captcha.MatrixZahlObenLinks.X   = (int)Math.Round((captcha.MatrixZahlObenLinks.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlObenLinks.Y   = (int)Math.Round((captcha.MatrixZahlObenLinks.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlObenMitte.X   = (int)Math.Round((captcha.MatrixZahlObenMitte.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlObenMitte.Y   = (int)Math.Round((captcha.MatrixZahlObenMitte.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlObenRechts.X  = (int)Math.Round((captcha.MatrixZahlObenRechts.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlObenRechts.Y  = (int)Math.Round((captcha.MatrixZahlObenRechts.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlMitteLinks.X  = (int)Math.Round((captcha.MatrixZahlMitteLinks.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlMitteLinks.Y  = (int)Math.Round((captcha.MatrixZahlMitteLinks.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlMitteMitte.X  = (int)Math.Round((captcha.MatrixZahlMitteMitte.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlMitteMitte.Y  = (int)Math.Round((captcha.MatrixZahlMitteMitte.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlMitteRechts.X = (int)Math.Round((captcha.MatrixZahlMitteRechts.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlMitteRechts.Y = (int)Math.Round((captcha.MatrixZahlMitteRechts.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlUntenLinks.X  = (int)Math.Round((captcha.MatrixZahlUntenLinks.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlUntenLinks.Y  = (int)Math.Round((captcha.MatrixZahlUntenLinks.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlUntenMitte.X  = (int)Math.Round((captcha.MatrixZahlUntenMitte.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlUntenMitte.Y  = (int)Math.Round((captcha.MatrixZahlUntenMitte.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlUntenRechts.X = (int)Math.Round((captcha.MatrixZahlUntenRechts.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlUntenRechts.Y = (int)Math.Round((captcha.MatrixZahlUntenRechts.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.MatrixZahlGanzUnten.X   = (int)Math.Round((captcha.MatrixZahlGanzUnten.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.MatrixZahlGanzUnten.Y   = (int)Math.Round((captcha.MatrixZahlGanzUnten.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);
            captcha.Absenden.X = (int)Math.Round((captcha.Absenden.X * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Width, 0);
            captcha.Absenden.Y = (int)Math.Round((captcha.Absenden.Y * MAX_ABSOLUTE) / Screen.PrimaryScreen.Bounds.Height, 0);

            return(captcha);
        }
        /// <summary>
        /// Authenticates with the site and returns the cookies.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns>Cookies on success, <c>string.Empty</c> on failure.</returns>
        public override string Login(string username, string password)
        {
            // get captcha image

            var session = string.Empty;
            var sectext = string.Empty;
            var captcha = Utils.GetURL(Site + "freecap.php", encoding: new Utils.Base64Encoding(),
                                       request:  req => req.Referer = Site,
                                       response: resp => session    = Utils.EatCookieCollection(resp.Cookies));

            // show captcha to user

            MainWindow.Active.Run(() =>
            {
                var cw  = new CaptchaWindow(Name, Convert.FromBase64String(captcha), 347, 90);
                var res = cw.ShowDialog();

                if (res.HasValue && res.Value)
                {
                    sectext = cw.Solution;
                }
            });

            if (string.IsNullOrWhiteSpace(sectext))
            {
                return(string.Empty);
            }

            // send login request

            return(GazelleTrackerLogin(username, password, sectext, session));
        }
 public async Task Initialize()
 {
     await Application.Current.Dispatcher.InvokeAsync(() =>
     {
         window = new CaptchaWindow
         {
             Owner = Application.Current.MainWindow
         };
         window.Closing           += WindowClosing;
         viewModel                 = new CaptchaViewModel();
         viewModel.CaptchaEntered += CaptchaEntered;
         window.DataContext        = viewModel;
     });
 }
Beispiel #4
0
        public JToken Get(string method, params object[] args)
        {
            lock (_accessTokenArgs)
            {
                IEnumerable <object> localArgs = args.Concat(_accessTokenArgs);

                while (true)
                {
                    var delay = CallDelay - _callStopwatch.ElapsedMilliseconds;
                    if (delay > 0)
                    {
                        Thread.Sleep((int)delay);
                    }

                    var response = ExecuteCollection(method, localArgs);

                    _callStopwatch.Restart();

                    var error = response["error"];

                    if (error == null || error.Value <int>("error_code") != 14)
                    {
                        return(response["response"]);
                    }

                    var window = new CaptchaWindow(error.Value <string>("captcha_img"));
                    if (window.ShowDialog() == true)
                    {
                        localArgs = args.Concat(_accessTokenArgs).Concat(new object[]
                        {
                            "captcha_sid", error.Value <string>("captcha_sid"),
                            "captcha_key", window.CaptchaKey
                        });
                    }
                }
            }
        }
        /// <summary>
        /// Authenticates with the site and returns the cookies.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns>Cookies on success, <c>string.Empty</c> on failure.</returns>
        public override string Login(string username, string password)
        {
            // get captcha image

            var session = string.Empty;
            var sectext = string.Empty;
            var captcha = Utils.GetURL(Site + "freecap.php", encoding: new Utils.Base64Encoding(),
                request:  req  => req.Referer = Site,
                response: resp => session = Utils.EatCookieCollection(resp.Cookies));

            // show captcha to user

            MainWindow.Active.Run(() =>
                {
                    var cw  = new CaptchaWindow(Name, Convert.FromBase64String(captcha), 347, 90);
                    var res = cw.ShowDialog();

                    if (res.HasValue && res.Value)
                    {
                        sectext = cw.Solution;
                    }
                });

            if (string.IsNullOrWhiteSpace(sectext))
            {
                return string.Empty;
            }

            // send login request

            return GazelleTrackerLogin(username, password, sectext, session);
        }
        internal static void resolveCaptcha(string captchaZahl, string matrixZahl, IntPtr popupWindow)
        {
            Random rd = new Random(DateTime.Now.Millisecond);
            int    wt = 300; //for randomly Sleep( wait + random.next() % wait ) meaning 450 +- 150 milliseconds

            RECT currentWindowRect = new RECT();

            GetWindowRect(popupWindow, ref currentWindowRect);
            CaptchaWindow curCaptcha = new CaptchaWindow(currentWindowRect);

            //Verhältnis für MouseMove(ABSOLUTE)
            curCaptcha = PrepareCaptchaWindowForMouseMoveAbsolute(curCaptcha);

            for (int i = 0, j = 0; i < matrixZahl.Length; i++)
            {
                if (captchaZahl[j] == matrixZahl[i])
                {
                    switch (i)
                    {
                    case 0:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlObenLinks.X, curCaptcha.MatrixZahlObenLinks.Y, 0, new UIntPtr());
                        Console.WriteLine("oben links");
                        break;

                    case 1:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlObenMitte.X, curCaptcha.MatrixZahlObenMitte.Y, 0, new UIntPtr());
                        Console.WriteLine("oben mitte");
                        break;

                    case 2:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlObenRechts.X, curCaptcha.MatrixZahlObenRechts.Y, 0, new UIntPtr());
                        Console.WriteLine("oben rechts");
                        break;

                    case 3:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlMitteLinks.X, curCaptcha.MatrixZahlMitteLinks.Y, 0, new UIntPtr());
                        Console.WriteLine("mitte links");
                        break;

                    case 4:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlMitteMitte.X, curCaptcha.MatrixZahlMitteMitte.Y, 0, new UIntPtr());
                        Console.WriteLine("mitte mitte");
                        break;

                    case 5:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlMitteRechts.X, curCaptcha.MatrixZahlMitteRechts.Y, 0, new UIntPtr());
                        Console.WriteLine("mitte rechts");
                        break;

                    case 6:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlUntenLinks.X, curCaptcha.MatrixZahlUntenLinks.Y, 0, new UIntPtr());
                        Console.WriteLine("unten links");
                        break;

                    case 7:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlUntenMitte.X, curCaptcha.MatrixZahlUntenMitte.Y, 0, new UIntPtr());
                        Console.WriteLine("unten mitte");
                        break;

                    case 8:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlUntenRechts.X, curCaptcha.MatrixZahlUntenRechts.Y, 0, new UIntPtr());
                        Console.WriteLine("unten rechts");

                        break;

                    case 9:
                        mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.MatrixZahlGanzUnten.X, curCaptcha.MatrixZahlGanzUnten.Y, 0, new UIntPtr());
                        Console.WriteLine("ganz unten ");
                        break;
                    }
                    Thread.Sleep(wt + (rd.Next() % wt));

                    //click
                    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new UIntPtr());
                    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new UIntPtr());
                    Thread.Sleep(wt + (rd.Next() % wt));

                    //setup for new loop, only if numbers matched each other
                    j = j + 1;
                    i = -1;

                    if (j >= captchaZahl.Length)
                    {
                        break; //captcha done
                    }
                }
            }

            //click send
            mouse_event((MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE), curCaptcha.Absenden.X, curCaptcha.Absenden.Y, 0, new UIntPtr());
            Thread.Sleep(wt + (rd.Next() % wt));

            //ToDo: click send
            //Console.WriteLine("...press any key to continue...");
            //Console.ReadKey();
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new UIntPtr());
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new UIntPtr());
            Thread.Sleep(wt + (rd.Next() % wt));
        }
        /// <summary>
        /// Extracts the direct links from the supplied link.
        /// </summary>
        /// <param name="link">The protected link.</param>
        /// <returns>Direct links.</returns>
        public string ExpandLinks(Link link)
        {
            var html = Utils.GetHTML(link.FileURL);

            var captcha = html.DocumentNode.GetNodeAttributeValue("//td/img[contains(@src, '/secure/')]", "src");
            var session = html.DocumentNode.GetNodeAttributeValue("//input[@name='s']", "value");

            if (captcha == null && session == null)
            {
                goto extract;
            }

            var sectext = string.Empty;

            MainWindow.Active.Run(() =>
            {
                var cw  = new CaptchaWindow(Name, "http://download.serienjunkies.org" + captcha, 100, 60);
                var res = cw.ShowDialog();

                if (res.HasValue && res.Value)
                {
                    sectext = cw.Solution;
                }
            });

            if (string.IsNullOrWhiteSpace(sectext))
            {
                return(link.FileURL);
            }

            html = Utils.GetHTML(link.FileURL, "s=" + session + "&c=" + sectext + "&action=Download");

extract:
            var links = html.DocumentNode.SelectNodes("//form[contains(@action, '/go-')]");

            if (links == null)
            {
                return(link.FileURL);
            }

            var urls = string.Empty;

            foreach (var node in links)
            {
                var url = node.GetAttributeValue("action");

                if (string.IsNullOrWhiteSpace(url))
                {
                    continue;
                }

                Utils.GetHTML(
                    url,
                    request:  r => r.AllowAutoRedirect = false,
                    response: r => url = r.Headers[HttpResponseHeader.Location]
                    );

                urls += url + "\0";
            }

            return(urls.TrimEnd('\0'));
        }