コード例 #1
0
 public FormHistory(VirusScanner scanner)
 {
     InitializeComponent();
     _scanner             = scanner;
     _scanner.VirusFound += VirusScanner_VirusFound;
     FillListViewWithFoundViruses();
 }
コード例 #2
0
        public FormMain()
        {
            InitializeComponent();
            var drives = DriveInfo.GetDrives();

            _scanner = new VirusScanner();
            var fixedDrives = drives.Where(d => d.DriveType == DriveType.Fixed);
            var fileSystemMonitoringUnits = fixedDrives.Select(drive => new FileSystemMonitoringUnit(drive.RootDirectory.FullName));

            _monitoringUnitController = new MonitoringUnitController(
                fileSystemMonitoringUnits,
                new IAlertBehavior[]
            {
                new FileAlertBehavior(_scanner)
            }, new NoMatchingBehaviorBehavior());
            _scanner.VirusFound  += Scanner_VirusFound;
            _scanner.NewFileScan += VirusScanner_NewScanFile;
            foreach (var unit in _monitoringUnitController.Units)
            {
                unit.NewAlert += Unit_NewAlert;
            }
            var key = VirusScannerSettings.GetApiKeyFromFile();

            if (key != null)
            {
                _scanner.Start(key);
                _scanner.VirusTotalQueue.StateChanged += VirusTotalQueue_StateChanged;
                _monitoringUnitController.Start();
            }
            else
            {
                MessageBox.Show(Resources.FormMain_FormMain_Virus_Total_API_Key_Not_found,
                                Resources.FormMain_FormMain_Virus_Total_API_Key_missing);
            }
        }
コード例 #3
0
        public async Task <IActionResult> CheckFile()
        {
            var result = await VirusScanner.ScanStream(Request.Body);

            await _sql.AddVirusResult(result.Item1, result.Item2);

            return(Ok(result.Item2.ToString()));
        }
コード例 #4
0
ファイル: VirusCheckTests.cs プロジェクト: rhysmdnz/wabbajack
        public async Task CheckVirus()
        {
            var tmpFile = new TempFile();

            var meta    = Game.SkyrimSpecialEdition.MetaData();
            var srcFile = meta.GameLocation().Combine(meta.MainExecutable !);

            await srcFile.CopyToAsync(tmpFile.Path);

            using (var s = await tmpFile.Path.OpenWrite())
            {
                s.Position = 1000;
                s.WriteByte(42);
            }

            Assert.True(await VirusScanner.ShouldScan(tmpFile.Path));

            Assert.Equal(VirusScanner.Result.NotMalware, await ClientAPI.GetVirusScanResult(tmpFile.Path));
        }
コード例 #5
0
 public FileAlertBehavior(VirusScanner scanner)
 {
     _scanner = scanner;
 }
コード例 #6
0
ファイル: IncludePatches.cs プロジェクト: rhysmdnz/wabbajack
        public override async ValueTask <Directive?> Run(RawSourceFile source)
        {
            if (_isGenericGame)
            {
                if (source.Path.StartsWith(Consts.GameFolderFilesDir))
                {
                    return(null);
                }
            }

            var          name           = source.File.Name.FileName;
            RelativePath nameWithoutExt = name;

            if (name.Extension == Consts.MOHIDDEN)
            {
                nameWithoutExt = name.FileNameWithoutExtension;
            }

            if (!_indexed.TryGetValue(name, out var choices))
            {
                _indexed.TryGetValue(nameWithoutExt, out choices);
            }

            dynamic?modIni = null;

            if (_compiler is MO2Compiler)
            {
                if (_bsa == null && source.File.IsNative && source.AbsolutePath.InFolder(((MO2Compiler)_compiler).MO2ModsFolder))
                {
                    ((MO2Compiler)_compiler).ModInis.TryGetValue(ModForFile(source.AbsolutePath), out modIni);
                }
                else if (_bsa != null)
                {
                    var bsaPath = _bsa.FullPath.Base;
                    ((MO2Compiler)_compiler).ModInis.TryGetValue(ModForFile(bsaPath), out modIni);
                }
            }

            var installationFile = (string?)modIni?.General?.installationFile;

            VirtualFile[] found = {};

            // Find based on exact file name + ext
            if (choices != null && installationFile != null)
            {
                var relName = (RelativePath)Path.GetFileName(installationFile);
                found = choices.Where(f => f.FilesInFullPath.First().Name.FileName == relName).ToArray();
            }

            // Find based on file name only (not ext)
            if (found.Length == 0 && choices != null)
            {
                found = choices.ToArray();
            }

            // Find based on matchAll=<archivename> in [General] in meta.ini
            var matchAllName = (string?)modIni?.General?.matchAll;

            if (matchAllName != null && found.Length == 0)
            {
                var relName = (RelativePath)Path.GetFileName(matchAllName);
                if (_indexedByName.TryGetValue(relName, out var arch))
                {
                    var dist = new Levenshtein();
                    found = arch.SelectMany(a => a.ThisAndAllChildren)
                            .OrderBy(a => dist.Distance(a.Name.FileName.ToString(), source.File.Name.FileName.ToString()))
                            .Take(3)
                            .ToArray();
                }
            }

            if (found.Length == 0)
            {
                return(null);
            }


            var e = source.EvolveTo <PatchedFromArchive>();

            var patches = found.Select(c => (Utils.TryGetPatch(c.Hash, source.File.Hash, out var data), data, c))
                          .ToArray();

            if (patches.All(p => p.Item1))
            {
                var(_, bytes, file) = PickPatch(_compiler, patches);
                e.FromHash          = file.Hash;
                e.ArchiveHashPath   = file.MakeRelativePaths();
                e.PatchID           = await _compiler.IncludeFile(await bytes !.GetData());
            }
            else
            {
                e.Choices = found;
            }

            if (source.File.IsNative && await VirusScanner.ShouldScan(source.File.AbsoluteName))
            {
                if (await ClientAPI.GetVirusScanResult(source.File.AbsoluteName) == VirusScanner.Result.Malware)
                {
                    Utils.ErrorThrow(new Exception($"Executable file {source.File.AbsoluteName} ({source.File}) has been marked as malware."));
                }
            }

            return(e);
        }