コード例 #1
0
 public IEnumerable <ModuleHeader <Payload> > GetAvailables(IPayloadRequirements req)
 {
     foreach (ModuleHeader <Payload> p in Current)
     {
         if (!req.IsAllowed(p))
         {
             continue;
         }
         yield return(p);
     }
 }
コード例 #2
0
        public Payload[] GetPayloadAvailables(IPayloadRequirements req)
        {
            if (req == null)
            {
                return new Payload[] { }
            }
            ;
            List <Payload> ls = new List <Payload>();

            foreach (Payload p in PayloadCollection.Current)
            {
                if (!req.IsAllowed(p))
                {
                    continue;
                }
                ls.Add(p);
            }
            return(ls.ToArray());
        }
    }
コード例 #3
0
        public IEnumerable <string> GetArgument(string command, string[] arguments)
        {
            switch (command.ToLowerInvariant().Trim())
            {
            case "man":
            case "help":
            {
                foreach (CommandMenuItem m in _Command)
                {
                    foreach (string sep in m.Selector)
                    {
                        yield return(sep);
                    }
                }

                break;
            }

            case "use":
            {
                foreach (ModuleHeader <Module> e in ModuleCollection.Current)
                {
                    yield return(e.FullPath);
                }
                foreach (ModuleHeader <Payload> e in PayloadCollection.Current)
                {
                    yield return(e.FullPath);
                }
                break;
            }

            case "show":
            {
                if (arguments == null || arguments.Length <= 1)
                {
                    foreach (string e in new string[] { "options", "config", "payloads", "targets", "info" })
                    {
                        yield return(e);
                    }
                }
                break;
            }

            case "set":
            case "gset":
            {
                if (_Current == null)
                {
                    break;
                }

                Module curM = _Current.ModuleType == EModuleType.Module ? (Module)_Current : null;

                if (arguments == null || arguments.Length <= 1)
                {
                    if (curM != null)
                    {
                        Target[] t = curM.Targets;
                        if (t != null && t.Length > 1)
                        {
                            yield return("Target");
                        }
                        if (curM.PayloadRequirements != null)
                        {
                            yield return("Payload");
                        }

                        if (curM.Payload != null)
                        {
                            foreach (PropertyInfo pi in ReflectionHelper.GetProperties(curM.Payload, true, true, true))
                            {
                                yield return(pi.Name);
                            }
                        }
                    }

                    foreach (PropertyInfo pi in ReflectionHelper.GetProperties(_Current, true, true, true))
                    {
                        yield return(pi.Name);
                    }
                }
                else
                {
                    string pname = arguments[0].ToLowerInvariant().Trim();
                    switch (pname)
                    {
                    case "target":
                    {
                        Target[] ts = curM == null ? null : curM.Targets;
                        if (ts != null)
                        {
                            foreach (Target t in ts)
                            {
                                yield return(t.Id.ToString());
                            }
                        }
                        break;
                    }

                    case "payload":
                    {
                        IPayloadRequirements req = curM == null ? null : curM.PayloadRequirements;
                        if (req != null && req.ItsRequired())
                        {
                            foreach (ModuleHeader <Payload> p in PayloadCollection.Current)
                            {
                                if (!req.IsAllowed(p))
                                {
                                    continue;
                                }

                                yield return(p.FullPath);
                            }
                        }
                        break;
                    }

                    default:
                    {
                        // By property value
                        PropertyInfo[] pi = null;

                        object ob = null;
                        if (curM != null && curM.Payload != null)
                        {
                            pi = ReflectionHelper.GetProperties(curM.Payload, pname);
                            ob = curM.Payload;
                        }

                        if (pi == null || pi.Length == 0)
                        {
                            pi = ReflectionHelper.GetProperties(_Current, pname);
                            ob = _Current;
                        }
                        if (pi != null && pi.Length > 0)
                        {
                            Type tp = pi[0].PropertyType;
                            if (tp == typeof(bool))
                            {
                                yield return("true");

                                yield return("false");
                            }
                            else
                            {
                                if (tp.IsEnum)
                                {
                                    foreach (string name in Enum.GetNames(pi[0].PropertyType))
                                    {
                                        yield return(name);
                                    }
                                }
                                else
                                {
                                    if (ob != null)
                                    {
                                        AutoFillAttribute auto = pi[0].GetCustomAttribute <AutoFillAttribute>();
                                        if (auto != null)
                                        {
                                            MethodInfo mi = ReflectionHelper.GetMethods(ob.GetType(), auto.Function).FirstOrDefault();
                                            if (mi != null)
                                            {
                                                object var = mi.Invoke(ob, new object[] { });
                                                if (var is string[])
                                                {
                                                    if (var is string[])
                                                    {
                                                        foreach (string v in ((string[])var))
                                                        {
                                                            yield return(v);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (var is IEnumerable <string> )
                                                    {
                                                        foreach (string v in ((IEnumerable <string>)var))
                                                        {
                                                            yield return(v);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (tp == typeof(Encoding))
                                    {
                                        foreach (EncodingInfo v in Encoding.GetEncodings())
                                        {
                                            yield return(v.Name);
                                        }
                                    }
                                    else if (/*tp == typeof(string) ||*/ tp == typeof(FileInfo) || tp == typeof(DirectoryInfo))
                                    {
                                        string path = arguments[1];

                                        if (!string.IsNullOrEmpty(path))
                                        {
                                            string pathl = path.ToLowerInvariant();

                                            bool allowFolders =
                                                tp == typeof(DirectoryInfo) /*||
                                                                             * pi[0].Name.ToLowerInvariant().Contains("folder") ||
                                                                             * pi[0].Name.ToLowerInvariant().Contains("directory") ||
                                                                             * pi[0].Name.ToLowerInvariant().Contains("path")*/;

                                            bool allowFiles = !allowFolders;
                                            //if (!allowFiles) allowFolders = true;

                                            if (Directory.Exists(path))
                                            {
                                                if (allowFiles)
                                                {
                                                    foreach (string dir in Directory.GetFiles(path))
                                                    {
                                                        yield return(dir);
                                                    }
                                                }
                                                if (allowFolders)
                                                {
                                                    foreach (string dir in Directory.GetDirectories(path))
                                                    {
                                                        yield return(dir);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                bool   isWindows = SystemHelper.IsWindows;
                                                string path2     = Path.GetDirectoryName(path);

                                                if (!string.IsNullOrEmpty(path2) && Directory.Exists(path2))
                                                {
                                                    if (allowFiles)
                                                    {
                                                        foreach (string dir in Directory.GetFiles(path2))
                                                        {
                                                            if (isWindows)
                                                            {
                                                                if (!dir.ToLowerInvariant().StartsWith(pathl))
                                                                {
                                                                    continue;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (!dir.StartsWith(path))
                                                                {
                                                                    continue;
                                                                }
                                                            }
                                                            yield return(dir);
                                                        }
                                                    }
                                                    foreach (string dir in Directory.GetDirectories(path2))
                                                    {
                                                        if (isWindows)
                                                        {
                                                            if (!dir.ToLowerInvariant().StartsWith(pathl))
                                                            {
                                                                continue;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (!dir.StartsWith(path))
                                                            {
                                                                continue;
                                                            }
                                                        }

                                                        if (allowFolders)
                                                        {
                                                            foreach (string d in Directory.GetDirectories(dir))
                                                            {
                                                                yield return(d);
                                                            }
                                                        }
                                                        if (allowFiles)
                                                        {
                                                            foreach (string d in Directory.GetFiles(dir))
                                                            {
                                                                yield return(d);
                                                            }
                                                        }

                                                        if (allowFolders)
                                                        {
                                                            yield return(dir);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                    }
                }
                break;
            }
            }
        }