Exemplo n.º 1
0
        /// <summary>
        /// generally manage input and do all the stuff
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            lastFilePath = "";
            vtResult     = "none";
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var fi = new FileInfo(ofd.FileName);
                if (fi.Length < MINIMUM_FILE_SIZE)
                {
                    MessageBox.Show($"File is too small! Minimum size of a file is {MINIMUM_FILE_SIZE} bytes!");
                    return;
                }
                else if (fi.Length > MAXIMUM_FILE_SIZE)
                {
                    MessageBox.Show($"File is too big! Maximum size of a file is {MAXIMUM_FILE_SIZE} bytes!");
                    return;
                }
                lastFilePath       = ofd.FileName;
                saveButton.Enabled = true;
                vtButton.Enabled   = true;
                List <double> entropy;
                var           fileName = ofd.FileName;
                bool          res      = int.TryParse(textBox1.Text, out int temp);
                if (!res)
                {
                    MessageBox.Show("Incorrect number or no sample number included, using default value of 256.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                int samples = res ? temp : 256;
                if (samples < 64)
                {
                    samples = 64;
                }
                if (samples > fi.Length)
                {
                    samples = 256;
                }
                var ent = new EntropyCounter(fileName, samples);
                entropy = ent.GetFileEntropy();
                var charter = new Charting(entropy);
                pictureBox1.Image = charter.GetBitmap();


                DetectionInfo detectionInfo = new DetectionInfo(ofd.FileName);

                md5label.Text    = detectionInfo.getMD5();
                sha1label.Text   = detectionInfo.getSHA1();
                sha256label.Text = detectionInfo.getSHA256();
                sha512label.Text = detectionInfo.getSHA512();

                locationLabel.Text = ofd.FileName;

                double sum = 0;
                entropy.ForEach(x => sum += x);
                avgEntLabel.Text          = (sum / samples).ToString();

                fileSizeLabel.Text = new FileInfo(ofd.FileName).Length.ToString();

                fileTypesLabel.Text = detectionInfo.Detect();
            }
            else
            {
                MessageBox.Show("No file chosen!");
                vtButton.Enabled   = false;
                saveButton.Enabled = false;
            }
        }