// find files in a directory and subdirs
        public static void fileSearch(string dir, List <string> list)
        {
            try
            {
                string[] files = Directory.GetFiles(dir);

                foreach (string f in files)
                {
                    if (f.EndsWith("lnk"))
                    {
                        list.Add(FileUtils.getPathFromLnk(f));
                    }
                    else
                    {
                        list.Add(f);
                    }
                }
            }
            catch (Exception e)
            {
                //Console.WriteLine(e.Message);
            }

            try
            {
                string[] dirs = Directory.GetDirectories(dir);
                foreach (string d in dirs)
                {
                    fileSearch(d, list);
                }
            }
            catch (Exception e) { }
        }
        // find files in a directory and subdirs
        public static void fileSearch(string dir, List <ScannedObject> list, string[] allowedExtensions = null)
        {
            try
            {
                if (!Settings.working)
                {
                    return;
                }

                string[] files = null;

                if (allowedExtensions == null)
                {
                    files = Directory.GetFiles(dir);
                }
                else
                {
                    files = Directory.GetFiles(dir).Where(s =>
                                                          allowedExtensions.Any(e => s.ToLower().EndsWith(e))
                                                          ).ToArray();
                }


                if (!Settings.working)
                {
                    return;
                }

                foreach (string f in files)
                {
                    if (f.EndsWith("lnk"))
                    {
                        list.Add(new ScannedObject("lnk", FileUtils.getPathFromLnk(f), "", ""));
                    }
                    else
                    {
                        list.Add(new ScannedObject("file", f, "", ""));
                    }
                }
            }
            catch (Exception e)
            {
            }

            try
            {
                string[] dirs = Directory.GetDirectories(dir);
                foreach (string d in dirs)
                {
                    if (!Settings.working)
                    {
                        return;
                    }

                    fileSearch(d, list, allowedExtensions);
                }
            }
            catch (Exception e) { }
        }
Exemple #3
0
        //registry search
        public static void regSearch(bool CurrentUser, string subKeyName, string valueName, List <string> list)
        {
            try
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey(subKeyName);

                if (valueName != null)
                {
                    string f = (string)key.GetValue(valueName);

                    if (f.EndsWith("lnk")) //if it is a link ...
                    {
                        // ... then extract the path from LNK and add to list
                        list.Add(FileUtils.getPathFromLnk(f));
                    }
                    else
                    {
                        // add file path to list
                        list.Add(f);
                    }
                }
                else
                {
                    // check multiple values
                    string[] valuesNames = key.GetValueNames();

                    foreach (var name in valuesNames)
                    {
                        string f = (string)key.GetValue(name);
                        if (f.EndsWith("lnk"))
                        {
                            list.Add(FileUtils.getPathFromLnk(f));
                        }
                        else
                        {
                            list.Add(f);
                        }
                    }
                }
            }
            catch (Exception e) { }
        }
        //registry search
        public static void regSearch(bool CurrentUser, string subKeyName, string valueName, List <ScannedObject> list)
        {
            try
            {
                string basekey = "HKLM";
                if (CurrentUser)
                {
                    basekey = "HKCU";
                }

                RegistryKey key = Registry.CurrentUser.OpenSubKey(subKeyName);

                if (valueName != null)
                {
                    string f = (string)key.GetValue(valueName);

                    if (f.EndsWith("lnk")) //if it is a link ...
                    {
                        // ... then extract the path from LNK and add to list
                        list.Add(new ScannedObject("registry", basekey + "\\" + subKeyName + "\\" + valueName, FileUtils.getPathFromLnk(f), ""));
                    }
                    else
                    {
                        // add file path to list
                        list.Add(new ScannedObject("registry", basekey + "\\" + subKeyName + "\\" + valueName, f, ""));
                    }
                }
                else
                {
                    // check multiple values
                    string[] valuesNames = key.GetValueNames();

                    foreach (var name in valuesNames)
                    {
                        string f = (string)key.GetValue(name);
                        if (f.EndsWith("lnk"))
                        {
                            list.Add(new ScannedObject("registry", basekey + "\\" + subKeyName + "\\" + name, FileUtils.getPathFromLnk(f), ""));
                        }
                        else
                        {
                            list.Add(new ScannedObject("registry", basekey + "\\" + subKeyName + "\\" + name, f, ""));
                        }
                    }
                }
            }
            catch (Exception e) { }
        }