internal static bool ExecuteCmd(string command) { bool isManagedCmd = false; string[] commands = command.Split(' '); string cmdName = commands.First(); string[] args = commands.Skip(1).ToArray(); switch (cmdName) { case "exit": Environment.Exit(0); break; case "clear": Console.Clear(); isManagedCmd = true; break; case "yadd": isManagedCmd = true; CmdAddRules(args); break; case "sadd": isManagedCmd = true; CmdAddSamples(args); break; case "ycompile": isManagedCmd = true; using (var compiler = new Compiler()) { foreach (var yara in yaras.Distinct()) { var err = ScanHelper.CheckRule(yara); if (err == YARA_ERROR.SUCCESS) { try { compiler.AddRuleFile(yara); Console.WriteLine($":Added {yara}"); } catch (Exception e) { Console.WriteLine($"!Exception adding \"{yara}\": {e.Message}"); } } else { Console.WriteLine($"!Exception adding \"{yara}\": {err}"); } } try { rules = compiler.Compile(); Console.WriteLine($"* Compiled"); } catch (Exception e) { Console.WriteLine($"!Exception compiling rules: {e.Message}"); } } break; case "run": isManagedCmd = true; CmdRun(); break; } return(isManagedCmd); }