Example #1
0
        // This function splits text on the command line up and identifies each component
        static List <DisplayCmdComponent> dislayCmdComponents(AttackState attackState)
        {
            List <DisplayCmdComponent> results = new List <DisplayCmdComponent>();

            String[] displayCmdItemList = Regex.Split(attackState.displayCmd, @"(?=[\s])");
            int      index     = 0;
            int      cmdLength = attackState.promptLength + 1;

            foreach (string item in displayCmdItemList)
            {
                string itemType = seedIdentification(item);
                DisplayCmdComponent itemSeed = new DisplayCmdComponent();
                itemSeed.Index    = index;
                itemSeed.Contents = item;
                itemSeed.Type     = itemType;
                cmdLength        += item.Length;
                if ((cmdLength > attackState.cursorPos) && (attackState.cmdComponentsIndex == -1))
                {
                    attackState.cmdComponentsIndex = index;
                }
                if (itemType == "path" || itemType == "unknown")
                {
                    if (results.Last().Type == "path")
                    {
                        results.Last().Contents += itemSeed.Contents;
                    }
                    else
                    {
                        results.Add(itemSeed);
                        index++;
                    }
                }
                else
                {
                    results.Add(itemSeed);
                    index++;
                }
            }
            return(results);
        }
Example #2
0
        public static AttackState Process(AttackState attackState)
        {
            if (attackState.loopType == null)
            {
                attackState.cmdComponents = dislayCmdComponents(attackState);

                // route to appropriate autcomplete handler
                DisplayCmdComponent cmdSeed = attackState.cmdComponents[attackState.cmdComponentsIndex];
                attackState.loopType = cmdSeed.Type;
                switch (cmdSeed.Type)
                {
                case "param":
                    attackState = paramAutoComplete(attackState);
                    break;

                case "variable":
                    attackState = variableAutoComplete(attackState);
                    break;

                case "path":
                    attackState = pathAutoComplete(attackState);
                    break;

                default:
                    attackState = cmdAutoComplete(attackState);
                    break;
                }
            }

            // If we're already in an autocomplete loop, increment loopPos appropriately
            else if (attackState.loopType != null)
            {
                if (attackState.keyInfo.Modifiers == ConsoleModifiers.Shift)
                {
                    attackState.loopPos -= 1;
                    // loop around if we're at the beginning
                    if (attackState.loopPos < 0)
                    {
                        attackState.loopPos = attackState.results.Count - 1;
                    }
                }
                else
                {
                    attackState.loopPos += 1;
                    // loop around if we reach the end
                    if (attackState.loopPos >= attackState.results.Count)
                    {
                        attackState.loopPos = 0;
                    }
                }
            }

            // if we have results, format them and return them
            if (attackState.results.Count > 0)
            {
                string seperator = "";
                string result;
                switch (attackState.loopType)
                {
                case "param":
                    seperator = " -";
                    result    = attackState.results[attackState.loopPos].ToString();
                    break;

                case "variable":
                    seperator = " $";
                    result    = attackState.results[attackState.loopPos].Members["Name"].Value.ToString();
                    break;

                case "path":
                    seperator = " ";
                    result    = "\"" + attackState.results[attackState.loopPos].Members["FullName"].Value.ToString() + "\"";
                    break;

                default:
                    result = attackState.results[attackState.loopPos].BaseObject.ToString();
                    break;
                }
                // reconstruct display cmd from components
                string completedCmd = "";
                int    i            = 0;
                int    cursorPos    = attackState.promptLength;
                while (i < attackState.cmdComponents.Count())
                {
                    if (i == attackState.cmdComponentsIndex)
                    {
                        completedCmd += seperator + result;
                        cursorPos    += completedCmd.Length;
                    }
                    else
                    {
                        completedCmd += attackState.cmdComponents[i].Contents;
                    }
                    i++;
                }
                attackState.displayCmd = completedCmd;
                attackState.cursorPos  = cursorPos;
            }
            return(attackState);
        }
Example #3
0
        // This function splits text on the command line up and identifies each component
        static List<DisplayCmdComponent> dislayCmdComponents(AttackState attackState)
        {
            List<DisplayCmdComponent> results = new List<DisplayCmdComponent>();
            String[] displayCmdItemList = Regex.Split(attackState.displayCmd, @"(?=[\s])");
            int index = 0;
            int cmdLength = attackState.promptLength + 1;
            foreach (string item in displayCmdItemList)
            {
                string itemType = seedIdentification(item);
                DisplayCmdComponent itemSeed = new DisplayCmdComponent();
                itemSeed.Index = index;
                itemSeed.Contents = item;
                itemSeed.Type = itemType;
                cmdLength += item.Length;
                if ((cmdLength > attackState.cursorPos) && (attackState.cmdComponentsIndex == -1))
                {
                    attackState.cmdComponentsIndex = index;
                }
                if (itemType == "path" || itemType == "unknown")
                {
                    if (results.Last().Type == "path")
                    {
                        results.Last().Contents +=  itemSeed.Contents;

                    }
                    else
                    {
                        results.Add(itemSeed);
                        index++;
                    }
                }
                else
                {
                    results.Add(itemSeed);
                    index++;
                }
            }
            return results;
        }