Exemple #1
0
        /// <summary>
        /// Changes the current directory
        /// </summary>
        /// <param name="directory">The directory to be working into.</param>
        /// <param name="dir">holds a formatted version of the directory path.</param>
        /// <returns></returns>
        public bool cd(List <string> directory)
        {
            Formatters format = new Formatters();
            Rashell    shell  = new Rashell();

            if (directory.Count != 0)
            {
                try
                {
                    string dir = format.RemoveSpace(directory[0].ToLower());

                    if (!string.IsNullOrEmpty(dir) && !string.IsNullOrWhiteSpace(dir) && Directory.Exists(dir))
                    {
                        Directory.SetCurrentDirectory(dir);
                        int CountSlash = 0;

                        //Formats the shell working directory.
                        foreach (char slash in Directory.GetCurrentDirectory())
                        {
                            if (slash.ToString() == "\\")
                            {
                                CountSlash++;
                            }
                        }

                        string dirname = Directory.GetCurrentDirectory().ToString();
                        string workdir;

                        if (CountSlash != 1)
                        {
                            if (!string.IsNullOrEmpty(dirname) || !string.IsNullOrWhiteSpace(dirname))
                            {
                                workdir = shell.setShellWorkingDirectory(shell.getSessionUser(), dirname);
                            }
                            else
                            {
                                workdir = shell.setShellWorkingDirectory(shell.getSessionUser(), dir);
                            }
                        }
                        else
                        {
                            workdir = shell.setShellWorkingDirectory(shell.getSessionUser(), Directory.GetCurrentDirectory());
                        }

                        Rashell.ShellSessionDirectory = workdir;
                    }
                    else
                    {
                        Console.WriteLine("The directory you specified is invalid.");
                    }
                }
                catch (Exception)
                {
                }
            }
            return(true);
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            //Call init functions
            Rashell shell = new Rashell();

            //assign shell arguments
            Rashell.RashellArguments = args;

            shell.Init();
            shell.ExecArgument();
            shell.Listen();
        }
