示例#1
0
        // ReSharper restore AccessToStaticMemberViaDerivedType

        private void btnCompute_Click(object sender, EventArgs e)
        {
            try
            {
                var fs = File.OpenRead(_filePath);

                var blockSize = chkEntireFile.Checked ? fs.Length : Int32.Parse(cbComputeBlockSize.Text);
                var blocks    = chkEntireFile.Checked ? 1 : Int32.Parse(txtBlocks.Text);

                var block = new byte[blockSize];
                setHashAlgorithm();

                progressBar.Maximum = (blocks > 0 ? blocks : (int)(fs.Length / blockSize));
                progressBar.Value   = 0;
                var sb = new StringBuilder();
                fs.Seek(Int32.Parse(txtOffset.Text), SeekOrigin.Begin);
                int readBytes;
                do
                {
                    var pos = fs.Position;
                    readBytes = fs.Read(block, 0, (int)blockSize);
                    var hash = _ha != null?_ha.ComputeHash(block) : CRC16.GetCRC(block);

                    sb.Append("@" + pos.ToString("X7") + ": " + byteArrayToString(hash) + Environment.NewLine);
                    blocks--;
                    progressBar.PerformStep();
                } while (readBytes == blockSize && blocks != 0);
                // Show results
                txtList.Text = sb.ToString();

                fs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        private void superBruteForce_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = (BackgroundWorker)sender;

            try
            {
                var fileBuffer = File.ReadAllBytes(_filePath);

                worker.ReportProgress(0, new ValueObject(fileBuffer.Length));
                for (var blockSize = 64; blockSize <= fileBuffer.Length; blockSize += 4)
                {
                    worker.ReportProgress(1, new ValueObject(fileBuffer.Length - blockSize));
                    for (var offset = 0; offset < fileBuffer.Length - blockSize; offset += 4)
                    {
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        var hash = _ha != null?_ha.ComputeHash(fileBuffer, offset, blockSize) : CRC16.GetCRC(fileBuffer, offset, blockSize);

                        if (_searchKey[0] == hash[0])                             // 1:256 probability
                        {
                            if (memcmp(_searchKey, hash, _searchKey.Length) == 0) //key found!!!
                            {
                                e.Result = "@" + offset.ToString("X7") + " of " + blockSize + " : " + byteArrayToString(hash);
                                return;
                            }
                        }
                        if (!chkHighCPU.Checked && (offset % 64) == 0)
                        {
                            System.Threading.Thread.Sleep(1); //let the cpu cool off
                        }
                        worker.ReportProgress(11, new ValueObject(offset));
                    }
                    worker.ReportProgress(10, new ValueObject(blockSize));
                }
                e.Result = "Search key not found.";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }