private static void YaraRulesCompileTest(FileEnumeratorParameters parameters)
        {
            if (!parameters.YaraParameters.Any())
            {
                return;
            }

            foreach (YaraFilter filter in parameters.YaraParameters)
            {
                YSScanner compiledRule = null;
                try
                {
                    compiledRule = YaraHelper.CompileRules(filter.OnMatchRules, parameters.ReportAndLogOutputFunction);
                }
                catch (Exception ex)
                {
                    parameters.ReportExceptionFunction.Invoke(nameof(YaraRulesCompileTest), string.Empty, ex);
                    throw;
                }
                finally
                {
                    if (compiledRule != null)
                    {
                        compiledRule.Dispose();
                    }
                }
            }
        }
Пример #2
0
        public static void ThrowIfAnyParametersInvalid(FileEnumeratorParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (parameters.DataPersistenceLayer == null)
            {
                throw new ArgumentException(nameof(DataPersistenceLayer));
            }
            if (parameters.SearchPatterns == null)
            {
                throw new ArgumentNullException(nameof(parameters.SearchPatterns));
            }
            if (parameters.ReportExceptionFunction == null)
            {
                throw new ArgumentNullException(nameof(parameters.ReportExceptionFunction));
            }
            if (parameters.ReportOutputFunction == null)
            {
                throw new ArgumentNullException(nameof(parameters.ReportOutputFunction));
            }
            if (parameters.LogOutputFunction == null)
            {
                throw new ArgumentNullException(nameof(parameters.LogOutputFunction));
            }
            if (parameters.ReportResultsFunction == null)
            {
                throw new ArgumentNullException(nameof(parameters.ReportResultsFunction));
            }
            if (string.IsNullOrWhiteSpace(parameters.SelectedFolder))
            {
                throw new ArgumentNullException(nameof(parameters.SelectedFolder));
            }
            if (!Directory.Exists(parameters.SelectedFolder))
            {
                throw new DirectoryNotFoundException(parameters.SelectedFolder);
            }

            char suppliedDriveLetter = char.ToUpper(parameters.SelectedFolder[0]);

            List <char> foundDriveLetters = DriveInfo.GetDrives()
                                            .Where(d => d.IsReady && d.DriveFormat == "NTFS")
                                            .Select(di => di.Name.ToUpper()[0])
                                            .ToList();

            if (!foundDriveLetters.Any() || !foundDriveLetters.Contains(suppliedDriveLetter))
            {
                throw new DriveNotFoundException($"The drive {suppliedDriveLetter}:\\ was not found, the drive was not mounted or ready, or the drive had a file system other than NTFS.");
            }

            if (parameters.CancelToken == null)
            {
                throw new ArgumentNullException(nameof(parameters.CancelToken), "If you do not want to pass a CancellationToken, then pass 'CancellationToken.None'");
            }
            parameters.CancelToken.ThrowIfCancellationRequested();
        }