Ejemplo n.º 1
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[name filter]"));
     CMD_HELP = new Command("HELP", TABLE, true, "Returns descriptions of all commands in the current CLI mode.", ExecutionLevel.User, CLIMode.Any);
     CMD_HELP.SetFunction(() =>
     {
         string var_name = (string)EnvironmentVariables.GetCurrentValue("CLI_MODE") == "Default" ? "DEF_CMD_POOL" : "REG_CMD_POOL";
         if (CMD_HELP.InputArgumentEntry.Arguments.Count == 0)
         {
             ((CommandPool)EnvironmentVariables.GetCurrentValue(var_name)).GetPool().ForEach((x) =>
             {
                 IOInteractLayer.StandardOutput(CMD_HELP, "\n" + x.Description);
             });
         }
         else
         {
             Interpreter interpreter = new Interpreter((string)CMD_HELP.InputArgumentEntry.Arguments[0].Value);
             ((CommandPool)EnvironmentVariables.GetCurrentValue(var_name)).GetPool().ForEach((x) =>
             {
                 if (interpreter.GetResult(x.Call.ToLower()))
                 {
                     IOInteractLayer.StandardOutput(CMD_HELP, "\n" + x.Description);
                 }
             });
         }
         return("");
     });
     return(CMD_HELP);
 }
Ejemplo n.º 2
0
        public Command GetCommand()
        {
            TABLE.Add(new CommandArgumentEntry("[string] [string]", false, "[path] [new name]"));

            CMD_RENAME = new Command("RENAME", TABLE, false, "Renames the file system entry", ExecutionLevel.User, CLIMode.Default);
            CMD_RENAME.SetFunction(() =>
            {
                if (File.Exists((string)CMD_RENAME.InputArgumentEntry.Arguments[0].Value) && CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
                {
                    File.Move(CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString(), CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString().Replace(Path.GetFileName(CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString()), CMD_RENAME.InputArgumentEntry.Arguments[1].Value.ToString()));
                }
                else if (File.Exists((string)EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_RENAME.InputArgumentEntry.Arguments[0].Value))
                {
                    File.Move(EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString(), EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString().Replace(Path.GetFileName(EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString()), CMD_RENAME.InputArgumentEntry.Arguments[1].Value.ToString()));
                }
                else if (Directory.Exists((string)CMD_RENAME.InputArgumentEntry.Arguments[0].Value) && CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
                {
                    Directory.Move(CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString(), CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString().Replace(new DirectoryInfo(CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString()).Name, CMD_RENAME.InputArgumentEntry.Arguments[1].Value.ToString()));
                }
                else if (Directory.Exists((string)EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_RENAME.InputArgumentEntry.Arguments[0].Value))
                {
                    Directory.Move(EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString(), EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString().Replace(new DirectoryInfo(EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_RENAME.InputArgumentEntry.Arguments[0].Value.ToString()).Name, CMD_RENAME.InputArgumentEntry.Arguments[1].Value.ToString()));
                }
                else
                {
                    return("\nInvalid path!");
                }
                return("");
            });
            return(CMD_RENAME);
        }
Ejemplo n.º 3
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[file path]"));
     CMD_OPEN = new Command("OPEN", TABLE, false, "Displays the editable contents of the specified file. Press 'F1' to save, press 'F2' to save and close, press 'ESC' to discard and colse.", ExecutionLevel.User, CLIMode.Default);
     CMD_OPEN.SetAsyncFunction(async() =>
     {
         await Task.Delay(0);
         c = new CountdownEvent(1);
         if (File.Exists(CMD_OPEN.InputArgumentEntry.Arguments[0].Value.ToString()) && CMD_OPEN.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
         {
             path = CMD_OPEN.InputArgumentEntry.Arguments[0].Value.ToString();
         }
         else if (File.Exists(EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_OPEN.InputArgumentEntry.Arguments[0].Value.ToString()))
         {
             path = EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_OPEN.InputArgumentEntry.Arguments[0].Value.ToString();
         }
         else
         {
             return("\nFile not found!");
         }
         EnvironmentVariables.ChangeCurrentValue("CLI_MODE", "Text", false);
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
         {
             ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Clear();
             IOInteractLayer.StandardOutput(CMD_OPEN, File.ReadAllText(path));
             ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown += Main_PreviewKeyDown;
         });
         c.Wait();
         return("");
     });
     return(CMD_OPEN);
 }
Ejemplo n.º 4
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[file path]"));
     CMD_MF = new Command("MF", TABLE, true, "Creates a new file at the provided relative or full path.", ExecutionLevel.User, CLIMode.Default);
     CMD_MF.SetFunction(() =>
     {
         string path      = CMD_MF.InputArgumentEntry.Arguments[0].Value.ToString();
         path             = path.Last() == '\\' ? path.Remove(path.Length - 1, 1) : path;
         string full_path = EnvironmentVariables.GetCurrentValue("DIRECTORY") + path;
         if (Directory.Exists(path.Remove(path.LastIndexOf("\\"))) && path.Contains(":"))
         {
             File.Create(path).Close();
         }
         else if (Directory.Exists(full_path.Remove(full_path.LastIndexOf("\\"))))
         {
             File.Create(full_path).Close();
         }
         else
         {
             return("\nDirectory not found!");
         }
         return("");
     });
     return(CMD_MF);
 }
Ejemplo n.º 5
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("-rhost", false, "-rhost(resolve hostnames)"));
     CMD_NMAP = new Command("NMAP", TABLE, false, "Attempts to discover all connacted devices on all connected networks.", ExecutionLevel.User, CLIMode.Default);
     CMD_NMAP.SetAsyncFunction(async() =>
     {
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
         {
             ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly = true;
             ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).KeyDown   += Main_KeyDown;
             IOInteractLayer.StandardOutput(CMD_NMAP, "\n");
         });
         NetworkInterfaceDiscovery nics = new NetworkInterfaceDiscovery();
         ToolShed.ThisPC.NetworkInterface[] interfaces = await nics.GetInterfaces();
         NetworkInfo inf = new NetworkInfo();
         string[] ip_arr = inf.GetAddresses(interfaces);
         await GetDevices(ip_arr, interfaces, CMD_NMAP.InputArgumentEntry.Arguments.Exists(x => x.Call == "-rhost"));
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
         {
             ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).KeyDown   -= Main_KeyDown;
             ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly = false;
         });
         return("");
     });
     return(CMD_NMAP);
 }
Ejemplo n.º 6
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[result filter]"));
     CMD_HISTORY_SHLIST = new Command("HISTORY-SHLIST", TABLE, true, "Returns the input history of the current CLI mode.", ExecutionLevel.User, CLIMode.Any);
     CMD_HISTORY_SHLIST.SetFunction(() =>
     {
         string var_name = (string)EnvironmentVariables.GetCurrentValue("CLI_MODE") == "Default" ? "DEF_HISTORY" : "REG_HISTORY";
         if (CMD_HISTORY_SHLIST.InputArgumentEntry.Arguments.Count == 1)
         {
             Interpreter interpreter = new Interpreter((string)CMD_HISTORY_SHLIST.InputArgumentEntry.Arguments[0].Value);
             for (int i = 1; i < ((List <string>)EnvironmentVariables.GetCurrentValue(var_name)).Count; i++)
             {
                 if (interpreter.GetResult(((List <string>)EnvironmentVariables.GetCurrentValue(var_name))[i]))
                 {
                     IOInteractLayer.StandardOutput(CMD_HISTORY_SHLIST, "\n\t" + i + " " + ((List <string>)EnvironmentVariables.GetCurrentValue(var_name))[i]);
                 }
             }
         }
         else
         {
             for (int i = 1; i < ((List <string>)EnvironmentVariables.GetCurrentValue(var_name)).Count; i++)
             {
                 IOInteractLayer.StandardOutput(CMD_HISTORY_SHLIST, "\n\t" + i + " " + ((List <string>)EnvironmentVariables.GetCurrentValue(var_name))[i]);
             }
         }
         return("");
     });
     return(CMD_HISTORY_SHLIST);
 }
