Ejemplo n.º 1
0
        public void LocateHooks()
        {
            _discovered = new List <APIPath>(); // Always reset this list at the start of this method!
            try
            {
                int i = 0;
                for (i = 0; i < AppDomain.CurrentDomain.GetAssemblies().Length; i++)
                {
                    Assembly asm = null;

                    try
                    {
                        asm = AppDomain.CurrentDomain.GetAssemblies()[i];
                    } catch (Exception e)
                    {
                        // nothing needs be done here
                    }

                    if (asm != null)
                    {
                        int ii = 0;
                        for (ii = 0; ii < asm.GetTypes().Length; ii++)
                        {
                            Type _type = null;
                            try
                            {
                                _type = asm.GetTypes()[ii];
                            }catch (Exception E) { }
                            if (_type != null)
                            {
                                if (_type.IsClass)
                                {
                                    foreach (MethodInfo MI in _type.GetMethods())
                                    {
                                        APIPath[] paths = (APIPath[])MI.GetCustomAttributes(typeof(APIPath), true);

                                        int ix = 0;
                                        for (ix = 0; ix < paths.Length; ix++)
                                        {
                                            APIPath _path = paths[ix];
                                            _path.AssignedMethod = MI;
                                            _discovered.Add(_path);

                                            Console.WriteLine("Discovered: " + _path.PathLike + "; " + MI.Name);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }catch (Exception e)
            {
            }
        }
Ejemplo n.º 2
0
        public void LocateCommands()
        {
            try
            {
                int i = 0;
                // Locate all commands--
                for (i = 0; i < AppDomain.CurrentDomain.GetAssemblies().Length; i++)
                {
                    Assembly A = null;
                    try
                    {
                        A = AppDomain.CurrentDomain.GetAssemblies()[i];
                    }
                    catch (Exception e)
                    {
                        //                    MHEx(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "")
                    }
                    if (A != null)
                    {
                        int ii = 0;
                        for (ii = 0; ii < A.GetTypes().Length; ii++)
                        {
                            Type T = null;
                            try
                            {
                                T = A.GetTypes()[ii];
                            }
                            catch (Exception e)
                            {
                            }
                            if (T != null)
                            {
                                if (T.IsClass)
                                {
                                    foreach (MethodInfo MI in T.GetMethods())
                                    {
                                        CommandGroup[] Command = (CommandGroup[])MI.GetCustomAttributes(typeof(CommandGroup), false);
                                        //var CommandO = MI.GetCustomAttributes(typeof(CommandGroup), false);
                                        if (Command.Length > 0)
                                        {
                                            for (int ix = 0; ix < Command.Length; ix++)
                                            {
                                                CommandGroup CG = Command[ix];
                                                CG.AssignedMethod = MI;

                                                if (Cmds.ContainsKey(CG.Command.ToLower()) == false)
                                                {
                                                    Log.info(true, "DISCOVER: " + CG.Command);
                                                    Cmds.Add(CG.Command.ToLower(), CG);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                Log.info(log: "Discovered " + Cmds.Count.ToString() + " total commands");
            }
            catch (ReflectionTypeLoadException e)
            {
                MessageFactory.Post(Destinations.DEST_LOCAL, "FAILURE!!!\n\n[Assembly load failure]", UUID.Zero);
                foreach (Exception X in e.LoaderExceptions)
                {
                    MessageFactory.Post(Destinations.DEST_LOCAL, X.Message + "\n \nSTACK: " + X.StackTrace, UUID.Zero);
                }
            }
        }
Ejemplo n.º 3
0
        public static Dictionary <string, List <RoleAttribute> > GetAllAction()
        {
            //action 列表
            Dictionary <string, List <RoleAttribute> > ActionList = new Dictionary <string, List <RoleAttribute> >();

            SiteInfo m_SiteInfo = DealMvc.WebCacheHelper.GetSiteInfo();

            if (!m_SiteInfo.WebCompetence)
            {
                return(ActionList);
            }

            try
            {
                //要进行反射的DLL
                string[] S_Ref_Dll = DealMvc.Common.Config.ConfigInfo <DealMvc.Common.Config.RoleDLLInfo> .Instance().path.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); //new string[] { "~/bin/DealMvc.dll" };

                //遍历DLL文件
                foreach (string S_Dll in S_Ref_Dll)
                {
                    //获得DLL里的类型
                    Type[] ActionType = Assembly.LoadFile(System.Web.HttpContext.Current.Server.MapPath(S_Dll)).GetTypes();

                    //遍历DLL里的类型
                    foreach (Type Action_Ref in ActionType)
                    {
                        //获取类上的描述信息
                        object[] ClassObj = Action_Ref.GetCustomAttributes(typeof(ControlInfoAttribute), false);

                        if (ClassObj.Length < 1)
                        {
                            continue;
                        }

                        ControlInfoAttribute ClassObjAttr = ClassObj[0] as ControlInfoAttribute;


                        //获得类Action的Name属性
                        List <RoleAttribute> Type_Action_Lit = new List <RoleAttribute>();

                        //遍历Action
                        foreach (MethodInfo MI in Action_Ref.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                        {
                            object[] ActionObj = MI.GetCustomAttributes(typeof(RoleAttribute), false);

                            if (ActionObj.Length < 1)
                            {
                                continue;
                            }

                            RoleAttribute ActionRoleAttr = ActionObj[0] as RoleAttribute;

                            if (ActionRoleAttr.IsAuthorize)
                            {
                                //给Action Url赋值
                                ActionRoleAttr.ActionUrl = string.Format("{0}/{1}", Action_Ref.Name.Replace("Controller", ""), MI.Name);

                                Type_Action_Lit.Add(ActionRoleAttr);
                            }
                        }

                        //将类信息加到返回集里
                        ActionList.Add(ClassObjAttr.Name, Type_Action_Lit);
                    }
                }
            }
            catch
            {
                ExceptionEx.MyExceptionLog.AddLogError("反射权限dll出错");
            }

            return(ActionList);
        }
Ejemplo n.º 4
0
        public WebhookRegistry.HTTPResponseData showHelp(List <string> arguments, string body, string method, NameValueCollection headers)
        {
            WebhookRegistry.HTTPResponseData httpReply = new WebhookRegistry.HTTPResponseData();
            CommandRegistry reg = CommandRegistry.Instance;

            string Final = "<body bgcolor='black'><style type='text/css'>table.HelpTable {  border: 5px solid #1C6EA4;" +
                           "  background - color: #000000; " +
                           "  width: 100 %;            text - align: left;            border - collapse: collapse;" +
                           "        }        table.HelpTable td, table.HelpTable th        {            border: 3px solid #AAAAAA;" +
                           "  padding: 3px 2px;        }        table.HelpTable tbody td {  font-size: 19px;  color: #69FAF7;" +
                           "}    table.HelpTable tr:nth-child(even)    {    background: #000000;}    table.HelpTable thead" +
                           "    {        background: #26A486;  background: -moz-linear-gradient(top, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
                           "  background: -webkit-linear-gradient(top, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
                           "  background: linear-gradient(to bottom, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
                           "  border-bottom: 2px solid #444444;}    table.HelpTable thead th {  font-size: 25px;" +
                           "  font-weight: bold;  color: #FFFFFF;  text-align: center;  border-left: 2px solid #D0E4F5;" +
                           "}table.HelpTable thead th:first-child {  border-left: none;}table.HelpTable tfoot td {  font-size: 14px;" +
                           "}table.HelpTable tfoot.links{    text-align: right;}table.HelpTable tfoot.links a{display: inline - block;" +
                           "background: #1C6EA4;  color: #FFFFFF;  padding: 2px 8px;    border - radius: 5px;}</style>";

            Final += "<table class='HelpTable'><thead><tr><th>Bot Version</th><th>" + ASMInfo.BotVer + "</th></tr></table><br/>";

            Final += "<table class='HelpTable'><thead><tr><th>Command</th><th>Minimum Level Required</th><th>Usage</th><th>Allowed Sources</th></thead><tbody>";
            foreach (KeyValuePair <string, CommandGroup> cmd in reg.Cmds)
            {
                // Command
                Final += "<tr><td>" + cmd.Value.Command + "</td>";
                // Level
                Final += "<td>" + cmd.Value.minLevel.ToString() + "</td>";
                // Usage
                Final += "<td>" + cmd.Value.cmdUsage.RawUsage() + "</td>";
                // Allowed Sources
                Final += "<td>" + cmd.Value.CommandSource + "</td>";
            }
            Final += "</tbody></table>";

            Final += "<table class='HelpTable'><thead><tr><th>Hook Path</th><tr></thead><tbody>";
            WebhookRegistry regx = WebhookRegistry.Instance;

            foreach (KeyValuePair <string, WebhookAttribs> hooks in regx.hooks)
            {
                Final += "<tr><td>" + hooks.Value.Path + "</td></tr>";
            }
            Final += "</tbody></table>";

            Final += "<br/><table class='HelpTable'><thead><tr><th>Assembly</th><th>Version</th><th># Of Commands</th><th>Total Classes</th></tr></thead><tbody>";

            foreach (Assembly A in AppDomain.CurrentDomain.GetAssemblies())
            {
                Final += "<tr><td>" + A.GetName().Name + "</td><td>" + A.GetName().Version + "</td>";
                int TotalCommandsContained = 0;
                int TotalClasses           = 0;
                foreach (Type T in A.GetTypes())
                {
                    if (T.IsClass)
                    {
                        TotalClasses++;
                        foreach (MethodInfo MI in T.GetMethods())
                        {
                            CommandGroup[] CG = (CommandGroup[])MI.GetCustomAttributes(typeof(CommandGroup), false);
                            TotalCommandsContained += CG.Length;
                        }
                    }
                }

                Final += "<td>" + TotalCommandsContained.ToString() + "</td><td>" + TotalClasses.ToString() + "</td></tr>";
            }
            Final += "</tbody></table>";


            httpReply.ReplyString       = Final;
            httpReply.Status            = 200;
            httpReply.ReturnContentType = "text/html";

            return(httpReply);
        }