Ejemplo n.º 1
0
        string AttackThread(DatabaseOpener cracker, IPasswordSource passwordSource)
        {
            string passwordGuess;

            while (true)
            {
                if (_stopWorking)
                {
                    return(null);
                }

                if (_passwordFound != null)
                {
                    return(null);
                }

                passwordGuess = passwordSource.NextPassword();
                if (passwordGuess == null)
                {
                    return(null);
                }

                if (cracker.TryKey(passwordGuess))
                {
                    break;
                }

                Thread.MemoryBarrier();

                _guessCounter++;
                _lastGuess = passwordGuess;
            }

            return(passwordGuess);
        }
Ejemplo n.º 2
0
        //--- Public Methods ---

        public void StartAttack(string databasePath, int numThreads, IPasswordSource passwordSource)
        {
            if (numThreads <= 0)
            {
                throw new ArgumentOutOfRangeException("numThreads");
            }

            lock (_syncLock)
            {
                if (_started)
                {
                    throw new InvalidOperationException();
                }
                _started = true;
            }

            if (!PerformSelfTest())
            {
                throw new Exception("Self test failed");
            }

            var fileStream = new FileStream(databasePath, FileMode.Open, FileAccess.Read);

            DatabaseOpener databaseOpener = new DatabaseOpener(fileStream);

            stopwatch.Start();
            for (int i = 0; i < numThreads; i++)
            {
                EasyThread.BeginInvoke(new EasyThreadMethod(
                                           () =>
                {
                    Thread.MemoryBarrier();
                    _guessingThreadsRunning++;
                    Thread.MemoryBarrier();

                    string result = AttackThread(databaseOpener, passwordSource);

                    Thread.MemoryBarrier();
                    _guessingThreadsRunning--;
                    Thread.MemoryBarrier();

                    if (result != null)
                    {
                        _passwordFound = result;
                        OnPasswordFound(new PasswordFoundEventArgs(_passwordFound));
                    }
                    else if (_guessingThreadsRunning == 0)
                    {
                        OnPasswordNotFound(EventArgs.Empty);
                    }

                    if (_guessingThreadsRunning == 0)
                    {
                        fileStream.Close();
                        OnCompleted(EventArgs.Empty);
                    }
                }));
            }
        }
Ejemplo n.º 3
0
        //--- Public Methods ---
        public void StartAttack(string databasePath, int numThreads, IPasswordSource passwordSource)
        {
            if (numThreads <= 0)
                throw new ArgumentOutOfRangeException("numThreads");

            lock (_syncLock)
            {
                if (_started)
                    throw new InvalidOperationException();
                _started = true;
            }

            if (!PerformSelfTest())
                throw new Exception("Self test failed");

            var fileStream = new FileStream(databasePath, FileMode.Open, FileAccess.Read);

            DatabaseOpener databaseOpener = new DatabaseOpener(fileStream);

            stopwatch.Start();
            for (int i = 0; i < numThreads; i++)
            {
                EasyThread.BeginInvoke(new EasyThreadMethod(
                () =>
                {
                    Thread.MemoryBarrier();
                    _guessingThreadsRunning++;
                    Thread.MemoryBarrier();

                    string result = AttackThread(databaseOpener, passwordSource);

                    Thread.MemoryBarrier();
                    _guessingThreadsRunning--;
                    Thread.MemoryBarrier();

                    if (result != null)
                    {
                        _passwordFound = result;
                        OnPasswordFound(new PasswordFoundEventArgs(_passwordFound));
                    }
                    else if (_guessingThreadsRunning == 0)
                    {
                        OnPasswordNotFound(EventArgs.Empty);
                    }

                    if (_guessingThreadsRunning == 0)
                    {
                        fileStream.Close();
                        OnCompleted(EventArgs.Empty);
                    }
                }));
            }
        }
Ejemplo n.º 4
0
        string AttackThread(DatabaseOpener cracker, IPasswordSource passwordSource)
        {
            string passwordGuess;

            while (true)
            {
                if (_stopWorking)
                    return null;

                if (_passwordFound != null)
                    return null;

                passwordGuess = passwordSource.NextPassword();
                if (passwordGuess == null)
                    return null;

                if (cracker.TryKey(passwordGuess))
                    break;

                Thread.MemoryBarrier();

                _guessCounter++;
                _lastGuess = passwordGuess;
            }

            return passwordGuess;
        }