Ejemplo n.º 7
0
 private void Main_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Escape)
     {
         CTS.Cancel();
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = false;
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_PreviewKeyDown;
     }
 }
Ejemplo n.º 8
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[subkey path]"));
     TABLE.Add(new CommandArgumentEntry("[string] -r", true, "[subkey path] -r(remove subkey and all child elements)"));
     CMD_SK_DELETE = new Command("SK-DELETE", TABLE, false, "Removes the specified subkey.", ExecutionLevel.Administrator, CLIMode.Regedit);
     CMD_SK_DELETE.SetFunction(() =>
     {
         if (CMD_SK_DELETE.InputArgumentEntry.Arguments.Count == 0)
         {
             return("\nInvalid arguments!");
         }
         RegistryHive hiveKey;
         string subKey      = null;
         RegistryKey newKey = null;
         try
         {
             hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_SK_DELETE.InputArgumentEntry.Arguments[0].Value.ToString().Substring(0, CMD_SK_DELETE.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf('\\')));
             subKey  = CMD_SK_DELETE.InputArgumentEntry.Arguments[0].Value.ToString().Substring(CMD_SK_DELETE.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf('\\') + 1);
         }
         catch (Exception ex)
         {
             hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf('\\')));
             subKey  = EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf('\\') + 1) + CMD_SK_DELETE.InputArgumentEntry.Arguments[0].Value.ToString();
         }
         try
         {
             newKey = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
             if (newKey == null)
             {
                 Debug.WriteLine(hiveKey.ToString() + " || " + CMD_SK_DELETE.InputArgumentEntry.Arguments[0].Value.ToString().Substring(CMD_SK_DELETE.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf('\\') + 1));
                 return("\nSubkey not found!");
             }
             else if (newKey == RegistryKey.OpenBaseKey((RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf('\\'))), RegistryView.Default).OpenSubKey(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf('\\') + 1)))
             {
                 return("\nCannot delete current subkey.");
             }
             else
             {
                 if (CMD_SK_DELETE.InputArgumentEntry.Arguments.Exists(x => x.Call == "-r"))
                 {
                     RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).DeleteSubKeyTree(subKey);
                 }
                 else
                 {
                     RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).DeleteSubKey(subKey);
                 }
             }
         }
         catch (Exception ex)
         {
             IOInteractLayer.StandardError(CMD_SK_DELETE, ex);
         }
         return("");
     });
     return(CMD_SK_DELETE);
 }
Ejemplo n.º 9
0
 public Command GetCommand()
 {
     CMD_HISTORY_CLEAR = new Command("HISTORY-CLEAR", null, false, "Clears the input history of the current CLI mode.", ExecutionLevel.User, CLIMode.Any);
     CMD_HISTORY_CLEAR.SetFunction(() =>
     {
         EnvironmentVariables.ChangeCurrentValue((string)EnvironmentVariables.GetCurrentValue("CLI_MODE") == "Default" ? "DEF_HISTORY" : "REG_HISTORY", new List <string>());
         return("");
     });
     return(CMD_HISTORY_CLEAR);
 }
Ejemplo n.º 10
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[file path]"));
     CMD_EXEC = new Command("EXEC", TABLE, false, "Executes commands from the specified file(one command per line). Asynchronous commands will not wait for the previous command to finish.", ExecutionLevel.User, CLIMode.Default);
     CMD_EXEC.SetAsyncFunction(async() =>
     {
         string path = null;
         if (File.Exists(CMD_EXEC.InputArgumentEntry.Arguments[0].Value.ToString()) && CMD_EXEC.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
         {
             path = CMD_EXEC.InputArgumentEntry.Arguments[0].Value.ToString();
         }
         else if (File.Exists(EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_EXEC.InputArgumentEntry.Arguments[0].Value.ToString()))
         {
             path = EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_EXEC.InputArgumentEntry.Arguments[0].Value.ToString();
         }
         else
         {
             return("\nInvalid path!");
         }
         string[] lines     = File.ReadAllLines(path);
         Command[] commands = new Command[lines.Length];
         for (int i = 0; i < lines.Length; i++)
         {
             commands[i] = ((CommandManagement)EnvironmentVariables.GetCurrentValue("CMD_MGMT")).GetCommand(lines[i].Trim(), (CLIMode)Enum.Parse(typeof(CLIMode), (string)EnvironmentVariables.GetCurrentValue("CLI_MODE")) == CLIMode.Default ? (CommandPool)EnvironmentVariables.GetCurrentValue("DEF_CMD_POOL") : (CommandPool)EnvironmentVariables.GetCurrentValue("REG_CMD_POOL"));
         }
         for (int i = 0; i < commands.Length; i++)
         {
             try
             {
                 if (commands[i].AsyncFunction == null)
                 {
                     ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                     {
                         ((CommandManagement)EnvironmentVariables.GetCurrentValue("CMD_MGMT")).ExecuteCommand(commands[i]);
                     });
                 }
                 else
                 {
                     await((CommandManagement)EnvironmentVariables.GetCurrentValue("CMD_MGMT")).ExecuteAsyncCommand(commands[i]);
                 }
             }
             catch (Exception ex)
             {
                 ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                 {
                     IOInteractLayer.StandardError(commands[i], ex);
                 });
             }
         }
         return("");
     });
     return(CMD_EXEC);
 }
Ejemplo n.º 11
0
 private void Main_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Escape)
     {
         CTS.Cancel();
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = false;
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_KeyDown;
     }
     if (e.Key == Key.Enter)
     {
         IOInteractLayer.StandardOutput(CMD_HASHCRACK, $"\nProcessed words: {processedWords}\nProgress: {progress:0.00}%\nLast word: {currentWord}\nLast hash: {currentResult}");
     }
 }
