/// <summary>
        /// Condition on the cmdlet that must be satisfied for the error to be raised
        /// </summary>
        /// <param name="CmdAst"></param>
        /// <returns></returns>
        public override bool CommandCondition(CommandAst CmdAst)
        {
            if (CTSTCmdlet == null)
            {
                CTSTCmdlet = Helper.Instance.CmdletNameAndAliases("convertto-securestring");
            }

            return CmdAst != null && CmdAst.GetCommandName() != null && CTSTCmdlet.Contains(CmdAst.GetCommandName(), StringComparer.OrdinalIgnoreCase);
        }
Example #2
0
        internal bool IsInWorkflow()
        {
            Ast  parent = this;
            bool flag   = false;

            while ((parent != null) && !flag)
            {
                ScriptBlockAst ast2 = parent as ScriptBlockAst;
                if (ast2 != null)
                {
                    FunctionDefinitionAst ast3 = ast2.Parent as FunctionDefinitionAst;
                    if (ast3 != null)
                    {
                        flag = true;
                        if (ast3.IsWorkflow)
                        {
                            return(true);
                        }
                    }
                }
                CommandAst ast4 = parent as CommandAst;
                if (((ast4 != null) && string.Equals(TokenKind.InlineScript.Text(), ast4.GetCommandName(), StringComparison.OrdinalIgnoreCase)) && (this != ast4))
                {
                    return(false);
                }
                parent = parent.Parent;
            }
            return(false);
        }
        public override AstVisitAction VisitCommand(CommandAst commandAst)
        {
            string commandName;

            if (commandAst.InvocationOperator == TokenKind.Dot)
            {
                this.ReportError(commandAst, () => ParserStrings.DotSourcingNotSupportedInDataSection, new object[0]);
                return(AstVisitAction.Continue);
            }
            if (this._allowedCommands != null)
            {
                commandName = commandAst.GetCommandName();
                if (commandName == null)
                {
                    if (commandAst.InvocationOperator == TokenKind.Ampersand)
                    {
                        this.ReportError(commandAst, () => ParserStrings.OperatorNotSupportedInDataSection, new object[] { TokenKind.Ampersand.Text() });
                    }
                    else
                    {
                        this.ReportError(commandAst, () => ParserStrings.CmdletNotInAllowedListForDataSection, new object[] { commandAst.Extent.Text });
                    }
                    return(AstVisitAction.Continue);
                }
                if (!(from allowedCommand in this._allowedCommands
                      where allowedCommand.Equals(commandName, StringComparison.OrdinalIgnoreCase)
                      select allowedCommand).Any <string>())
                {
                    this.ReportError(commandAst, () => ParserStrings.CmdletNotInAllowedListForDataSection, new object[] { commandName });
                }
            }
            return(AstVisitAction.Continue);
        }
        /// <summary>
        /// Retrieves the error message
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="CmdAst"></param>
        /// <returns></returns>
        public override string GetError(string FileName, CommandAst CmdAst)
        {
            if (CmdAst == null)
            {
                return string.Empty;
            }

            return string.Format(CultureInfo.CurrentCulture, Strings.AvoidComputerNameHardcodedError, CmdAst.GetCommandName());
        }
        /// <summary>
        /// Checks that write-host command is not used
        /// </summary>
        /// <param name="cmdAst"></param>
        /// <returns></returns>
        public override AstVisitAction VisitCommand(CommandAst cmdAst)
        {
            if (cmdAst == null)
            {
                return AstVisitAction.SkipChildren;
            }

            if (cmdAst.GetCommandName() != null && String.Equals(cmdAst.GetCommandName(), "write-host", StringComparison.OrdinalIgnoreCase))
            {
                if (String.IsNullOrWhiteSpace(fileName))
                {
                    records.Add(new DiagnosticRecord(String.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingWriteHostErrorScriptDefinition),
                        cmdAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName));
                }
                else
                {
                    records.Add(new DiagnosticRecord(String.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingWriteHostError,
                        System.IO.Path.GetFileName(fileName)), cmdAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName));
                }
            }

            return AstVisitAction.Continue;
        }
        private static FunctionDefinitionAst FindDefinition(CommandAst ast, Ast parentAst)
        {
            if (ast == null) throw new ArgumentNullException("ast");
            if (parentAst == null) return null;

            var definitions = parentAst.FindAll(
                m => m is FunctionDefinitionAst && ((FunctionDefinitionAst) m).Name.Equals(ast.GetCommandName()), false).ToList();

            if (definitions.Any())
            {
                return definitions.Last() as FunctionDefinitionAst;
            }

            return FindDefinition(ast, parentAst.Parent);
        }
