Beispiel #1
0
 public FileSystemScan(ModuleBox mBox)
 {
     _mBox             = new ModuleBox(mBox);
     _workBodyDi       = new List <DirectoryInfo>();
     _workBodyFi       = new List <FileInfo>();
     this.ScanDelegate = UnpackMessage;
     _mBox.ModListener(new ModuleBox()
     {
         CodeId = CodeId.BindwithScan, ScanListener = ScanDelegate
     });
     _mBox.ScanFListener(new ModuleBox()
     {
         CodeId = CodeId.BindwithScan, ScanListener = ScanDelegate
     });
     try
     {
         foreach (var dirs in _mBox.ApplicationOptions.DirectoriesForScanStart)
         {
             _workBodyDi.Add(dirs);
         }
         _mBox.ScanFListener(new ModuleBox()
         {
             CodeId = CodeId.UpdateLblDirectories, StringBody = _workBodyDi[0].FullName
         });
     }
     catch (Exception e)
     {
         throw new Exception("Init FileSysScan |" + e.Message);
     }
 }
Beispiel #2
0
        public void Dispose()
        {
            ModuleBox.SaveOptions(AppOptions);

            FilesTypeInSystem.Clear();
            AuditResult.Clear();
            ReleaseUnmanagedResources();
            GC.SuppressFinalize((object)this);
        }
Beispiel #3
0
 public Module(object obj)
 {
     if (obj != null)
     {
         MBox = (ModuleBox)obj;
         FilesTypeInSystem = RegisteredFileType.GetFileType();
         UpdateDriveInfo();
         ModListener = UnpackBox;
         AuditResult = new List <AuditResultInfo>();
         if (MBox.ApplicationOptions == null)
         {
             AppOptions = ModuleBox.LoadOptions();
         }
     }
 }
 public ModuleBox(ModuleBox moduleBox)
 {
     if (moduleBox != null)
     {
         ScanListener       = moduleBox.ScanListener;
         ModListener        = moduleBox.ModListener;
         MainFListener      = moduleBox.MainFListener;
         ScanFListener      = moduleBox.ScanFListener;
         CodeId             = moduleBox.CodeId;
         StringBody         = moduleBox.StringBody;
         ApplicationOptions = new ApplicationOptions(moduleBox.ApplicationOptions);
         Ari             = new AuditResultInfo(moduleBox.Ari);
         ListReportAudit = new List <AuditResultInfo>(moduleBox.ListReportAudit);
     }
 }
