Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
            // ProcessDirectory("C");
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            string dir;

            //     DialogResult result = fbd.ShowDialog();
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                //   dir = .SelectedPath;
                dir = fbd.SelectedPath;
                ProcessDirectory(dir);
            }

            swMalewares.Close();
            swNormals.Close();
            swExceptions.Close();
            StreamWriter finalOutput = new StreamWriter("final.csv");

            finalOutput.WriteLine("link name" + "," + "viruses");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                MalwareReport rep = entry.Value;

                finalOutput.WriteLine(entry.Key + "," + rep.getPerInf());
                int k = 0;
                for (k = 0; k < rep.getInf().Count(); k++)
                {
                    finalOutput.Write("," + rep.getInf()[k]);
                }

                finalOutput.WriteLine();
            }

            finalOutput.Flush();
            finalOutput.Close();
            StreamWriter finalOutput1 = new StreamWriter("final1.csv");

            finalOutput1.WriteLine("link name" + "," + "unrated");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                MalwareReport rep = entry.Value;
                finalOutput1.WriteLine(entry.Key + "," + rep.getPerUnr());

                int k = 0;
                for (k = 0; k < rep.getunrated().Count(); k++)
                {
                    finalOutput.Write("," + rep.getunrated()[k]);
                }
                finalOutput.WriteLine();
            }
            finalOutput1.Flush();
            finalOutput1.Close();
            MessageBox.Show("Done");
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Stream         myStream        = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            string         result2         = "";

            openFileDialog1.InitialDirectory = "C:\\Users\\ialsmadi\\Desktop\\Malware\\SQL_Injection_Projects\\Main\\SQL_Injection-master\\SQL_Injection-master\\SQL注入\\bin\\Debug";
            openFileDialog1.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                inputFilename = openFileDialog1.FileName;
                //    string path = @"C:\Users\ialsmadi\Desktop\Malware\";
                result2 = Path.GetFileNameWithoutExtension(inputFilename);
                string malwares   = "maleware" + result2 + ".csv";
                string exceptions = "exceptions" + result2 + ".csv";
                string normals    = "normals" + result2 + ".csv";
                swMalewares  = new StreamWriter(malwares);
                swExceptions = new StreamWriter(exceptions);
                swNormals    = new StreamWriter(normals);
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        ProcessDirectory1(openFileDialog1.FileName);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            swMalewares.Close();
            swNormals.Close();
            swExceptions.Close();

            string       final       = "final" + result2 + ".csv";
            StreamWriter finalOutput = new StreamWriter(final);

            finalOutput.WriteLine("link name" + "," + "Websites that decalre this link as malecious");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                //    finalOutput.WriteLine(entry.Key + "," + entry.Value);

                MalwareReport rep = entry.Value;
                finalOutput.WriteLine(entry.Key + "," + rep.getPerInf());
                int k = 0;
                for (k = 0; k < rep.getInf().Count; k++)
                {
                    finalOutput.Write("," + rep.getInf()[k]);
                }

                finalOutput.WriteLine();
            }
            finalOutput.Flush();
            finalOutput.Close();
            string       final1       = "final_unrated" + result2 + ".csv";
            StreamWriter finalOutput1 = new StreamWriter(final1);

            finalOutput1.WriteLine("link name" + "," + "Websites that decalre this link as unrated");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                //    finalOutput.WriteLine(entry.Key + "," + entry.Value);

                MalwareReport rep = entry.Value;
                finalOutput1.WriteLine(entry.Key + "," + rep.getPerUnr());
                int k = 0;
                for (k = 0; k < rep.getunrated().Count; k++)
                {
                    finalOutput1.Write("," + rep.getunrated()[k]);
                }

                finalOutput1.WriteLine();
            }
            finalOutput1.Flush();
            finalOutput1.Close();
            MessageBox.Show("Done");
        }
Exemple #3
0
        public void ProcessDirectory1(string targetFile)
        {
            List <string> lines = new List <string>();

            // 2
            // Use using StreamReader for disposing.
            using (StreamReader r = new StreamReader(targetFile))
            {
                // 3
                // Use while != null pattern for loop
                string line;
                while ((line = r.ReadLine()) != null)
                {
                    // 4
                    // Insert logic here.
                    // ...
                    // "line" is a line in the file. Add it to our List.
                    lines.Add(line);
                    extract(line);
                    try
                    {
                        foreach (LinkItem line1 in LinkFinder.Find(line))
                        {
                            extract(line1.Text);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            swExceptions.Flush();
            swMalewares.Flush();
            swNormals.Flush();
            string       final       = "final_infected" + inputFilename + ".csv";
            string       final1      = "final_unrated" + inputFilename + ".csv";
            StreamWriter finalOutput = new StreamWriter(final);

            finalOutput.WriteLine("link name" + "," + "Websites that decalre this link as malecious");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                //  finalOutput.WriteLine(entry.Key + "," + entry.Value);

                MalwareReport rep = entry.Value;
                finalOutput.WriteLine(entry.Key + "," + rep.getPerInf());
                int k = 0;
                for (k = 0; k < rep.getInf().Count; k++)
                {
                    finalOutput.Write("," + rep.getInf()[k]);
                }

                finalOutput.WriteLine();
            }
            StreamWriter finalOutput1 = new StreamWriter(final1);

            finalOutput.WriteLine("link name" + "," + "Websites that decalre this link as unrated");
            foreach (KeyValuePair <string, MalwareReport> entry in scannedItems)
            {
                //  finalOutput.WriteLine(entry.Key + "," + entry.Value);

                MalwareReport rep = entry.Value;
                finalOutput1.WriteLine(entry.Key + "," + rep.getPerUnr());

                int k = 0;
                for (k = 0; k < rep.getunrated().Count; k++)
                {
                    finalOutput1.Write("," + rep.getunrated()[k]);
                }

                finalOutput1.WriteLine();
            }
            MessageBox.Show("Done");
            // Recurse into subdirectories of this directory.

            /*       string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
             *     foreach (string subdirectory in subdirectoryEntries)
             *     {
             *         ProcessDirectory(subdirectory);
             *         swExceptions.Flush();
             *         swMalewares.Flush();
             *         swNormals.Flush();
             *     }
             */
        }