Ejemplo n.º 12
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[int]", false, "[new size]"));
     TABLE.Add(new CommandArgumentEntry("[int] -s", true, "[new size] -s(save to startup)"));
     TABLE.Add(new CommandArgumentEntry("[int] -b", true, "[new size] -b(save to running and startup)"));
     CMD_HISTORY_SETSIZE = new Command("HISTORY-SETSIZE", TABLE, false, "Sets the history size of the current CLI mode. If the new size is lower than the previous one, some of the entries will be discarded.", ExecutionLevel.User, CLIMode.Any);
     CMD_HISTORY_SETSIZE.SetFunction(() =>
     {
         if ((string)EnvironmentVariables.GetCurrentValue("CLI_MODE") == "Default")
         {
             if (CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments.Count == 2)
             {
                 if (CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[1].Call == "-s")
                 {
                     EnvironmentVariables.ChangeDefaultValue("DEF_HIST_SIZE", (int)CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[0].Value);
                 }
                 else
                 {
                     EnvironmentVariables.ChangeDefaultValue("DEF_HIST_SIZE", (int)CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[0].Value);
                     EnvironmentVariables.ChangeCurrentValue("DEF_HIST_SIZE", (int)CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[0].Value);
                 }
             }
             else
             {
                 EnvironmentVariables.ChangeCurrentValue("DEF_HIST_SIZE", (int)CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[0].Value);
             }
         }
         else
         {
             if (CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments.Count == 2)
             {
                 if (CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[1].Call == "-s")
                 {
                     EnvironmentVariables.ChangeDefaultValue("REG_HIST_SIZE", (int)CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[0].Value);
                 }
                 else
                 {
                     EnvironmentVariables.ChangeDefaultValue("REG_HIST_SIZE", (int)CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[0].Value);
                     EnvironmentVariables.ChangeCurrentValue("REG_HIST_SIZE", (int)CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[0].Value);
                 }
             }
             else
             {
                 EnvironmentVariables.ChangeCurrentValue("REG_HIST_SIZE", (int)CMD_HISTORY_SETSIZE.InputArgumentEntry.Arguments[0].Value);
             }
         }
         return("");
     });
     return(CMD_HISTORY_SETSIZE);
 }
Ejemplo n.º 13
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[file path]"));
     TABLE.Add(new CommandArgumentEntry("[string] [string]", true, "[file path] [arguments]"));
     CMD_START = new Command("START", TABLE, false, "Attempts to start the specified executable, with the specified arguments.", ExecutionLevel.User, CLIMode.Default);
     CMD_START.SetFunction(() =>
     {
         if (CMD_START.InputArgumentEntry.Arguments.Count == 0)
         {
             return("\nInvalid arguments!");
         }
         Process p   = null;
         string path = null;
         if (File.Exists(CMD_START.InputArgumentEntry.Arguments[0].Value.ToString()) && CMD_START.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
         {
             path = CMD_START.InputArgumentEntry.Arguments[0].Value.ToString();
         }
         else if (File.Exists(EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_START.InputArgumentEntry.Arguments[0].Value.ToString()))
         {
             path = EnvironmentVariables.GetCurrentValue("DIRECTORY") + CMD_START.InputArgumentEntry.Arguments[0].Value.ToString();
         }
         else
         {
             return("\nExecutable not found!");
         }
         p = new Process();
         p.StartInfo.FileName         = path;
         p.StartInfo.WorkingDirectory = path.Replace(Path.GetFileName(path), "");
         p.StartInfo.UseShellExecute  = false;
         p.StartInfo.CreateNoWindow   = false;
         if (CMD_START.InputArgumentEntry.Arguments.Count == 2)
         {
             p.StartInfo.Arguments = CMD_START.InputArgumentEntry.Arguments[1].Value.ToString();
         }
         try
         {
             p.Start();
         }
         catch (Exception ex)
         {
             IOInteractLayer.StandardError(CMD_START, ex);
         }
         return("");
     });
     return(CMD_START);
 }
Ejemplo n.º 14
0
        public Command GetCommand()
        {
            CMD_EXIT.SetFunction(() =>
            {
                switch ((CLIMode)Enum.Parse(typeof(CLIMode), (string)EnvironmentVariables.GetCurrentValue("CLI_MODE")))
                {
                case CLIMode.Default:
                    Environment.Exit(0);
                    break;

                case CLIMode.Regedit:
                    EnvironmentVariables.ChangeCurrentValue("CLI_MODE", CLIMode.Default);
                    break;
                }
                return("");
            });
            return(CMD_EXIT);
        }
Ejemplo n.º 15
0
        public Command GetCommand()
        {
            TABLE.Add(new CommandArgumentEntry("[string]", false, "[path]"));

            CMD_MD = new Command("MD", TABLE, false, "Creates a new directory at the provided relative/full path.", ExecutionLevel.User, CLIMode.Default);
            CMD_MD.SetFunction(() =>
            {
                if (CMD_MD.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
                {
                    Directory.CreateDirectory((string)CMD_MD.InputArgumentEntry.Arguments[0].Value);
                }
                else
                {
                    Directory.CreateDirectory((string)EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_MD.InputArgumentEntry.Arguments[0].Value);
                }
                return("");
            });
            return(CMD_MD);
        }
Ejemplo n.º 16
0
 private void Main_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.F2)
     {
         File.WriteAllText(path, ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Text);
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Clear();
         EnvironmentVariables.ChangeCurrentValue("CLI_MODE", "Default", false);
         c.Signal();
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_PreviewKeyDown;
     }
     else if (e.Key == Key.F1)
     {
         File.WriteAllText(path, ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Text);
     }
     else if (e.Key == Key.Escape)
     {
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Clear();
         EnvironmentVariables.ChangeCurrentValue("CLI_MODE", "Default", false);
         c.Signal();
         ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_PreviewKeyDown;
     }
 }
Ejemplo n.º 17
0
        public Command GetCommand()
        {
            TABLE.Add(new CommandArgumentEntry("[string]", false, "[file path]"));

            CMD_DEL = new Command("DEL", TABLE, false, "Removes the file at the provided relative/full path.", ExecutionLevel.User, CLIMode.Default);
            CMD_DEL.SetFunction(() =>
            {
                if (File.Exists((string)CMD_DEL.InputArgumentEntry.Arguments[0].Value) && CMD_DEL.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
                {
                    File.Delete((string)CMD_DEL.InputArgumentEntry.Arguments[0].Value);
                }
                else if (File.Exists((string)EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_DEL.InputArgumentEntry.Arguments[0].Value))
                {
                    File.Delete((string)EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_DEL.InputArgumentEntry.Arguments[0].Value);
                }
                else
                {
                    return("\nFile not found!");
                }
                return("");
            });
            return(CMD_DEL);
        }
Ejemplo n.º 18
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[path]"));
     TABLE.Add(new CommandArgumentEntry("[string] -a", false, "[path], -a(remove content if any)"));
     CMD_RD = new Command("RD", TABLE, false, "Removes the directory at the provided relative/full path.", ExecutionLevel.User, CLIMode.Default);
     CMD_RD.SetFunction(() =>
     {
         if (Directory.Exists((string)CMD_RD.InputArgumentEntry.Arguments[0].Value) && CMD_RD.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
         {
             Directory.Delete((string)CMD_RD.InputArgumentEntry.Arguments[0].Value, CMD_RD.InputArgumentEntry.Arguments.Exists(x => x.Call == "-a"));
         }
         else if (Directory.Exists((string)EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_RD.InputArgumentEntry.Arguments[0].Value))
         {
             Directory.Delete((string)EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_RD.InputArgumentEntry.Arguments[0].Value, CMD_RD.InputArgumentEntry.Arguments.Exists(x => x.Call == "-a"));
         }
         else
         {
             return("\nInvalid path!");
         }
         return("");
     });
     return(CMD_RD);
 }
Ejemplo n.º 19
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[int]", false, "[entry index]"));
     TABLE.Add(new CommandArgumentEntry("[int] -r", false, "[entry index] -r(reverse search)"));
     CMD_HISTORY_GETENTRY = new Command("HISTORY-GETENTRY", TABLE, false, "Returns the specified history entry of the current CLI mode.", ExecutionLevel.User, CLIMode.Any);
     CMD_HISTORY_GETENTRY.SetFunction(() =>
     {
         int entry       = (int)CMD_HISTORY_GETENTRY.InputArgumentEntry.Arguments.Find(x => x.Call == "").Value;
         string var_name = (string)EnvironmentVariables.GetCurrentValue("CLI_MODE") == "Default" ? "DEF_HIST_SIZE" : "REG_HIST_SIZE";
         if ((int)EnvironmentVariables.GetCurrentValue(var_name) >= entry && entry > 0)
         {
             if (CMD_HISTORY_GETENTRY.InputArgumentEntry.Arguments.Exists(x => x.Call == "-r"))
             {
                 IOInteractLayer.StandardOutput(CMD_HISTORY_GETENTRY, "\n\t" + ((List <string>)EnvironmentVariables.GetCurrentValue(var_name))[((List <string>)EnvironmentVariables.GetCurrentValue(var_name)).Count - (int)CMD_HISTORY_GETENTRY.InputArgumentEntry.Arguments.Find(x => x.Call == "").Value]);
             }
             else
             {
                 IOInteractLayer.StandardOutput(CMD_HISTORY_GETENTRY, "\n\t" + ((List <string>)EnvironmentVariables.GetCurrentValue(var_name))[(int)CMD_HISTORY_GETENTRY.InputArgumentEntry.Arguments.Find(x => x.Call == "").Value]);
             }
         }
         return("");
     });
     return(CMD_HISTORY_GETENTRY);
 }
