public void ModelRunner_EXETest() { var model = new ModelRunner(); var argumentResponseItem = new ArgumentResponseItem(new List <BaseArgument>()); argumentResponseItem.FileNameForClassification = Path.Combine(Environment.GetEnvironmentVariable("windir") ?? string.Empty, "explorer.exe"); var response = model.RunModel(argumentResponseItem); Assert.IsNotNull(response); Assert.IsFalse(response.Prediction); }
public void ModelRunner_PCAPTest() { var model = new ModelRunner(); var argumentResponseItem = new ArgumentResponseItem(new List <BaseArgument>()); argumentResponseItem.FileNameForClassification = Path.Combine(AppContext.BaseDirectory, @"..\..\..\Samples\pcap\benign_pcap.pcap"); var response = model.RunModel(argumentResponseItem); Assert.IsNotNull(response); Assert.IsFalse(response.Prediction); }
public ModelPredictionResponse RunModel(ArgumentResponseItem responseItem) { if (!File.Exists(responseItem.FileNameForClassification)) { throw new FileNotFoundException($"Could not find file {responseItem.FileNameForClassification}"); } var fileBytes = File.ReadAllBytes(responseItem.FileNameForClassification); var matchedParser = Parsers.FirstOrDefault(parser => parser.IsParseable(fileBytes, responseItem.FileNameForClassification)); if (matchedParser == null) { throw new ArgumentOutOfRangeException($"No parser matched for {responseItem.FileNameForClassification}"); } Console.WriteLine($"Using {matchedParser.Name} Parser to parse {responseItem.FileNameForClassification}"); matchedParser.LoadModel(); return(matchedParser.RunModel(fileBytes, responseItem.FileNameForClassification)); }
/// <summary> /// Parses the command line argument /// </summary> /// <param name="args">Contains the file name to scan</param> /// <returns>Filename of the file to scan</returns> /// <exception cref="System.ArgumentNullException">Thrown when args is null</exception> /// <exception cref="System.ArgumentException">Thrown when args is empty</exception> public static (ArgumentResponseItem ArgResponse, bool ValidOption) Parse(string[] args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } if (!args.Any()) { throw new ArgumentException("Args was empty"); } var response = new ArgumentResponseItem(SupportedArguments); var incrementer = INCREMENTER_KEY_VALUE; for (var x = 0; x < args.Length; x += incrementer) { if (!args[x].StartsWith(ARGUMENT_PREFIX)) { Console.WriteLine($"Invalid option: {args[x]}"); continue; } var argumentKey = args[x].ToLower().Substring(1); var argument = SupportedArguments.FirstOrDefault(a => a.Argument == argumentKey); if (argument == null) { Console.WriteLine($"Invalid option: {argumentKey}"); continue; } if (argument.KeyOnly) { incrementer = INCREMENTER_KEY_ONLY; continue; } incrementer = INCREMENTER_KEY_VALUE; if (args.Length < x + incrementer) { Console.WriteLine($"{argumentKey} requires a value, but was not found"); throw new ArgumentException($"Associated value for {argumentKey} was not found"); } var argumentValue = args[x + 1]; if (!argument.ValidArgument(argumentValue)) { Console.WriteLine($"{argumentValue} is an invalid value for {argumentKey}"); continue; } response.UpdateProperty(argument.PropertyMap, argument.GetValue(argumentValue)); } return(response, response.IsValid()); }
public void ArgumentTests_ToString() { var argumentResponse = new ArgumentResponseItem(new List <BaseArgument>()); Assert.IsNotNull(argumentResponse.ToString()); }
public void InvalidProperty() { var argumentResponse = new ArgumentResponseItem(new List <BaseArgument>()); argumentResponse.UpdateProperty("blah", null); }
public void NullArgumentResponseItemConstructor() { var argumentResponse = new ArgumentResponseItem(null); }