Beispiel #5
0
        private void LoopModule(object obj)
        {
            if (obj != null)
            {
                ModuleBox moduleBox = obj as ModuleBox;
                MBox = new ModuleBox(moduleBox)
                {
                    ModListener = UnpackBox
                };

                if (MBox.MainFListener != null)
                {
                    _isUiActive        = true;
                    MBox.MainFListener = moduleBox.MainFListener;
                    MBox.MainFListener(new ModuleBox()
                    {
                        CodeId      = CodeId.BindWithModule,
                        ModListener = MBox.ModListener
                    });
                }

                bool flag = true;
                while (flag)
                {
                    Thread.Sleep(100);
                    lock (_locker)
                    {
                        if (MustDo.Count > 0 && MBoxs.Count > 0)
                        {
                            switch (MustDo.Peek())
                            {
                            case CodeId.ListReportAudit:
                                MustDo.Dequeue();
                                if (_isUiActive)
                                {
                                    ModuleBox m = new ModuleBox()
                                    {
                                        CodeId = CodeId.ListReportAudit
                                    };
                                    for (int i = 0; i < AuditResult.Count; i++)
                                    {
                                        m.ListReportAudit.Add(AuditResult[i]);
                                        File.AppendAllText("TTX.txt", $"\r\n{AuditResult[i].FindWords.Count}");
                                    }
                                    MBox.MainFListener(m);
                                }
                                MBoxs.Dequeue();
                                break;

                            case CodeId.AddToAuditResult:
                                MustDo.Dequeue();
                                var ari = MBoxs.Peek();
                                this.AuditResult.Add(new AuditResultInfo(ari.Ari));
                                MBoxs.Dequeue();
                                break;

                            case CodeId.BindWithScanF:
                                MustDo.Dequeue();
                                var bwsf = MBoxs.Peek();
                                MBox.ScanFListener = bwsf.ScanFListener;
                                MBoxs.Dequeue();
                                break;

                            case CodeId.BindwithScan:
                                MustDo.Dequeue();
                                var bws = MBoxs.Peek();
                                MBox.ScanListener = bws.ScanListener;
                                MBoxs.Dequeue();
                                break;

                            case CodeId.UnBindWithScanF:
                                moduleBox.ScanFListener = null;
                                MustDo.Dequeue();
                                MBoxs.Dequeue();
                                break;

                            case CodeId.DisposeModule:
                                flag = false;
                                if (_scanTask != null)
                                {
                                    if (_scanTask.IsAlive)
                                    {
                                        _scanTask.Abort();
                                    }
                                }
                                MustDo.Clear();
                                MBoxs.Clear();
                                break;

                            case CodeId.RunScanForm:
                                AuditResult.Clear();
                                MustDo.Dequeue();
                                _scanTask = new Thread(RunScanFormExternalTrigger);
                                ModuleBox t = new ModuleBox(MBoxs.Dequeue());
                                _scanTask.Start(t);
                                break;

                            case CodeId.TestHookApp:
                                MustDo.Dequeue();
                                MBoxs.Dequeue();
                                new Thread(new TestAppHook(_mhf).Show).Start();
                                break;

                            case CodeId.TestHookKeyboard:
                                MustDo.Dequeue();
                                MBoxs.Dequeue();
                                new Thread(new TestKeyBoardHook(_mhf).Show).Start();
                                break;

                            case CodeId.TestHookMouse:
                                MustDo.Dequeue();
                                MBoxs.Dequeue();

                                new Thread(new TestMouseHook(_mhf).Show).Start();
                                break;

                            case CodeId.TestHookClipboard:
                                MustDo.Dequeue();
                                MBoxs.Dequeue();
                                new Thread(new TestClipBordHook(_mhf).Show).Start();
                                break;

                            case CodeId.TestHookPrint:
                                MustDo.Dequeue();
                                MBoxs.Dequeue();
                                new Thread(new TestPrintHook(_mhf).Show).Start();
                                break;

                            case CodeId.TestCameraSpy:
                                MustDo.Dequeue();
                                MBoxs.Dequeue();
                                new Thread(new ClientSpy.ClientSpy().TestRun);
                                new Thread(new ServerSpy.TestVideo().Show).Start();
                                break;
                            }
                        }
                    }
                }

                Dispose();
            }
        }