Example #7
0
        Command GetCommand(CommandAst commandAst)
        {
            if (commandAst.CommandElements.First() is ScriptBlockExpressionAst)
            {
                var scriptBlockAst = (commandAst.CommandElements.First() as ScriptBlockExpressionAst).ScriptBlock;
                return new Command(scriptBlockAst);
            }

            else
            {
                return new Command(commandAst.GetCommandName());
            }
        }
        /// <summary>
        /// Return true if mandatory parameters are used OR the cmdlet does not exist
        /// </summary>
        /// <param name="cmdAst"></param>
        /// <returns></returns>
        private bool IsMandatoryParameterExisted(CommandAst cmdAst)
        {
            CommandInfo cmdInfo = null;
            List<ParameterMetadata> mandParams = new List<ParameterMetadata>();
            IEnumerable<CommandElementAst> ceAsts = null;
            bool returnValue = false;

            #region Predicates

            // Predicate to find ParameterAsts.
            Func<CommandElementAst, bool> foundParamASTs = delegate(CommandElementAst ceAst)
            {
                if (ceAst is CommandParameterAst) return true;
                return false;
            };

            #endregion

            #region Compares parameter list and mandatory parameter list.

            cmdInfo = Helper.Instance.GetCommandInfo(Helper.Instance.GetCmdletNameFromAlias(cmdAst.GetCommandName()))
                ?? Helper.Instance.GetCommandInfo(cmdAst.GetCommandName());

            if (cmdInfo == null || (cmdInfo.CommandType != System.Management.Automation.CommandTypes.Cmdlet))
            {
                return true;
            }

            // ignores if splatted variable is used
            if (Helper.Instance.HasSplattedVariable(cmdAst))
            {
                return true;
            }

            // Gets parameters from command elements.
            ceAsts = cmdAst.CommandElements.Where<CommandElementAst>(foundParamASTs);

            // Gets mandatory parameters from cmdlet.
            // If cannot find any mandatory parameter, it's not necessary to do a further check for current cmdlet.
            try
            {
                int noOfParamSets = cmdInfo.ParameterSets.Count; 
                foreach (ParameterMetadata pm in cmdInfo.Parameters.Values)
                {
                    int count = 0;

                    if (pm.Attributes.Count < noOfParamSets)
                    {
                        continue;
                    }

                    foreach (Attribute attr in pm.Attributes)
                    {
                        if (!(attr is ParameterAttribute)) continue;
                        if (((ParameterAttribute)attr).Mandatory)
                        {
                            count += 1;
                        }
                    }

                    if (count >= noOfParamSets)
                    {
                        mandParams.Add(pm);
                    }
                }
            }
            catch (Exception)
            {
                // For cases like cmd.exe. Also for runtime exception
                return true;
            }

            if (mandParams.Count() == 0 || Helper.Instance.PositionalParameterUsed(cmdAst))
            {
                returnValue = true;
            }
            else
            {
                // Compares parameter list and mandatory parameter list.
                foreach (CommandElementAst ceAst in ceAsts)
                {
                    CommandParameterAst cpAst = (CommandParameterAst)ceAst;
                    if (mandParams.Count<ParameterMetadata>(item =>
                        item.Name.Equals(cpAst.ParameterName, StringComparison.OrdinalIgnoreCase)) > 0)
                    {
                        returnValue = true;
                        break;
                    }
                }
            }

            #endregion

            return returnValue;
        }
        /// <summary>
        /// Visit command
        /// </summary>
        /// <param name="commandAst"></param>
        /// <returns></returns>
        public object VisitCommand(CommandAst commandAst)
        {
            if (commandAst == null) return null;

            //Add the check for Tee-Object -Variable var 
            if (string.Equals(commandAst.GetCommandName(), "Tee-Object", StringComparison.OrdinalIgnoreCase))
            {
                foreach (CommandElementAst ceAst in commandAst.CommandElements)
                {
                    if (ceAst is CommandParameterAst)
                    {
                        string paramName = (ceAst as CommandParameterAst).ParameterName;
                        if (string.Equals(paramName, "Variable", StringComparison.OrdinalIgnoreCase))
                        {
                            int index = commandAst.CommandElements.IndexOf(ceAst);
                            if (commandAst.CommandElements.Count > (index + 1))
                            {
                                CommandElementAst paramConstant = commandAst.CommandElements[index + 1];
                                if (paramConstant is StringConstantExpressionAst)
                                {
                                    //If common parameters are used, create a variable target and store the variable value
                                    _currentBlock.AddAst(new AssignmentTarget((paramConstant as StringConstantExpressionAst).Value, typeof(string)));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (CommandElementAst ceAst in commandAst.CommandElements)
                {
                    if (ceAst is CommandParameterAst)
                    {
                        string paramName = (ceAst as CommandParameterAst).ParameterName;
                        if (string.Equals(paramName, "ErrorVariable", StringComparison.OrdinalIgnoreCase)
                             || string.Equals(paramName, "WarningVariable", StringComparison.OrdinalIgnoreCase)
                            || string.Equals(paramName, "PipelineVariable ", StringComparison.OrdinalIgnoreCase)
                            || string.Equals(paramName, "OutVariable", StringComparison.OrdinalIgnoreCase))
                        {
                            int index = commandAst.CommandElements.IndexOf(ceAst);
                            if (commandAst.CommandElements.Count > (index + 1))
                            {
                                CommandElementAst paramConstant = commandAst.CommandElements[index + 1];
                                if (paramConstant is StringConstantExpressionAst)
                                {
                                    //If common parameters are used, create a variable target and store the variable value
                                    _currentBlock.AddAst(new AssignmentTarget((paramConstant as StringConstantExpressionAst).Value, typeof(string)));
                                }
                            }
                        }
                    }
                    ceAst.Visit(this.Decorator);
                }
            }
            return null;
        }
 public override AstVisitAction VisitCommand(CommandAst commandAst)
 {
     string commandName;
     if (commandAst.InvocationOperator == TokenKind.Dot)
     {
         this.ReportError(commandAst, () => ParserStrings.DotSourcingNotSupportedInDataSection, new object[0]);
         return AstVisitAction.Continue;
     }
     if (this._allowedCommands != null)
     {
         commandName = commandAst.GetCommandName();
         if (commandName == null)
         {
             if (commandAst.InvocationOperator == TokenKind.Ampersand)
             {
                 this.ReportError(commandAst, () => ParserStrings.OperatorNotSupportedInDataSection, new object[] { TokenKind.Ampersand.Text() });
             }
             else
             {
                 this.ReportError(commandAst, () => ParserStrings.CmdletNotInAllowedListForDataSection, new object[] { commandAst.Extent.Text });
             }
             return AstVisitAction.Continue;
         }
         if (!(from allowedCommand in this._allowedCommands
             where allowedCommand.Equals(commandName, StringComparison.OrdinalIgnoreCase)
             select allowedCommand).Any<string>())
         {
             this.ReportError(commandAst, () => ParserStrings.CmdletNotInAllowedListForDataSection, new object[] { commandName });
         }
     }
     return AstVisitAction.Continue;
 }
        /// <summary>
        /// Visit CommandAst. Skip if name of command is in
        /// namestobeskipped
        /// </summary>
        /// <param name="commandAst"></param>
        /// <returns></returns>
        public override AstVisitAction VisitCommand(CommandAst commandAst)
        {
            if (commandAst == null || commandAst.GetCommandName() == null)
            {
                return AstVisitAction.SkipChildren;
            }

            if (commandAst.CommandElements != null && commandAst.CommandElements.Count > 0)
            {
                var firstCommand = commandAst.CommandElements[0];
                if (NamesToBeSkipped.Contains(firstCommand.Extent.Text, StringComparer.OrdinalIgnoreCase))
                {
                    return AstVisitAction.SkipChildren;
                }
            }

            return AstVisitAction.Continue;
        }
Example #12
0
 Command GetCommand(CommandAst commandAst)
 {
     return new Command(commandAst.GetCommandName());
 }
Example #13
0
        public override AstVisitAction VisitCommand(CommandAst commandAst)
        {
            // Commands are allowed if arguments are allowed, no redirection, no dotting

            // If _allowedCommands is null, any command is allowed, otherwise
            // we must check the command name.

            if (commandAst.InvocationOperator == TokenKind.Dot)
            {
                ReportError(commandAst, () => ParserStrings.DotSourcingNotSupportedInDataSection);
                return AstVisitAction.Continue;
            }

            if (_allowedCommands == null)
                return AstVisitAction.Continue;

            string commandName = commandAst.GetCommandName();
            if (commandName == null)
            {
                if (commandAst.InvocationOperator == TokenKind.Ampersand)
                {
                    ReportError(commandAst, () => ParserStrings.OperatorNotSupportedInDataSection,
                                TokenKind.Ampersand.Text());
                }
                else
                {
                    ReportError(commandAst, () => ParserStrings.CmdletNotInAllowedListForDataSection, commandAst.Extent.Text);
                }
                return AstVisitAction.Continue;
            }

            if (_allowedCommands.Any(allowedCommand => allowedCommand.Equals(commandName, StringComparison.OrdinalIgnoreCase)))
            {
                return AstVisitAction.Continue;
            }

            ReportError(commandAst, () => ParserStrings.CmdletNotInAllowedListForDataSection, commandName);

            return AstVisitAction.Continue;
        }
Example #14
0
        // Visit one the other variations:
        //  - Dotting scripts
        //  - Setting aliases
        //  - Importing modules
        //  - Exporting module members
        public override AstVisitAction VisitCommand(CommandAst commandAst)
        {
            string commandName =
                commandAst.GetCommandName() ??
                GetSafeValueVisitor.GetSafeValue(commandAst.CommandElements[0], null, GetSafeValueVisitor.SafeValueContext.ModuleAnalysis) as string;

            if (commandName == null)
                return AstVisitAction.SkipChildren;

            // They are trying to dot a script
            if (commandAst.InvocationOperator == TokenKind.Dot)
            {
                // . Foo-Bar4.ps1
                // . $psScriptRoot\Foo-Bar.ps1 -Bing Baz
                // . ""$psScriptRoot\Support Files\Foo-Bar2.ps1"" -Bing Baz
                // . '$psScriptRoot\Support Files\Foo-Bar3.ps1' -Bing Baz

                DiscoveredModules.Add(
                    new RequiredModuleInfo { Name = commandName, CommandsToPostFilter = new List<string>() });
                ModuleIntrinsics.Tracer.WriteLine("Module dots {0}", commandName);
            }

            // They are setting an alias.
            if (String.Equals(commandName, "New-Alias", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(commandName, "Microsoft.PowerShell.Utility\\New-Alias", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(commandName, "Set-Alias", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(commandName, "Microsoft.PowerShell.Utility\\Set-Alias", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(commandName, "nal", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(commandName, "sal", StringComparison.OrdinalIgnoreCase))
            {
                // Set-Alias Foo-Bar5 Foo-Bar
                // Set-Alias -Name Foo-Bar6 -Value Foo-Bar
                // sal Foo-Bar7 Foo-Bar
                // sal -Value Foo-Bar -Name Foo-Bar8

                var boundParameters = DoPsuedoParameterBinding(commandAst, commandName);

                var name = boundParameters["Name"] as string;
                if (!string.IsNullOrEmpty(name))
                {
                    var value = boundParameters["Value"] as string;
                    if (!string.IsNullOrEmpty(value))
                    {
                        // These aren't stored in DiscoveredExports, as they are only
                        // exported after the user calls Export-ModuleMember.
                        DiscoveredAliases[name] = value;
                        ModuleIntrinsics.Tracer.WriteLine("Module defines alias: {0} = {1}", name, value);
                    }
                }

                return AstVisitAction.SkipChildren;
            }

            // They are importing a module
            if (String.Equals(commandName, "Import-Module", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(commandName, "ipmo", StringComparison.OrdinalIgnoreCase))
            {
                // Import-Module Module1
                // Import-Module Module2 -Function Foo-Module2*, Foo-Module2Second* -Cmdlet Foo-Module2Cmdlet,Foo-Module2Cmdlet*
                // Import-Module Module3 -Function Foo-Module3Command1, Foo-Module3Command2
                // Import-Module Module4,
                //    Module5
                // Import-Module -Name Module6,
                //    Module7 -Global

                var boundParameters = DoPsuedoParameterBinding(commandAst, commandName);

                List<string> commandsToPostFilter = new List<string>();

                Action<string> onEachCommand = importedCommandName =>
                {
                    commandsToPostFilter.Add(importedCommandName);
                };

                // Process any exports from the module that we determine from
                // the -Function, -Cmdlet, or -Alias parameters
                ProcessCmdletArguments(boundParameters["Function"], onEachCommand);
                ProcessCmdletArguments(boundParameters["Cmdlet"], onEachCommand);
                ProcessCmdletArguments(boundParameters["Alias"], onEachCommand);

                // Now, go through all of the discovered modules on Import-Module
                // and register them for deeper investigation.
                Action<string> onEachModule = moduleName =>
                {
                    ModuleIntrinsics.Tracer.WriteLine("Discovered module import: {0}", moduleName);
                    DiscoveredModules.Add(
                        new RequiredModuleInfo
                        {
                            Name = moduleName,
                            CommandsToPostFilter = commandsToPostFilter
                        });
                };
                ProcessCmdletArguments(boundParameters["Name"], onEachModule);

                return AstVisitAction.SkipChildren;
            }

            // They are exporting a module member
            if (String.Equals(commandName, "Export-ModuleMember", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(commandName, "Microsoft.PowerShell.Core\\Export-ModuleMember", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(commandName, "$script:ExportModuleMember", StringComparison.OrdinalIgnoreCase))
            {
                // Export-ModuleMember *
                // Export-ModuleMember Exported-UnNamedModuleMember
                // Export-ModuleMember -Function Exported-FunctionModuleMember1, Exported-FunctionModuleMember2 -Cmdlet Exported-CmdletModuleMember `
                //    -Alias Exported-AliasModuleMember
                // & $script:ExportModuleMember -Function (...)

                var boundParameters = DoPsuedoParameterBinding(commandAst, commandName);

                Action<string> onEachFunction = exportedCommandName =>
                {
                    DiscoveredCommandFilters.Add(exportedCommandName);
                    ModuleIntrinsics.Tracer.WriteLine("Discovered explicit export: {0}", exportedCommandName);

                    // If the export doesn't contain wildcards, then add it to the
                    // discovered commands as well. It is likely that they created
                    // the command dynamically
                    if ((!WildcardPattern.ContainsWildcardCharacters(exportedCommandName)) &&
                        (!DiscoveredExports.Contains(exportedCommandName)))
                    {
                        DiscoveredExports.Add(exportedCommandName);
                    }
                };
                ProcessCmdletArguments(boundParameters["Function"], onEachFunction);
                ProcessCmdletArguments(boundParameters["Cmdlet"], onEachFunction);

                Action<string> onEachAlias = exportedAlias =>
                {
                    DiscoveredCommandFilters.Add(exportedAlias);

                    // If the export doesn't contain wildcards, then add it to the
                    // discovered commands as well. It is likely that they created
                    // the command dynamically
                    if (!WildcardPattern.ContainsWildcardCharacters(exportedAlias))
                    {
                        DiscoveredAliases[exportedAlias] = null;
                    }
                };
                ProcessCmdletArguments(boundParameters["Alias"], onEachAlias);

                return AstVisitAction.SkipChildren;
            }

            // They are exporting a module member using our advanced 'public' function
            // that we've presented in many demos
            if ((String.Equals(commandName, "public", StringComparison.OrdinalIgnoreCase)) &&
                (commandAst.CommandElements.Count > 2))
            {
                // public function Publicly-ExportedFunction
                // public alias Publicly-ExportedAlias
                string publicCommandName = commandAst.CommandElements[2].ToString().Trim();
                DiscoveredExports.Add(publicCommandName);
                DiscoveredCommandFilters.Add(publicCommandName);
            }

            return AstVisitAction.SkipChildren;
        }
Example #15
0
            public override AstVisitAction VisitCommand(CommandAst commandAst)
            {
                var commandName = commandAst.GetCommandName();
                if (commandName != null)
                {
                    if (_singleton._engineIntrinsics != null)
                    {
                        var commandInfo = _singleton._engineIntrinsics.InvokeCommand.GetCommand(commandName, CommandTypes.All);
                        if (commandInfo == null && !_singleton.UnresolvedCommandCouldSucceed(commandName, _rootAst))
                        {
                            _singleton._current = commandAst.CommandElements[0].Extent.EndOffset;
                            detectedError = string.Format(CultureInfo.CurrentCulture, PSReadLineResources.CommandNotFoundError, commandName);
                            return AstVisitAction.StopVisit;
                        }
                    }

                    if (commandAst.CommandElements.Any(e => e is ScriptBlockExpressionAst))
                    {
                        if (_singleton._options.CommandsToValidateScriptBlockArguments == null ||
                            !_singleton._options.CommandsToValidateScriptBlockArguments.Contains(commandName))
                        {
                            return AstVisitAction.SkipChildren;
                        }
                    }
                }

                if (_singleton._options.CommandValidationHandler != null)
                {
                    try
                    {
                        _singleton._options.CommandValidationHandler(commandAst);
                    }
                    catch (Exception e)
                    {
                        detectedError = e.Message;
                    }
                }

                return !string.IsNullOrWhiteSpace(detectedError)
                    ? AstVisitAction.StopVisit
                    : AstVisitAction.Continue;
            }
Example #16
0
 /// <summary>
 /// Creates a list containing suggested correction
 /// </summary>
 /// <param name="cmdAst">Command AST of an alias</param>
 /// <param name="cmdletName">Full name of the alias</param>
 /// <returns>Retruns a list of suggested corrections</returns>
 private List<CorrectionExtent> GetCorrectionExtent(CommandAst cmdAst, string cmdletName)
 {
     var ext = cmdAst.Extent;
     if (ext.File == null)
     {
         return null;
     }
     var corrections = new List<CorrectionExtent>();
     var alias = cmdAst.GetCommandName();
     string description = string.Format(
         CultureInfo.CurrentCulture,
         Strings.AvoidUsingCmdletAliasesCorrectionDescription,
         alias,
         cmdletName);
     corrections.Add(new CorrectionExtent(
         ext.StartLineNumber,
         ext.EndLineNumber,
         cmdAst.CommandElements[0].Extent.StartColumnNumber,
         cmdAst.CommandElements[0].Extent.EndColumnNumber,
         cmdletName,
         ext.File,
         description));
     return corrections;
 }
Example #17
0
 public override AstVisitAction VisitCommand(CommandAst commandAst)
 {
     string commandName = commandAst.GetCommandName();
     if (string.IsNullOrEmpty(commandName))
     {
         commandName = commandAst.CommandElements[0].ToString().Trim(new char[] { '"', '\'' });
     }
     if (commandAst.InvocationOperator == TokenKind.Dot)
     {
         commandName = Regex.Replace(commandName, @"\$[^\\]*\\", "", RegexOptions.IgnoreCase);
         RequiredModuleInfo item = new RequiredModuleInfo {
             Name = commandName,
             CommandsToPostFilter = new List<string>()
         };
         this.DiscoveredModules.Add(item);
         ModuleIntrinsics.Tracer.WriteLine("Module dots " + commandName, new object[0]);
     }
     if (((string.Equals(commandName, "New-Alias", StringComparison.OrdinalIgnoreCase) || string.Equals(commandName, @"Microsoft.PowerShell.Utility\New-Alias", StringComparison.OrdinalIgnoreCase)) || (string.Equals(commandName, "Set-Alias", StringComparison.OrdinalIgnoreCase) || string.Equals(commandName, @"Microsoft.PowerShell.Utility\Set-Alias", StringComparison.OrdinalIgnoreCase))) || (string.Equals(commandName, "nal", StringComparison.OrdinalIgnoreCase) || string.Equals(commandName, "sal", StringComparison.OrdinalIgnoreCase)))
     {
         string str2 = this.GetParameterByNameOrPosition("Name", 0, commandAst);
         string str3 = this.GetParameterByNameOrPosition("Value", 1, commandAst);
         if (!string.IsNullOrEmpty(str2))
         {
             this.DiscoveredAliases[str2] = str3;
             ModuleIntrinsics.Tracer.WriteLine("Module defines alias: " + str2 + "=" + str3, new object[0]);
         }
     }
     if (string.Equals(commandName, "Import-Module", StringComparison.OrdinalIgnoreCase) || string.Equals(commandName, "ipmo", StringComparison.OrdinalIgnoreCase))
     {
         List<string> list = new List<string>();
         string str4 = this.GetParameterByNameOrPosition("Function", -1, commandAst);
         if (!string.IsNullOrEmpty(str4))
         {
             list.AddRange(this.ProcessExportedCommandList(str4));
         }
         string str5 = this.GetParameterByNameOrPosition("Cmdlet", -1, commandAst);
         if (!string.IsNullOrEmpty(str5))
         {
             list.AddRange(this.ProcessExportedCommandList(str5));
         }
         string str6 = this.GetParameterByNameOrPosition("Alias", -1, commandAst);
         if (!string.IsNullOrEmpty(str6))
         {
             list.AddRange(this.ProcessExportedCommandList(str6));
         }
         string str7 = this.GetParameterByNameOrPosition("Name", 0, commandAst);
         if (!string.IsNullOrEmpty(str7))
         {
             foreach (string str8 in str7.Split(new char[] { ',' }))
             {
                 ModuleIntrinsics.Tracer.WriteLine("Discovered module import: " + str8, new object[0]);
                 RequiredModuleInfo info2 = new RequiredModuleInfo {
                     Name = str8.Trim(),
                     CommandsToPostFilter = list
                 };
                 this.DiscoveredModules.Add(info2);
             }
         }
     }
     if ((string.Equals(commandName, "Export-ModuleMember", StringComparison.OrdinalIgnoreCase) || string.Equals(commandName, @"Microsoft.PowerShell.Core\Export-ModuleMember", StringComparison.OrdinalIgnoreCase)) || string.Equals(commandName, "$script:ExportModuleMember", StringComparison.OrdinalIgnoreCase))
     {
         List<string> list2 = new List<string>();
         string arguments = this.GetParameterByNameOrPosition("Function", 0, commandAst);
         list2.AddRange(this.ExtractArgumentList(arguments));
         string str10 = this.GetParameterByNameOrPosition("Cmdlet", -1, commandAst);
         list2.AddRange(this.ExtractArgumentList(str10));
         foreach (string str11 in list2)
         {
             this.DiscoveredCommandFilters.Add(str11);
             ModuleIntrinsics.Tracer.WriteLine("Discovered explicit export: " + str11, new object[0]);
             if (!WildcardPattern.ContainsWildcardCharacters(str11) && !this.DiscoveredExports.Contains(str11))
             {
                 this.DiscoveredExports.Add(str11);
             }
         }
         list2 = new List<string>();
         string str12 = this.GetParameterByNameOrPosition("Alias", -1, commandAst);
         list2.AddRange(this.ExtractArgumentList(str12));
         foreach (string str13 in list2)
         {
             this.DiscoveredCommandFilters.Add(str13);
             if (!WildcardPattern.ContainsWildcardCharacters(str13) && !this.DiscoveredAliases.ContainsKey(str13))
             {
                 this.DiscoveredAliases.Add(str13, null);
             }
         }
     }
     if (string.Equals(commandName, "public", StringComparison.OrdinalIgnoreCase) && (commandAst.CommandElements.Count > 2))
     {
         string str14 = commandAst.CommandElements[2].ToString().Trim();
         this.DiscoveredExports.Add(str14);
         this.DiscoveredCommandFilters.Add(str14);
     }
     return AstVisitAction.Continue;
 }