Example #1
0
        public static void TreatRequest(string request,
                                        ref List <KeyValuePair <string, string> > list)
        {
            string rq   = string.Empty;
            string args = string.Empty;

            if (request.Contains('|'))
            {
                string[] temp = request.Substring(3).Split(new char[] { '|' },
                                                           2);
                rq   = temp[0];
                args = temp[1];
            }
            else
            {
                rq = request.Substring(3);
            }
            int index = list.FindIndex(x => x.Key == rq);

            if (index != -1)
            {
                if (File.Exists(list[index].Value))
                {
                    if (DAHelper.IsCommandLine(list[index].Value))
                    {
                        Process.Start("cmd", "/c \"" + list[index].Value + " "
                                      + args + "||pause\"");
                    }
                    else
                    {
                        Process.Start(list[index].Value, args);
                    }
                }
                else if (UAHelper.IsApp(list[index].Value))
                {
                    UAHelper.RunApplication(list[index].Value);
                }
                else
                {
                    Console.WriteLine("\tProgram requested was missing.");
                }
            }
            else
            {
                Console.WriteLine("\tProgram requested was not in the list");
            }
        }
Example #2
0
        /// <summary>
        /// Return a list of all the binaries and links.
        /// </summary>
        /// <param name="ParseStartmenu">Should we crawl the start menu</param>
        /// <param name="BlackList">Array of regexes</param>
        /// <returns></returns>
        public static List <KeyValuePair <string, string> > GetBinaries(
            bool ParseStartmenu, Regex[] BlackList)
        {
            string[] paths = GetEnvironmentVariable("PATH").Split(';');
            string[] exts  = GetEnvironmentVariable("PATHEXT").Split(';');

            List <KeyValuePair <string, string> > output =
                new List <KeyValuePair <string, string> >();

            Console.WriteLine("Parsing paths");
            foreach (string path in paths)
            {
                if (Directory.Exists(path))
                {
                    foreach (string file in Directory.EnumerateFiles(path))
                    {
                        bool matchesExt = false;
                        foreach (string ext in exts)
                        {
                            if (file.ToUpper().EndsWith(ext))
                            {
                                matchesExt = true;
                            }
                        }
                        if (!matchesExt)
                        {
                            continue;
                        }

                        string name        = Path.GetFileNameWithoutExtension(file);
                        bool   onBlacklist = false;

                        foreach (Regex rgx in BlackList)
                        {
                            if (rgx.IsMatch(name))
                            {
                                onBlacklist = true;
                            }
                        }

                        if (!onBlacklist)
                        {
                            output.Add(new KeyValuePair <string, string>(
                                           Path.GetFileNameWithoutExtension(file),
                                           file));
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Path is invalid {" + path + "}");
                }
            }

            if (ParseStartmenu)
            {
                Console.WriteLine("Parsing start menus");
                string userSm  = GetFolderPath(SpecialFolder.StartMenu);
                string globlSm = GetFolderPath(SpecialFolder.CommonStartMenu);


                List <string> links = new List <string>();
                links.AddRange(recursivelyListLinks(userSm));
                links.AddRange(recursivelyListLinks(globlSm));
                foreach (string link in links)
                {
                    string name        = Path.GetFileNameWithoutExtension(link);
                    bool   onBlacklist = false;

                    foreach (Regex rgx in BlackList)
                    {
                        if (rgx.IsMatch(name))
                        {
                            onBlacklist = true;
                        }
                    }

                    if (!onBlacklist)
                    {
                        output.Add(new KeyValuePair <string, string>(
                                       Path.GetFileNameWithoutExtension(link), link));
                    }
                }
                output.AddRange(
                    UAHelper.GetApplicationList());
            }

            Console.WriteLine("Done parsing");
            return(output);
        }