Ejemplo n.º 1
0
        public static byte EntryPoint()
        {
            new Thread(() => Connector.Init()).Start();
            ScanTasks.Init();
            YaraIntegration.Init();

            return(0);
        }
Ejemplo n.º 2
0
        public static void ScanThread()
        {
            while (true)
            {
                ScanTask task = null;

                lock (TaskQueue.SyncRoot)
                {
                    if (TaskQueue.Count > 0)
                    {
                        task = (ScanTask)TaskQueue.Dequeue();
                    }
                }

                if (task != null)
                {
                    if (Configuration.UsingYara)
                    {
                        Connector.Logger.WriteLine($"[ScanThread {Thread.CurrentThread.Name}] Поток начал проверку правил Yara", LogLevel.WARN);

                        ScanResult result;

                        if (!File.Exists(task.file))
                        {
                            Connector.Logger.WriteLine($"[ScanThread {Thread.CurrentThread.Name}] Файл не найден", LogLevel.ERROR);
                            result = new ScanResult(0, MODULE__SCAN.result.Error);
                        }
                        else
                        {
                            try
                            {
                                if (YaraIntegration.CheckFile(task.file))
                                {
                                    result = new ScanResult(0, MODULE__SCAN.result.Virus);
                                }
                                else
                                {
                                    result = new ScanResult(0, MODULE__SCAN.result.NotVirus);
                                }
                            }
                            catch (Exception ex)
                            {
                                Connector.Logger.WriteLine($"[ScanThread {Thread.CurrentThread.Name}] Ошибка при проверке файла {ex.Message}", LogLevel.ERROR);
                                result = new ScanResult(0, MODULE__SCAN.result.Error);
                            }
                        }

                        ScanCompleted(
                            task,
                            new ScanResult(0, result.Result)
                            );
                    }
                    else
                    {
                        FileStream stream = null;

                        try
                        {
                            stream = File.Open(task.file, FileMode.Open, FileAccess.Read);
                        }
                        catch (PathTooLongException)
                        {
                            Connector.Logger.WriteLine($"[SCANNER] PathTooLongException", LogLevel.ERROR);
                            ScanCompleted(task, new ScanResult(0, MODULE__SCAN.result.NotVirus));
                        }
                        catch (UnauthorizedAccessException)
                        {
                            Connector.Logger.WriteLine($"[SCANNER] UnauthorizedAccessException", LogLevel.ERROR);
                            ScanCompleted(task, new ScanResult(0, MODULE__SCAN.result.NotVirus));
                        }
                        catch (DirectoryNotFoundException)
                        {
                            Connector.Logger.WriteLine($"[SCANNER] DirectoryNotFoundException", LogLevel.ERROR);
                            ScanCompleted(task, new ScanResult(0, MODULE__SCAN.result.NotVirus));
                        }
                        catch (FileNotFoundException)
                        {
                            Connector.Logger.WriteLine($"[SCANNER] FileNotFoundException", LogLevel.ERROR);
                            ScanCompleted(task, new ScanResult(0, MODULE__SCAN.result.NotVirus));
                        }
                        catch (Exception ex)
                        {
                            Connector.Logger.WriteLine($"[SCANNER] ERROR OPEN FILE {ex.Message}", LogLevel.ERROR);
                            ScanCompleted(task, new ScanResult(0, MODULE__SCAN.result.Error));
                            continue;
                        }

                        Connector.Logger.WriteLine($"[ScanThread {Thread.CurrentThread.Name}] Поток начал сканирование поиском сигнатуры", LogLevel.WARN);

                        var result = Scanner.ScanFile(stream);

                        stream.Close();
                        ScanCompleted(task, result);
                    }
                }

                Thread.Sleep(Configuration.SCAN_THREAD_SLEEP);
            }
        }