Ejemplo n.º 20
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[path]"));
     CMD_FSEINF = new Command("FSEINF", TABLE, false, "Returns information about the specified file system entry.", ExecutionLevel.User, CLIMode.Default);
     CMD_FSEINF.SetFunction(() =>
     {
         string in_path      = CMD_FSEINF.InputArgumentEntry.Arguments[0].Value.ToString();
         string in_full_path = EnvironmentVariables.GetCurrentValue("DIRECTORY") + in_path;
         object inf          = null;
         if (File.Exists(in_path) && in_path.Contains(":"))
         {
             inf = new FileInfo(in_path);
             return($"\nName: {((FileInfo)inf).Name}\nDate created: {((FileInfo)inf).CreationTime}\nDate modified: {((FileInfo)inf).LastWriteTime}\nDate accessed: {((FileInfo)inf).LastAccessTime}\nParent directory: {((FileInfo)inf).DirectoryName}\nAttributes: {((FileInfo)inf).Attributes}\nExtension: {((FileInfo)inf).Extension}\nRead only: {((FileInfo)inf).IsReadOnly}");
         }
         else if (File.Exists(in_full_path))
         {
             inf = new FileInfo(in_full_path);
             return($"\nName: {((FileInfo)inf).Name}\nDate created: {((FileInfo)inf).CreationTime}\nDate modified: {((FileInfo)inf).LastWriteTime}\nDate accessed: {((FileInfo)inf).LastAccessTime}\nParent directory: {((FileInfo)inf).DirectoryName}\nAttributes: {((FileInfo)inf).Attributes}\nExtension: {((FileInfo)inf).Extension}\nRead only: {((FileInfo)inf).IsReadOnly}");
         }
         else if (Directory.Exists(in_path) && in_path.Contains(":"))
         {
             inf = new DirectoryInfo(in_path);
             return($"\nName: {((DirectoryInfo)inf).Name}\nDate created: {((DirectoryInfo)inf).CreationTime}\nDate modified: {((DirectoryInfo)inf).LastWriteTime}\nDate accessed: {((DirectoryInfo)inf).LastAccessTime}\nParent directory: {((DirectoryInfo)inf).Parent}\nAttributes: {((DirectoryInfo)inf).Attributes}\nExtension: {((DirectoryInfo)inf).Extension}");
         }
         else if (Directory.Exists(in_full_path))
         {
             inf = new FileInfo(in_full_path);
             return($"\nName: {((DirectoryInfo)inf).Name}\nDate created: {((DirectoryInfo)inf).CreationTime}\nDate modified: {((DirectoryInfo)inf).LastWriteTime}\nDate accessed: {((DirectoryInfo)inf).LastAccessTime}\nParent directory: {((DirectoryInfo)inf).Parent}\nAttributes: {((DirectoryInfo)inf).Attributes}\nExtension: {((DirectoryInfo)inf).Extension}");
         }
         else
         {
             return("\nFile system entry not found!");
         }
     });
     return(CMD_FSEINF);
 }
Ejemplo n.º 21
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[name/filter]"));
     CMD_VAL_DELETE = new Command("VAL-DELETE", TABLE, true, "Removes all values that matches the specified filter in the current subkey.", ExecutionLevel.Administrator, CLIMode.Regedit);
     CMD_VAL_DELETE.SetFunction(() =>
     {
         RegistryKey key         = RegistryKey.OpenBaseKey((RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\"))), RegistryView.Default).OpenSubKey(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\") + 1), true);
         Interpreter interpreter = new Interpreter(CMD_VAL_DELETE.InputArgumentEntry.Arguments[0].Value.ToString());
         string[] names          = key.GetValueNames();
         int removed             = 0;
         try
         {
             for (int i = 0; i < names.Length; i++)
             {
                 if (interpreter.GetResult(names[i]))
                 {
                     key.DeleteValue(names[i]);
                     removed++;
                 }
             }
         }
         catch (Exception ex)
         {
             IOInteractLayer.StandardError(CMD_VAL_DELETE, ex);
         }
         return($"\nRemoved: {removed} values");
     });
     return(CMD_VAL_DELETE);
 }
Ejemplo n.º 22
0
        public async Task GetDevices(string[] ipAddresses, ToolShed.ThisPC.NetworkInterface[] interfaces, bool resolveHostnames)
        {
            await Task.Delay(0);

            cts       = new CancellationTokenSource();
            ct        = cts.Token;
            countdown = new CountdownEvent(1);
            async Task GHE_TASK(string entry)
            {
                if (!ct.IsCancellationRequested)
                {
                    await Task.Delay(0);

                    string name = "";
                    try
                    {
                        IPHostEntry hostEntry = Dns.GetHostEntry(entry.Split(' ')[0]);
                        name = hostEntry.HostName;
                    }
                    catch (Exception)
                    {
                        name = "Unknown";
                    }
                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                    {
                        try
                        {
                            IOInteractLayer.StandardOutput(CMD_NMAP, $"\nName: {name} || IP address: {entry.Split(' ')[0]} || MAC address: {entry.Split(' ')[1].Replace("-", ":").ToUpper()}");
                        }
                        catch (Exception) { }
                    });
                }
            }

            Regex spacefix = new Regex("[ ]{2,}");

            for (int i = 0; i < ipAddresses.Length; i++)
            {
                if (!ct.IsCancellationRequested)
                {
                    ping = new Ping();
                    ping.PingCompleted += Ping_PingCompleted;
                    countdown.AddCount();
                    try
                    {
                        ping.SendAsync(ipAddresses[i], 100);
                    }
                    catch (Exception) {}
                    GC.Collect();
                }
                else
                {
                    return;
                }
            }
            countdown.Signal();
            countdown.Wait();
            string[]      entries     = null;
            List <Task>   taskList    = new List <Task>();
            List <string> checked_ips = new List <string>();

            for (int i = 0; i < interfaces.Length; i++)
            {
                if (interfaces[i].Status == "Up" && interfaces[i].Type != "Loopback" && interfaces[i].Type != "Tunnel")
                {
                    if (!ct.IsCancellationRequested)
                    {
                        cmdProcess = new Process();
                        cmdProcess.StartInfo.CreateNoWindow         = true;
                        cmdProcess.StartInfo.UseShellExecute        = false;
                        cmdProcess.StartInfo.FileName               = "arp";
                        cmdProcess.StartInfo.Arguments              = "-a -N " + interfaces[i].IPAddress;
                        cmdProcess.StartInfo.RedirectStandardOutput = true;
                        cmdProcess.Start();
                        entries = cmdProcess.StandardOutput.ReadToEnd().Split('\n');
                        cmdProcess.Close();
                        for (int j = 3; j < entries.Length - 1; j++)
                        {
                            if (!ct.IsCancellationRequested)
                            {
                                entries[j] = spacefix.Replace(entries[j].Trim(), " ");
                                if (!checked_ips.Contains(entries[j].Split(' ')[0]))
                                {
                                    checked_ips.Add(entries[j].Split(' ')[0]);
                                    if (resolveHostnames)
                                    {
                                        taskList.Add(GHE_TASK(entries[j]));
                                    }
                                    else
                                    {
                                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                                        {
                                            IOInteractLayer.StandardOutput(CMD_NMAP, $"\nIP address: {entries[j].Split(' ')[0]} || MAC address: {entries[j].Split(' ')[1].Replace("-", ":").ToUpper()}");
                                        });
                                    }
                                }
                            }
                            else
                            {
                                ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                                {
                                    IOInteractLayer.StandardOutput(CMD_NMAP, "\nProcess interrupted.");
                                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).KeyDown   -= Main_KeyDown;
                                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly = false;
                                });
                                return;
                            }
                        }
                        await Task.WhenAll(taskList);
                    }
                    else
                    {
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                        {
                            IOInteractLayer.StandardOutput(CMD_NMAP, "\nProcess interrupted.");
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).KeyDown   -= Main_KeyDown;
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly = false;
                        });
                        return;
                    }
                }
            }
        }
