Beispiel #1
0
 public bool StopScaning()
 {
     if (!DateValue.isScaning)
     {
         return(false);
     }
     else
     {
         DBManager.AddReport(DateValue.idReport, DateValue.dateStart, DateTime.Now.ToString("MM.dd.yyyy H:mm"), DateValue.path, DateValue.countFile, DateValue.countVirusFile);
         DateValue.isScaning    = false;
         DateValue.isSearchFile = false;
         return(true);
     }
 }
Beispiel #2
0
        public static void SearchFileDirectory(Object state)
        {
            object[] array = state as object[];
            var      path  = Convert.ToString(array[0]);

            DateValue.Operation oper = (DateValue.Operation)(int) array[1];

            if (File.Exists(path))
            {
                if (GetTypeFile(path) == 1)
                {
                    DateValue.countFile    = 1;
                    DateValue.isSearchFile = false;
                    ScanFile.AddTask(new ScanObject(path, oper, DateValue.Scan.SearchFile));
                }
                else
                {
                    DateValue.isScaning = false;
                }

                return;
            }

            int count = DateValue.countFile;

            string[] dirs = Directory.GetDirectories(path);
            foreach (string pathDir in dirs)
            {
                if (!DateValue.isScaning)
                {
                    return;
                }
                SearchFileDirectory(new object[] { pathDir, oper });
            }
            string[] files = Directory.GetFiles(path);
            foreach (string pathFile in files)
            {
                if (!DateValue.isScaning)
                {
                    return;
                }
                byte flag = GetTypeFile(pathFile);
                switch (flag)
                {
                case 0:     //other file
                    break;

                case 1:     //exe
                    DateValue.countFile++;
                    Console.WriteLine(pathFile);
                    ScanFile.AddTask(new ScanObject(pathFile, oper, DateValue.Scan.SearchFile));
                    break;

                case 2:     //zip
                    Console.WriteLine(pathFile);
                    OpenZip(pathFile, oper);
                    break;
                }
            }
            if (count == 0)
            {
                DateValue.isSearchFile = false;
                if (DateValue.countCheckFile == DateValue.countFile)
                {
                    DateValue.isScaning = false;
                    DBManager.AddReport(DateValue.idReport, DateValue.dateStart, DateTime.Now.ToString("MM.dd.yyyy H:mm"), DateValue.path, DateValue.countFile, DateValue.countVirusFile);
                }
            }
        }
Beispiel #3
0
        internal static void ThreadProc(Object state)
        {
            Console.WriteLine("Thread start");
            bool isFound = false;

            object[] array = state as object[];
            var      path  = Convert.ToString(array[0]);

            byte[] text = array[1] as byte[];
            DateValue.Operation oper = (DateValue.Operation)(int) array[2];
            DateValue.Scan      scan = (DateValue.Scan)(int) array[3];
            Console.WriteLine("if");
            if (text == null)
            {
                Console.WriteLine(".text null");
                if (scan.Equals(DateValue.Scan.SearchFile))
                {
                    DateValue.countCheckFile++;
                }
                return;
            }

            Console.WriteLine("thread for " + text.Length);
            for (int i = 0; i < text.Length - 4 && !isFound; i++)
            {
                //Console.WriteLine("thread: "+i);
                if (!DateValue.isScaning && scan.Equals(DateValue.Scan.SearchFile))
                {
                    return;
                }

                var temp = new byte[4];
                Array.Copy(text, i, temp, 0, 4);
                if (DateValue.signTree.isValue(temp))
                {
                    string searchSign = GetStringOfBytes(temp, 0, 4);

                    List <string> signaturs = DBManager.SearchSignature(searchSign, i);
                    foreach (var sign in signaturs)
                    {
                        if (CheckSignatureFullMatch(sign, text, i))
                        {
                            if (oper.Equals(DateValue.Operation.Quarantine))
                            {
                                QuarantineFile(path);
                                if (File.Exists(path))
                                {
                                    DBManager.AddQuarantine(DateTime.Now.ToString("MM/dd/yyyy H:mm"), path, DBManager.GetTypeSignature(sign));
                                }
                            }
                            else
                            {
                                DeleteFile(path);
                            }


                            if (scan.Equals(DateValue.Scan.SearchFile))
                            {
                                DateValue.countVirusFile++;
                                DBManager.AddFile(DateValue.idReport, path, oper, DBManager.GetTypeSignature(sign));
                            }
                            Console.WriteLine("GOOOOOD");
                            isFound = true;
                            break;
                        }
                    }
                }

                //string searchSign = GetStringOfBytes(text, i, 4);

                /*
                 * List<string> signaturs = DBManager.SearchSignature(searchSign, i);
                 * foreach (var sign in signaturs)
                 * {
                 *
                 *  if (CheckSignatureFullMatch(sign, text, i))
                 *  {
                 *
                 *      if (oper.Equals(DateValue.Operation.Quarantine))
                 *      {
                 *          QuarantineFile(path);
                 *          DBManager.AddQuarantine(DateTime.Now.ToString("MM/dd/yyyy H:mm"), path, DBManager.GetTypeSignature(sign));
                 *      }
                 *      else DeleteFile(path);
                 *
                 *
                 *      if (scan.Equals(DateValue.Scan.SearchFile))
                 *      {
                 *          DateValue.countVirusFile++;
                 *          DBManager.AddFile(DateValue.idReport, path, oper, DBManager.GetTypeSignature(sign));
                 *      }
                 *      Console.WriteLine("GOOOOOD");
                 *      isFound = true;
                 *      break;
                 *  }
                 * }*/
            }

            if (scan.Equals(DateValue.Scan.SearchFile))
            {
                DateValue.countCheckFile++;
                if (!DateValue.isSearchFile && DateValue.countCheckFile == DateValue.countFile)
                {
                    DateValue.isScaning = false;
                    DBManager.AddReport(DateValue.idReport, DateValue.dateStart, DateTime.Now.ToString("MM.dd.yyyy H:mm"), DateValue.path, DateValue.countFile, DateValue.countVirusFile);
                }
            }
            Console.WriteLine("End scan: " + path);
        }