コード例 #1
0
ファイル: Funcs.cs プロジェクト: Falofa/Vulner
 static public T PickRnd <T>(T[] s)
 {
     return(s[Funcs.Rnd(0, s.Length)]);
 }
コード例 #2
0
ファイル: Funcs.cs プロジェクト: Falofa/Vulner
        public static bool Run(string content, Main m)
        {
            bool   header = true;
            bool   stop   = false;
            bool   close  = true;
            bool   hidden = false;
            string dump   = "";

            Dictionary <string, Func <string, int> > properties = new Dictionary <string, Func <string, int> >()
            {
                { "window", (s) =>
                  {
                      if (s.ToLower().Trim() == "hidden")
                      {
                          hidden = true;
                      }
                      else
                      {
                          hidden = false;
                      }
                      return(1);
                  } },
                { "dump", (s) =>
                  {
                      dump = s.ToLower();
                      return(1);
                  } },
                { "close", (s) =>
                  {
                      close = bool.Parse(s);
                      return(1);
                  } },
            };

            try
            {
                foreach (string s in content.Split('\n'))
                {
                    if (stop)
                    {
                        break;
                    }
                    string str = s.Trim();
                    if (Regex.Match(str, @"^[\s]*$").Success)
                    {
                        continue;
                    }
                    if (str.StartsWith("@") && header)
                    {
                        string att = str.Split(' ')[0].Substring(1).ToLower();
                        string val = str.Substring(att.Length + 1);
                        if (properties.ContainsKey(att))
                        {
                            properties[att].Invoke(val);
                            if (stop)
                            {
                                break;
                            }
                        }
                        continue;
                    }
                    else if (header)
                    {
                        header = false;
                        if (hidden)
                        {
                            Funcs.HideConsole();
                        }
                        else
                        {
                            Funcs.ShowConsole();
                        }
                    }
                    m.RunCommand(str);
                }
            } catch (Exception)
            {
            }
            if (dump != "")
            {
                try { File.WriteAllText(dump, m.t.EndBuffer()); } catch (Exception) { }
            }
            if (close)
            {
                Process.GetCurrentProcess().Kill();
            }
            return(true);
        }
コード例 #3
0
ファイル: Funcs.cs プロジェクト: Falofa/Vulner
 static public char PickRnd(string s)
 {
     return(s[Funcs.Rnd(0, s.Length)]);
 }
コード例 #4
0
ファイル: Funcs.cs プロジェクト: Falofa/Vulner
        public static void RegexRename(string In, string Out, TerminalController Console, bool Copy = false, bool Randomize = false)
        {
            string Reg = Regex.Escape(In).Replace(@"\*", "(.+)");

            int u = 0;
            Dictionary <string, string> Fr = new Dictionary <string, string>();

            foreach (string s in Directory.GetFiles(Environment.CurrentDirectory))
            {
                FileInfo f = new FileInfo(s);
                Match    r = Regex.Match(f.Name, Reg);
                if (r.Success)
                {
                    if (Copy)
                    {
                        Fr[f.FullName] = f.FullName;
                    }
                    else
                    {
                        Fr[f.FullName] = Path.Combine(f.Directory.FullName, u.ToString("X8") + RandomString(40, 50) + "." + RandomString(3));
                        File.Move(f.FullName, Fr[f.FullName]);
                    }
                    u++;
                }
            }
            int kv = 0;
            IEnumerable <KeyValuePair <string, string> > Rf = Fr.OrderBy(o => Funcs.Rnd());
            IEnumerable <KeyValuePair <string, string> > Of = Fr.AsEnumerable();

            foreach (KeyValuePair <string, string> s in (Randomize ? Rf : Of))
            {
                FileInfo f   = new FileInfo(s.Key);
                Match    r   = Regex.Match(f.Name, Reg);
                string   res = "";
                string[] v   = new string[r.Groups.Count];
                int      i   = 0;

                foreach (Group b in r.Groups)
                {
                    v[i++] = b.Value;
                }
                res = Out;
                try
                {
                    for (int k = 0; k < v.Length; k++)
                    {
                        res = res.Replace("$" + k, v[k]);
                    }
                    res = res.Replace("$i", kv.ToString());
                    if (Copy)
                    {
                        File.Copy(s.Value, new FileInfo(res).FullName);
                    }
                    else
                    {
                        File.Move(s.Value, new FileInfo(res).FullName);
                    }
                    Console.ColorWrite("$a{0} $c=> $f{1}", f.Name, res);
                }
                catch (Exception ex)
                {
                    Console.ColorWrite("$c{0} $c=> $f{1} $c- Error: {2}", f.Name, res, ex.Message);
                }
                kv++;
            }
        }