Ejemplo n.º 23
0
        public Command GetCommand()
        {
            TABLE.Add(new CommandArgumentEntry("[string]", false, "[IP address/hostname]"));
            TABLE.Add(new CommandArgumentEntry("[string] -t", true, "[IP address/hostname] -t(ping indefinitely)"));

            CMD_PING = new Command("PING", TABLE, false, "", ExecutionLevel.User, CLIMode.Default);
            CMD_PING.SetAsyncFunction(async() =>
            {
                if (CMD_PING.InputArgumentEntry.Arguments.Count == 0)
                {
                    return("Invalid arguments!");
                }
                else
                {
                    Times    = new List <long>();
                    Sent     = 0;
                    Received = 0;
                    Lost     = 0;
                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                    {
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = true;
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown += Main_PreviewKeyDown;
                    });
                    CTS         = new CancellationTokenSource();
                    CT          = CTS.Token;
                    Ping p      = new Ping();
                    PingReply r = null;
                    async Task PING_TASK()
                    {
                        try
                        {
                            Sent++;
                            r = p.Send(CMD_PING.InputArgumentEntry.Arguments[0].Value.ToString(), 5000);
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                            {
                                IOInteractLayer.StandardOutput(CMD_PING, $"\nReply from {r.Address}: bytes={r.Buffer.Length} time={r.RoundtripTime}ms TTL={r.Options.Ttl}");
                                Times.Add(r.RoundtripTime);
                            });
                            Received++;
                        }
                        catch (PingException ex)
                        {
                            Lost++;
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                            {
                                IOInteractLayer.StandardError(CMD_PING, ex);
                            });
                        }
                        if (!CT.IsCancellationRequested && CMD_PING.InputArgumentEntry.Arguments.Exists(x => x.Call == "-t"))
                        {
                            await Task.Delay(1000);
                            await PING_TASK();
                        }
                    }

                    if (CMD_PING.InputArgumentEntry.Arguments.Exists(x => x.Call == "-t"))
                    {
                        await PING_TASK();
                    }
                    else
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            await PING_TASK();
                            await Task.Delay(1000);
                        }
                    }
                }
                ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                {
                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = false;
                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_PreviewKeyDown;
                });
                return($"\nPing statistics for {CMD_PING.InputArgumentEntry.Arguments[0].Value}:\n\tPackets: Sent = {Sent}, Received = {Received}, Lost = {Lost}, ({Lost / Sent * 100:0.00}% loss),\nApproximate round trip times in milli-seconds:\n\tMinimum = {Times.Min()}ms, Maximum = {Times.Max()}ms, Average = {Times.Average():0}ms");
            });
            return(CMD_PING);
        }
Ejemplo n.º 24
0
        public Command GetCommand()
        {
            TABLE.Add(new CommandArgumentEntry("[string] [string]", false, "[source path] [destination directory]"));

            CMD_COPY = new Command("COPY", TABLE, false, "Copies the specified file/directory to the specified location.", ExecutionLevel.User, CLIMode.Default);

            CMD_COPY.SetFunction(() =>
            {
                string in_path       = (string)CMD_COPY.InputArgumentEntry.Arguments[0].Value;
                string full_in_path  = EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_COPY.InputArgumentEntry.Arguments[0].Value;
                string out_path      = (string)CMD_COPY.InputArgumentEntry.Arguments[1].Value;
                string full_out_path = EnvironmentVariables.GetCurrentValue("DIRECTORY") + (string)CMD_COPY.InputArgumentEntry.Arguments[1].Value;
                if (File.Exists(in_path) && in_path.Contains(":"))
                {
                    if (Directory.Exists(out_path) && out_path.Contains(":"))
                    {
                        File.Copy(in_path, out_path + (out_path.EndsWith("\\") ? "" : "\\") + Path.GetFileName(in_path));
                    }
                    else if (Directory.Exists(full_out_path))
                    {
                        File.Copy(in_path, full_out_path + (full_out_path.EndsWith("\\") ? "" : "\\") + Path.GetFileName(in_path));
                    }
                    else
                    {
                        return("\nInvalid destination path!");
                    }
                }
                else if (File.Exists(full_in_path))
                {
                    if (Directory.Exists(out_path) && out_path.Contains(":"))
                    {
                        File.Copy(full_in_path, out_path + (out_path.EndsWith("\\") ? "" : "\\") + Path.GetFileName(full_in_path));
                    }
                    else if (Directory.Exists(full_out_path))
                    {
                        File.Copy(full_in_path, full_out_path + (full_out_path.EndsWith("\\") ? "" : "\\") + Path.GetFileName(full_in_path));
                    }
                    else
                    {
                        return("\nInvalid destination path!");
                    }
                }
                else if (Directory.Exists(in_path) && in_path.Contains(":"))
                {
                    if (Directory.Exists(out_path) && out_path.Contains(":"))
                    {
                        CopyDir(in_path, out_path + (out_path.EndsWith("\\") ? "" : "\\") + new DirectoryInfo(in_path).Name);
                    }
                    else if (Directory.Exists(full_out_path))
                    {
                        CopyDir(in_path, full_out_path + (full_out_path.EndsWith("\\") ? "" : "\\") + new DirectoryInfo(in_path).Name);
                    }
                    else
                    {
                        return("\nInvalid destination path!");
                    }
                }
                else if (Directory.Exists(full_in_path))
                {
                    if (Directory.Exists(out_path) && out_path.Contains(":"))
                    {
                        CopyDir(full_in_path, out_path + (out_path.EndsWith("\\") ? "" : "\\") + new DirectoryInfo(full_in_path).Name);
                    }
                    else if (Directory.Exists(full_out_path))
                    {
                        CopyDir(full_in_path, full_out_path + (full_out_path.EndsWith("\\") ? "" : "\\") + new DirectoryInfo(full_in_path).Name);
                    }
                    else
                    {
                        return("\nInvalid destination path!");
                    }
                }
                else
                {
                    return("\nSource file/directory not found!");
                }
                return("");
            });
            return(CMD_COPY);
        }