Exemple #3
0
        /// <summary>
        /// An extended version of the whoami command.
        /// </summary>
        /// <returns></returns>
        public bool whoami()
        {
            Rashell shell    = new Rashell();
            string  user     = shell.getSessionUser();
            string  domain   = Environment.MachineName.ToString();
            string  profile  = "\"" + Environment.ExpandEnvironmentVariables("%userprofile%") + "\"";
            string  sys_user = Environment.UserName.ToString();

            if (shell.IsAdministrator() == false)
            {
                Console.WriteLine("Session User: "******"\n" + "System User: "******"\n" + "Elevation: Standard" +
                                  "\n" + "Domain: " + domain + "\n" + "Profile: " + profile);
            }
            else
            {
                Console.WriteLine("Session User: "******"\n" + "System User: "******"\n" + "Elevation: Administrator" +
                                  "\n" + "Domain: " + domain + "\n" + "Profile: " + profile);
            }

            return(true);
        }
        /// <summary>
        /// Reads the configuration file and load the parameters
        /// </summary>
        /// <param name="FoundEnvi">Flag: Used to tell the program that en environment path is found.</param>
        /// <param name="FoundKnown">Flag: Used to tell the program that a executable extension is found.</param>
        /// <param name="Working_Dir">Tmp hold the DEF_WORKING_DIR path.</param>
        /// <param name="ElevationRequested">Whether Rights Elevation was required.</param>

        public bool Read()
        {
            bool   FoundEnvi          = false;
            bool   FoundKnown_Ex      = false;
            string Working_Dir        = null;
            bool   ElevationRequested = false;

Start:
            if (File.Exists(config_path))
            {
                StreamReader ConfigReader = new StreamReader(this.config_path);
                while (!ConfigReader.EndOfStream)
                {
                    string line = ConfigReader.ReadLine().ToUpper();
                    line = format.RemoveTab(line);
                    line = format.RemoveSpace(line);

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.StartsWith("ENVIRONMENT_PATHS {"))
                        {
                            FoundEnvi = true;
                        }
                        else if (line.StartsWith("KNOWN_EXECUTABLES {"))
                        {
                            FoundKnown_Ex = true;
                        }
                        else if (line.StartsWith("DEF_WORKING_DIR ="))
                        {
                            if (line.EndsWith(";"))
                            {
                                Working_Dir = line.Substring(line.IndexOf("=") + 1, (line.Length - (line.IndexOf("=") + 1)) - 1);

                                if (!string.IsNullOrEmpty(Working_Dir) && !string.IsNullOrWhiteSpace(Working_Dir))
                                {
                                    Working_Dir = format.Break(Working_Dir);
                                    if (Directory.Exists(Working_Dir))
                                    {
                                        this.DEF_WORKING_DIR = Working_Dir;
                                    }
                                }
                            }
                        }
                        else if (line.StartsWith("ENABLE_EVT_LOGGING:"))
                        {
                            if (line.EndsWith(";"))
                            {
                                string log = null;
                                log = line.Substring(line.IndexOf(":") + 2, (line.Length - (line.IndexOf(":") + 1)) - 2);
                                if (log == "ON")
                                {
                                    this.ENABLE_EVT_LOG = true;
                                }
                                else if (log == "OFF")
                                {
                                    this.ENABLE_EVT_LOG = false;
                                }
                            }
                        }
                        else if (line.StartsWith("ENABLE_ERR_LOGGING:"))
                        {
                            if (line.EndsWith(";"))
                            {
                                string log = null;
                                log = line.Substring(line.IndexOf(":") + 2, (line.Length - (line.IndexOf(":") + 1)) - 2);
                                if (log == "ON")
                                {
                                    this.ENABLE_ERR_LOG = true;
                                }
                                else if (log == "OFF")
                                {
                                    this.ENABLE_ERR_LOG = false;
                                }
                            }
                        }
                        else if (line.StartsWith("PRIORITIZE_BUILTIN_SHELL:"))
                        {
                            if (line.EndsWith(";"))
                            {
                                string log = null;
                                log = line.Substring(line.IndexOf(":") + 2, (line.Length - (line.IndexOf(":") + 1)) - 2);
                                if (log == "ON")
                                {
                                    this.PRIORITIZE_BUILTIN_SHELL = true;
                                }
                                else if (log == "OFF")
                                {
                                    this.PRIORITIZE_BUILTIN_SHELL = false;
                                }
                            }
                        }
                        else if (line.StartsWith("WELCOME_MESSAGE:"))
                        {
                            if (line.EndsWith(";"))
                            {
                                string log = null;
                                log = line.Substring(line.IndexOf(":") + 2, (line.Length - (line.IndexOf(":") + 1)) - 2);
                                if (log == "ON")
                                {
                                    this.DISPLAY_WELCOME_MSG = true;
                                }
                                else if (log == "OFF")
                                {
                                    this.DISPLAY_WELCOME_MSG = false;
                                }
                            }
                        }
                        else if (FoundEnvi)
                        {
                            string envipath = null;
                            if (line.EndsWith(";") && line.Length > 1)
                            {
                                envipath = line.Substring(0, line.Length - 1);
                                envipath = format.Break(envipath);

                                if (Directory.Exists(envipath))
                                {
                                    this.EnvironmentPaths.Add(envipath);
                                }
                            }
                            else if (line == "}")
                            {
                                FoundEnvi = false;
                            }
                        }
                        else if (FoundKnown_Ex)
                        {
                            string extension = null;
                            if (line.EndsWith(";") && line.Length > 1)
                            {
                                extension = line.Substring(0, line.Length - 1);
                                if (extension.StartsWith("."))
                                {
                                    this.Known_Extensions.Add(extension);
                                }
                            }
                            else if (line == "}")
                            {
                                FoundKnown_Ex = false;
                            }
                        }
                    }
                }

                ConfigReader.Close();
            }
            else
            {
                try
                {
                    Generate();
                } catch (Exception e)
                {
                    if (e.ToString().Contains("requires elevation"))
                    {
                        if (!ElevationRequested)
                        {
                            try
                            {
                                ElevationRequested = true;
                                Rashell shell = new Rashell();
                                shell.restartAsAdmin();
                            } catch (Exception x)
                            {
                            }
                        }
                        else
                        {
                            Environment.Exit(1);
                        }
                    }
                }

                goto Start;
            }
            return(true);
        }