Beispiel #6
0
        public void GetAllDirectoryInfo(object obj)
        {
            var mBox = new ModuleBox(obj as ModuleBox);
            //---------------------------------------------
            int    lowIndexDirInfo  = 0;     //lower index list dir_info
            int    lowIndexFileInfo = 0;     //lower index list files_info
            int    lowIndexFileScan = 0;     //lower index list files_info
            int    thPool           = 50;    //count task in sys_thread pool
            int    timeout          = 100;   //timeout for tasks - add to list dir_info
            string str = "";                 //info for scan_form - current directory added to list_info
            int    counEmptyJobDirInfo  = 5; //FUSE,breaker
            int    counEmptyJobFileInfo = 5; //FUSE,breaker
            int    counEmptyJobFileScan = 5; //FUSE,breaker
            bool   endGetFolders        = false;
            bool   endGetFiles          = false;

            //---------------------------------------------
            //---------------------------------------------
            while (!_endTasksWithFiles)
            {
                lock (_barrier)
                {
                    if (!_pauseTask && !endGetFolders)
                    {
                        if (lowIndexDirInfo < _workBodyDi.Count)
                        {
                            int count = _workBodyDi.Count - lowIndexDirInfo;
                            if (thPool < count)
                            {
                                count = thPool;
                            }
                            while (count != 0)
                            {
                                ThreadPool.QueueUserWorkItem(AddRangeToListDirInfo, lowIndexDirInfo);
                                count--;
                                lowIndexDirInfo++;
                            }

                            str = $"{lowIndexDirInfo} : " + _workBodyDi[lowIndexDirInfo - 1].FullName;
                            mBox.ScanFListener(new ModuleBox()
                            {
                                CodeId = CodeId.UpdateLblDirectories, StringBody = str
                            });
                        }
                        else
                        {
                            if (counEmptyJobDirInfo != 0)
                            {
                                counEmptyJobDirInfo--;
                            }
                            else
                            {
                                endGetFolders = true;
                                mBox.ScanFListener(new ModuleBox()
                                {
                                    CodeId = CodeId.UpdateLblDirectories, StringBody = @"Завершено."
                                });
                            }
                        }
                    }

                    if (!_pauseTask && endGetFolders && !endGetFiles)
                    {
                        if (lowIndexFileInfo < _workBodyDi.Count)
                        {
                            int count = _workBodyDi.Count - lowIndexFileInfo;
                            if (thPool < count)
                            {
                                count = thPool;
                            }
                            while (count != 0)
                            {
                                ThreadPool.QueueUserWorkItem(AddRAngeToListFilesInfo, lowIndexFileInfo);
                                count--;
                                lowIndexFileInfo++;
                            }

                            if (lowIndexFileInfo < _workBodyDi.Count)
                            {
                                str = $"{lowIndexFileInfo} : " + _workBodyDi[lowIndexFileInfo].FullName;
                                mBox.ScanFListener(
                                    new ModuleBox()
                                {
                                    CodeId = CodeId.UpdateLblDirFiles, StringBody = str
                                });
                            }
                        }
                        else
                        {
                            if (counEmptyJobFileInfo != 0)
                            {
                                counEmptyJobFileInfo--;
                            }
                            else
                            {
                                endGetFiles = true;
                                mBox.ScanFListener(new ModuleBox()
                                {
                                    CodeId = CodeId.UpdateLblDirFiles, StringBody = @"Завершено."
                                });
                            }
                        }
                    }

                    if (!_pauseTask && endGetFolders && endGetFiles)
                    {
                        if (lowIndexFileScan < _workBodyFi.Count)
                        {
                            int i = _workBodyFi.Count - lowIndexFileScan > thPool
                                ? thPool
                                : _workBodyFi.Count - lowIndexFileScan;
                            while (i != 0)
                            {
                                if (_workBodyFi[lowIndexFileScan].Length <= _mBox.ApplicationOptions.FileSizeIgnoreTo &&
                                    _workBodyFi[lowIndexFileScan].Length >=
                                    _mBox.ApplicationOptions.FileSizeIgnoreFrom &&
                                    _mBox.ApplicationOptions.FileExtensionForExecute.Contains(
                                        Path.GetExtension(_workBodyFi[lowIndexFileScan].FullName)))
                                {
                                    ThreadPool.QueueUserWorkItem(AuditValid,
                                                                 new ModuleBox(_mBox)
                                    {
                                        StringBody = _workBodyFi[lowIndexFileScan].FullName
                                    });
                                }

                                i--;
                                lowIndexFileScan++;
                            }
                            mBox.ScanFListener(new ModuleBox()
                            {
                                CodeId = CodeId.ProgresBarMax, IntBody = _workBodyFi.Count
                            });
                            mBox.ScanFListener(new ModuleBox()
                            {
                                CodeId = CodeId.ProgresBarStep, IntBody = lowIndexFileScan
                            });
                        }
                        else
                        {
                            if (counEmptyJobFileScan != 0)
                            {
                                counEmptyJobFileScan--;
                            }
                            else
                            {
                                _endTasksWithFiles = true;
                                mBox.ScanFListener(new ModuleBox()
                                {
                                    CodeId = CodeId.ProgresBarStep, IntBody = 0
                                });
                                Thread.Sleep(5000);
                                mBox.ModListener(new ModuleBox()
                                {
                                    CodeId = CodeId.ListReportAudit, StringBody = @"Завершено."
                                });
                                mBox.ScanFListener(new ModuleBox()
                                {
                                    CodeId = CodeId.UpdateLblCurFile, StringBody = @"Завершено."
                                });
                            }
                        }
                    }
                }

                Thread.Sleep(timeout);
            }
        }