Ejemplo n.º 25
0
        public Command GetCommand()
        {
            CTS = new CancellationTokenSource();
            CT  = CTS.Token;
            TABLE.Add(new CommandArgumentEntry("[string] [string]", true, "[wordlist path] [hash]"));
            CMD_HASHCRACK = new Command("HASHCRACK", TABLE, false, "Starts a search for a matching hash value in the specified wordlist. Supported hash types: SHA1, SHA256, SHA384, SHA512.", ExecutionLevel.User, CLIMode.Default);
            CMD_HASHCRACK.SetAsyncFunction(async() =>
            {
                processedWords = 0;
                progress       = 0;
                count          = 0;
                currentWord    = null;
                currentResult  = null;
                try
                {
                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                    {
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = true;
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown += Main_KeyDown;
                    });
                    HashType hashType;

                    string result = null;
                    async Task HASH_TASK(string word)
                    {
                        await Task.Delay(0);
                        object hashingObject = null;
                        string hash          = null;
                        if (result == null)
                        {
                            switch (hashType)
                            {
                            case HashType.SHA1:
                                hashingObject = SHA1.Create();
                                hash          = BitConverter.ToString(((SHA1)hashingObject).ComputeHash(Encoding.UTF8.GetBytes(word))).Replace("-", "");
                                break;

                            case HashType.SHA256:
                                hashingObject = SHA256.Create();
                                hash          = BitConverter.ToString(((SHA256)hashingObject).ComputeHash(Encoding.UTF8.GetBytes(word))).Replace("-", "");
                                break;

                            case HashType.SHA384:
                                hashingObject = SHA384.Create();
                                hash          = BitConverter.ToString(((SHA384)hashingObject).ComputeHash(Encoding.UTF8.GetBytes(word))).Replace("-", "");
                                break;

                            case HashType.SHA512:
                                hashingObject = SHA512.Create();
                                hash          = BitConverter.ToString(((SHA512)hashingObject).ComputeHash(Encoding.UTF8.GetBytes(word))).Replace("-", "");
                                break;
                            }
                            if (hash == CMD_HASHCRACK.InputArgumentEntry.Arguments[1].Value.ToString().ToUpper())
                            {
                                result = word;
                            }
                        }

                        currentResult = hash;
                        currentWord   = word;
                        processedWords++;
                        progress      = processedWords / count * 100;
                        word          = null;
                        hash          = null;
                        hashingObject = null;
                    }

                    List <Task> taskList = new List <Task>();
                    Regex hexCheck       = new Regex("^[a-fA-F0-9]*$");
                    switch (CMD_HASHCRACK.InputArgumentEntry.Arguments[1].Value.ToString().Length)
                    {
                    case 40 when hexCheck.IsMatch(CMD_HASHCRACK.InputArgumentEntry.Arguments[1].Value.ToString()):
                        hashType = HashType.SHA1;
                        break;

                    case 64 when hexCheck.IsMatch(CMD_HASHCRACK.InputArgumentEntry.Arguments[1].Value.ToString()):
                        hashType = HashType.SHA256;
                        break;

                    case 96 when hexCheck.IsMatch(CMD_HASHCRACK.InputArgumentEntry.Arguments[1].Value.ToString()):
                        hashType = HashType.SHA384;
                        break;

                    case 128 when hexCheck.IsMatch(CMD_HASHCRACK.InputArgumentEntry.Arguments[1].Value.ToString()):
                        hashType = HashType.SHA512;
                        break;

                    default:
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                        {
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = false;
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_KeyDown;
                        });
                        return("\nIncorrect hash format or unsupported type!");
                    }
                    string path = null;
                    if (File.Exists(CMD_HASHCRACK.InputArgumentEntry.Arguments[0].Value.ToString()) && CMD_HASHCRACK.InputArgumentEntry.Arguments[0].Value.ToString().Contains(":"))
                    {
                        path = CMD_HASHCRACK.InputArgumentEntry.Arguments[0].Value.ToString();
                    }
                    else if (File.Exists(EnvironmentVariables.GetCurrentValue("DIRECTORY").ToString() + CMD_HASHCRACK.InputArgumentEntry.Arguments[0].Value.ToString()))
                    {
                        path = EnvironmentVariables.GetCurrentValue("DIRECTORY").ToString() + CMD_HASHCRACK.InputArgumentEntry.Arguments[0].Value.ToString();
                    }
                    if (path == null)
                    {
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                        {
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = false;
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_KeyDown;
                        });
                        return("\nFile not found!");
                    }
                    string[] lines = File.ReadAllLines(path);
                    count          = lines.Length;
                    taskList.Add(Task.Run(async() => { await HASH_TASK(lines[0]); }));
                    for (int i = 0; i < lines.Length; i++)
                    {
                        if (CT.IsCancellationRequested)
                        {
                            ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                            {
                                ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = false;
                                ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_KeyDown;
                            });
                            return("\nProcess interrupted.");
                        }
                        if (result != null)
                        {
                            break;
                        }
                        taskList.RemoveAll(x => x.IsCompleted);
                        taskList.Add(Task.Run(async() => { await HASH_TASK(lines[i]); }));
                    }
                    await Task.WhenAll(taskList).ContinueWith(t => t.Dispose());
                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                    {
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = false;
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_KeyDown;
                    });
                    if (result == null)
                    {
                        return("\nNo matching hash found!");
                    }
                    return($"\nResult: {result}");
                }
                catch (Exception ex)
                {
                    ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).Dispatcher.Invoke(() =>
                    {
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).IsReadOnly      = false;
                        ((TextEditor)EnvironmentVariables.GetCurrentValue("IOFIELD")).PreviewKeyDown -= Main_KeyDown;
                        IOInteractLayer.StandardError(CMD_HASHCRACK, ex);
                    });
                    return("");
                }
            });
            return(CMD_HASHCRACK);
        }
Ejemplo n.º 26
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("-save", false));
     TABLE.Add(new CommandArgumentEntry("-save=[string]", false, "-save=[file path]"));
     TABLE.Add(new CommandArgumentEntry("-load=[string]", false, "-load=[file path]"));
     CMD_CONFIG_RUNNING = new Command("CONFIG-RUNNING", TABLE, false, "Saves/loads running config from/to the specified file.", ExecutionLevel.User, CLIMode.Default);
     CMD_CONFIG_RUNNING.SetFunction(() =>
     {
         if (CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments.Count == 0)
         {
             EnvironmentVariables.GetAll().ForEach((x) =>
             {
                 if (x.VarType == VariableType.Constant)
                 {
                     IOInteractLayer.StandardOutput(CMD_CONFIG_RUNNING, $"\n\t{x.Name} = {x.CurrentValue}");
                 }
             });
         }
         else if (CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value != null && CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString() != "")
         {
             if (CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Call == "-save")
             {
                 string path = string.Empty;
                 if (CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString().Contains("\\"))
                 {
                     if (Directory.Exists(CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString().Remove(CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString().LastIndexOf('\\'))) && CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString().Contains(':'))
                     {
                         path = CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString();
                     }
                     else if (Directory.Exists(EnvironmentVariables.GetCurrentValue("DIRECTORY").ToString() + CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString().Remove(CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString().LastIndexOf('\\'))))
                     {
                         path = EnvironmentVariables.GetCurrentValue("DIRECTORY").ToString() + CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString();
                     }
                 }
                 else
                 {
                     path = EnvironmentVariables.GetCurrentValue("DIRECTORY").ToString() + CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString();
                 }
                 if (path != string.Empty)
                 {
                     using (StreamWriter sw = new StreamWriter(CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString()))
                     {
                         EnvironmentVariables.FindAll(x => x.VarType == VariableType.Constant).ForEach((x) =>
                         {
                             sw.WriteLine($"{x.ValueType.FullName}:{x.Name}={x.CurrentValue}");
                         });
                         sw.Close();
                     }
                     return($"\nRunning config saved at: {Path.GetFullPath(path)}");
                 }
                 else
                 {
                     IOInteractLayer.StandardOutput(CMD_CONFIG_RUNNING, "\nInvalid path!");
                 }
             }
             else
             {
                 string path = string.Empty;
                 if (File.Exists(CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString()) && CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString().Contains(':'))
                 {
                     path = CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString();
                 }
                 else if (File.Exists(EnvironmentVariables.GetCurrentValue("DIRECTORY").ToString() + CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString()))
                 {
                     path = EnvironmentVariables.GetCurrentValue("DIRECTORY").ToString() + CMD_CONFIG_RUNNING.InputArgumentEntry.Arguments[0].Value.ToString();
                 }
                 if (path != string.Empty)
                 {
                     List <string> lines = File.ReadAllLines(path).ToList();
                     Type currentType;
                     string name;
                     string value;
                     lines.ForEach((x) =>
                     {
                         currentType = Type.GetType(x.Split(':')[0]);
                         x           = x.Remove(0, x.IndexOf(':') + 1);
                         name        = x.Split('=')[0];
                         value       = x.Split('=')[1];
                         try
                         {
                             EnvironmentVariables.ChangeCurrentValue(name, value);
                         }
                         catch (EnvironmentVariableException ex)
                         {
                             IOInteractLayer.StandardError(CMD_CONFIG_RUNNING, ex);
                         }
                     });
                     return($"\nRunning config loaded from: {Path.GetFullPath(path)}");
                 }
                 else
                 {
                     IOInteractLayer.StandardOutput(CMD_CONFIG_RUNNING, "\nConfig file not found!");
                 }
             }
         }
         else
         {
             using (StreamWriter sw = new StreamWriter("config.ini"))
             {
                 List <string> names = new List <string>();
                 EnvironmentVariables.FindAll(x => x.VarType == VariableType.Constant).ForEach((x) =>
                 {
                     sw.WriteLine($"{x.ValueType.FullName}:{x.Name}={x.CurrentValue}");
                     names.Add(x.Name);
                 });
                 sw.Close();
                 names.ForEach((x) =>
                 {
                     EnvironmentVariables.ChangeDefaultValue(x, EnvironmentVariables.GetCurrentValue(x), false);
                 });
             }
             return($"\nRunning config saved at: {Path.GetFullPath("config.ini")}");
         }
         return("");
     });
     return(CMD_CONFIG_RUNNING);
 }
Ejemplo n.º 27
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string]", false, "[subkey path]"));
     TABLE.Add(new CommandArgumentEntry("[string] -s", true, "[subkey path] -s(save to startup)"));
     TABLE.Add(new CommandArgumentEntry("[string] -b", true, "[subkey path] -b(save to running and startup)"));
     CMD_CSK = new Command("CSK", TABLE, false, "Changes the current subkey.", ExecutionLevel.Administrator, CLIMode.Regedit);
     CMD_CSK.SetFunction(() =>
     {
         if (CMD_CSK.InputArgumentEntry.Arguments.Count == 0)
         {
             return("\nInvalid arguments!");
         }
         RegistryHive hiveKey;
         string subKey = null;
         if (CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString() == "\\stsk")
         {
             EnvironmentVariables.SetToDefault("SUBKEY");
         }
         else if (CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString() == "..")
         {
             if (EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Count(x => x == '\\') > 1)
             {
                 string path = EnvironmentVariables.GetCurrentValue("SUBKEY").ToString();
                 path        = path.Remove(path.Length - 1, 1);
                 path        = path.Remove(path.LastIndexOf("\\"));
                 if (CMD_CSK.InputArgumentEntry.Arguments.Count == 1)
                 {
                     EnvironmentVariables.ChangeCurrentValue("SUBKEY", path + "\\");
                 }
                 else if (CMD_CSK.InputArgumentEntry.Arguments[1].Call == "-s")
                 {
                     EnvironmentVariables.ChangeDefaultValue("SUBKEY", path + "\\");
                 }
                 else
                 {
                     EnvironmentVariables.ChangeDefaultValue("SUBKEY", path + "\\");
                     EnvironmentVariables.ChangeCurrentValue("SUBKEY", path + "\\");
                 }
             }
         }
         else
         {
             try
             {
                 if (CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString().Contains("\\"))
                 {
                     hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString().Substring(0, CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf("\\")));
                     subKey  = CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString().Substring(CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf("\\") + 1);
                 }
                 else
                 {
                     hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString());
                     subKey  = "";
                 }
             }
             catch (Exception)
             {
                 hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\")));
                 subKey  = EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\") + 1) + CMD_CSK.InputArgumentEntry.Arguments[0].Value.ToString();
             }
             try
             {
                 RegistryKey newKey = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                 if (newKey == null)
                 {
                     return("\nSubkey not found!");
                 }
                 if (CMD_CSK.InputArgumentEntry.Arguments.Count == 1)
                 {
                     EnvironmentVariables.ChangeCurrentValue("SUBKEY", hiveKey.ToString() + "\\" + subKey + ((hiveKey.ToString() + "\\" + subKey).EndsWith("\\") ? "" : "\\"));
                 }
                 else if (CMD_CSK.InputArgumentEntry.Arguments[1].Call == "-s")
                 {
                     EnvironmentVariables.ChangeDefaultValue("SUBKEY", hiveKey.ToString() + "\\" + subKey + ((hiveKey.ToString() + "\\" + subKey).EndsWith("\\") ? "" : "\\"));
                 }
                 else
                 {
                     EnvironmentVariables.ChangeDefaultValue("SUBKEY", hiveKey.ToString() + "\\" + subKey + ((hiveKey.ToString() + "\\" + subKey).EndsWith("\\") ? "" : "\\"));
                     EnvironmentVariables.ChangeCurrentValue("SUBKEY", hiveKey.ToString() + "\\" + subKey + ((hiveKey.ToString() + "\\" + subKey).EndsWith("\\") ? "" : "\\"));
                 }
             }
             catch (Exception ex)
             {
                 IOInteractLayer.StandardError(CMD_CSK, ex);
             }
         }
         return("");
     });
     return(CMD_CSK);
 }
Ejemplo n.º 28
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string] [string]", false, "[name] [value]"));
     CMD_VAL_SET = new Command("VAL-SET", TABLE, false, "Modifies an existing registry value in the current subkey.", ExecutionLevel.Administrator, CLIMode.Regedit);
     CMD_VAL_SET.SetFunction(() =>
     {
         RegistryKey key = RegistryKey.OpenBaseKey((RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\"))), RegistryView.Default).OpenSubKey(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\") + 1), true);
         if (CMD_VAL_SET.InputArgumentEntry.Arguments[0].Value.ToString().ToList().Contains('=') && !CMD_VAL_SET.InputArgumentEntry.Arguments[0].Value.ToString().EndsWith("="))
         {
             string name            = CMD_VAL_SET.InputArgumentEntry.Arguments[0].Value.ToString();
             string value           = CMD_VAL_SET.InputArgumentEntry.Arguments[1].Value.ToString();
             RegistryValueKind type = key.GetValueKind(name);
             if (key.GetValueNames().Contains(name))
             {
                 try
                 {
                     if (type == RegistryValueKind.DWord || type == RegistryValueKind.QWord || type == RegistryValueKind.Binary)
                     {
                         key.SetValue(name, int.Parse(value), type);
                     }
                     else
                     {
                         key.SetValue(name, value);
                     }
                 }
                 catch (Exception ex)
                 {
                     IOInteractLayer.StandardError(CMD_VAL_SET, ex);
                 }
             }
             else
             {
                 return("\nValue not found!");
             }
         }
         else
         {
             return("\nIncorrect format!");
         }
         return("");
     });
     return(CMD_VAL_SET);
 }
Ejemplo n.º 29
0
        public Command GetCommand()
        {
            TABLE.Add(new CommandArgumentEntry("[string]", false, "[registry path/filter]"));
            TABLE.Add(new CommandArgumentEntry("[string] [string]", false, "[registry path] [filter]"));
            CMD_SK_GET = new Command("SK-GET", TABLE, true, "Returns all subkeys in the specified subkey(current subkey if not specified).", ExecutionLevel.Administrator, CLIMode.Regedit);
            CMD_SK_GET.SetFunction(() =>
            {
                RegistryHive hiveKey;
                string subKey           = null;
                RegistryKey newKey      = null;
                string[] keys           = null;
                Interpreter interpreter = null;
                switch (CMD_SK_GET.InputArgumentEntry.Arguments.Count)
                {
                case 0:
                    hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\")));
                    subKey  = EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\") + 1);
                    newKey  = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                    try
                    {
                        keys = newKey.GetSubKeyNames();
                        for (int i = 0; i < keys.Length; i++)
                        {
                            IOInteractLayer.StandardOutput(CMD_SK_GET, "\n" + keys[i]);
                        }
                    }
                    catch (Exception ex)
                    {
                        IOInteractLayer.StandardError(CMD_SK_GET, ex);
                    }
                    break;

                case 1:
                    try
                    {
                        //Check if input is full path
                        hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().Substring(0, CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf("\\")));
                        subKey  = CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().Substring(CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf("\\") + 1);
                        newKey  = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                    }
                    catch (Exception)
                    {
                        //Check if input is relative path
                        hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\")));
                        subKey  = EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\") + 1) + CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString();
                        newKey  = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                        if (newKey == null)
                        {
                            try
                            {
                                //Check if input is hive
                                if (CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().Contains("\\"))
                                {
                                    hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().Substring(0, CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf("\\")));
                                }
                                else
                                {
                                    hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString());
                                }
                                subKey = "";
                                newKey = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                            }
                            catch (Exception)
                            {
                                //Input is filter
                                hiveKey     = (RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\")));
                                subKey      = EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\") + 1);
                                newKey      = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                                interpreter = new Interpreter(CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString());
                            }
                        }
                    }
                    try
                    {
                        keys = newKey.GetSubKeyNames();
                        if (interpreter == null)
                        {
                            for (int i = 0; i < keys.Length; i++)
                            {
                                IOInteractLayer.StandardOutput(CMD_SK_GET, "\n" + keys[i]);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < keys.Length; i++)
                            {
                                if (interpreter.GetResult(keys[i]))
                                {
                                    IOInteractLayer.StandardOutput(CMD_SK_GET, "\n" + keys[i]);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        IOInteractLayer.StandardError(CMD_SK_GET, ex);
                    }
                    break;

                case 2:
                    try
                    {
                        //Check if input is full path
                        hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().Substring(0, CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf("\\")));
                        subKey  = CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().Substring(CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf("\\") + 1);
                        newKey  = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                    }
                    catch (Exception)
                    {
                        //Check if input relative full path
                        hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\")));
                        subKey  = EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\") + 1) + CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString();
                        newKey  = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                        if (newKey == null)
                        {
                            try
                            {
                                //Check if input is hive
                                if (CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().Contains("\\"))
                                {
                                    hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().Substring(0, CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString().IndexOf("\\")));
                                }
                                else
                                {
                                    hiveKey = (RegistryHive)Enum.Parse(typeof(RegistryHive), CMD_SK_GET.InputArgumentEntry.Arguments[0].Value.ToString());
                                }
                                subKey = "";
                                newKey = RegistryKey.OpenBaseKey(hiveKey, RegistryView.Default).OpenSubKey(subKey);
                            }
                            catch (Exception)
                            {
                                return("\nSubkey not found!");
                            }
                        }
                    }
                    try
                    {
                        interpreter = new Interpreter(CMD_SK_GET.InputArgumentEntry.Arguments[1].Value.ToString());
                        keys        = newKey.GetSubKeyNames();
                        for (int i = 0; i < keys.Length; i++)
                        {
                            if (interpreter.GetResult(keys[i]))
                            {
                                IOInteractLayer.StandardOutput(CMD_SK_GET, "\n" + keys[i]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        IOInteractLayer.StandardError(CMD_SK_GET, ex);
                    }
                    break;
                }
                return("");
            });
            return(CMD_SK_GET);
        }
Ejemplo n.º 30
0
 public Command GetCommand()
 {
     TABLE.Add(new CommandArgumentEntry("[string] [string]", false, "[old name] [new name]"));
     CMD_VAL_RENAME = new Command("VAL-RENAME", TABLE, false, "", ExecutionLevel.Administrator, CLIMode.Regedit);
     CMD_VAL_RENAME.SetFunction(() =>
     {
         RegistryKey key = RegistryKey.OpenBaseKey((RegistryHive)Enum.Parse(typeof(RegistryHive), EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(0, EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\"))), RegistryView.Default).OpenSubKey(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().Substring(EnvironmentVariables.GetCurrentValue("SUBKEY").ToString().IndexOf("\\") + 1), true);
         string[] names  = null;
         try
         {
             names = key.GetValueNames();
             if (names.Contains(CMD_VAL_RENAME.InputArgumentEntry.Arguments[0].Value.ToString()))
             {
                 if (names.Contains(CMD_VAL_RENAME.InputArgumentEntry.Arguments[1].Value.ToString()))
                 {
                     return("\nA value with the specified new name already exist!");
                 }
                 else
                 {
                     string name            = CMD_VAL_RENAME.InputArgumentEntry.Arguments[0].Value.ToString();
                     RegistryValueKind type = key.GetValueKind(name);
                     object value           = key.GetValue(name);
                     key.DeleteValue(name);
                     key.SetValue(CMD_VAL_RENAME.InputArgumentEntry.Arguments[1].Value.ToString(), value, type);
                 }
             }
             else
             {
                 return("\nValue not found!");
             }
         }
         catch (Exception ex)
         {
             IOInteractLayer.StandardError(CMD_VAL_RENAME, ex);
         }
         return("");
     });
     return(CMD_VAL_RENAME);
 }