internal static bool MoveNext(System.Management.Automation.ExecutionContext context, IScriptExtent errorPosition, IEnumerator enumerator) { bool flag; try { if ((context != null) && context.CurrentPipelineStopping) { throw new PipelineStoppedException(); } flag = enumerator.MoveNext(); } catch (RuntimeException) { throw; } catch (FlowControlException) { throw; } catch (ScriptCallDepthException) { throw; } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw InterpreterError.NewInterpreterExceptionWithInnerException(enumerator, typeof(RuntimeException), errorPosition, "BadEnumeration", ParserStrings.BadEnumeration, exception, new object[] { exception.Message }); } return(flag); }
internal static object Current(IScriptExtent errorPosition, IEnumerator enumerator) { object current; try { current = enumerator.Current; } catch (RuntimeException) { throw; } catch (ScriptCallDepthException) { throw; } catch (FlowControlException) { throw; } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw InterpreterError.NewInterpreterExceptionWithInnerException(enumerator, typeof(RuntimeException), errorPosition, "BadEnumeration", ParserStrings.BadEnumeration, exception, new object[] { exception.Message }); } return(current); }
private void DoSetValue(Array array, object index, object value) { if (index is IList list) { if (array.Rank != 1) { if (list.Count > 1) { if (!(list[0] is IList)) { goto label_5; } } else { goto label_5; } } throw InterpreterError.NewInterpreterException(index, typeof(RuntimeException), this.NodeToken, "ArraySliceAssignmentFailed", (object)ArrayReferenceNode.IndexStringMessage(index)); } label_5: try { this.SetArrayElement(array, index, value); } catch (IndexOutOfRangeException ex) { throw InterpreterError.NewInterpreterExceptionWithInnerException(index, typeof(RuntimeException), this.NodeToken, "IndexOutOfRange", (Exception)ex, (object)ArrayReferenceNode.IndexStringMessage(index)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); throw InterpreterError.NewInterpreterExceptionWithInnerException(value, typeof(RuntimeException), this.NodeToken, "ArrayAssignmentFailed", ex, (object)ArrayReferenceNode.IndexStringMessage(index), (object)ex.Message); } }
private PipelineProcessor BuildRedirectionPipeline( string path, ExecutionContext context) { CommandProcessorBase command = context.CreateCommand("out-file"); command.AddParameter("-encoding", (object)"unicode"); if (this.Appending) { command.AddParameter("-append", (object)true); } command.AddParameter("-filepath", (object)path); PipelineProcessor pipelineProcessor = new PipelineProcessor(); pipelineProcessor.Add(command); try { pipelineProcessor.StartStepping(true); } catch (RuntimeException ex) { if (ex.ErrorRecord.Exception is ArgumentException) { throw InterpreterError.NewInterpreterExceptionWithInnerException((object)null, typeof(RuntimeException), this._token, "RedirectionFailed", ex.ErrorRecord.Exception, (object)path, (object)ex.ErrorRecord.Exception.Message); } ex.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this._token, context)); throw ex; } return(pipelineProcessor); }
internal static RuntimeException NewInterpreterException( object targetObject, Type exceptionType, Token errToken, string resourceIdAndErrorId, params object[] args) { return(InterpreterError.NewInterpreterExceptionWithInnerException(targetObject, exceptionType, errToken, resourceIdAndErrorId, (Exception)null, args)); }
internal static bool ConditionSatisfiedRegex(bool caseSensitive, object condition, IScriptExtent errorPosition, string str, ExecutionContext context) { string str2; bool success; RegexOptions options = caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase; try { Match match; Regex regex = condition as Regex; if ((regex != null) && (((regex.Options & RegexOptions.IgnoreCase) != RegexOptions.None) != caseSensitive)) { match = regex.Match(str); } else { str2 = PSObject.ToStringParser(context, condition); match = Regex.Match(str, str2, options); if (match.Success && (match.Groups.Count > 0)) { regex = new Regex(str2, options); } } if (match.Success) { GroupCollection groups = match.Groups; if (groups.Count > 0) { Hashtable newValue = new Hashtable(StringComparer.CurrentCultureIgnoreCase); foreach (string str3 in regex.GetGroupNames()) { Group group = groups[str3]; if (group.Success) { int num; if (int.TryParse(str3, out num)) { newValue.Add(num, group.ToString()); } else { newValue.Add(str3, group.ToString()); } } } context.SetVariable(SpecialVariables.MatchesVarPath, newValue); } } success = match.Success; } catch (ArgumentException exception) { str2 = PSObject.ToStringParser(context, condition); throw InterpreterError.NewInterpreterExceptionWithInnerException(str2, typeof(RuntimeException), errorPosition, "InvalidRegularExpression", ParserStrings.InvalidRegularExpression, exception, new object[] { str2 }); } return(success); }
internal void ReportIndexingError(Array array, object index, Exception reason) { string str = ArrayReferenceNode.IndexStringMessage(index); if (reason == null) { throw InterpreterError.NewInterpreterException(index, typeof(RuntimeException), this.NodeToken, "NeedMultidimensionalIndex", (object)array.Rank, (object)str); } throw InterpreterError.NewInterpreterExceptionWithInnerException(index, typeof(RuntimeException), this.NodeToken, "NeedMultidimensionalIndex", reason, (object)array.Rank, (object)str); }
private static void ReportIndexingError(Array array, object index, Exception reason) { string str = IndexStringMessage(index); if (reason == null) { throw InterpreterError.NewInterpreterException(index, typeof(RuntimeException), null, "NeedMultidimensionalIndex", ParserStrings.NeedMultidimensionalIndex, new object[] { array.Rank, str }); } throw InterpreterError.NewInterpreterExceptionWithInnerException(index, typeof(RuntimeException), null, "NeedMultidimensionalIndex", ParserStrings.NeedMultidimensionalIndex, reason, new object[] { array.Rank, str }); }
private static void ReportIndexingError(Array array, object index, Exception reason) { // Convert this index into something printable (we hope)... string msgString = IndexStringMessage(index); if (reason == null) { throw InterpreterError.NewInterpreterException(index, typeof(RuntimeException), null, "NeedMultidimensionalIndex", ParserStrings.NeedMultidimensionalIndex, array.Rank, msgString); } throw InterpreterError.NewInterpreterExceptionWithInnerException(index, typeof(RuntimeException), null, "NeedMultidimensionalIndex", ParserStrings.NeedMultidimensionalIndex, reason, array.Rank, msgString); }
private void DoSetValue(IDictionary dictionary, object index, object value) { try { dictionary[index] = value; } catch (InvalidCastException ex) { throw InterpreterError.NewInterpreterExceptionWithInnerException(index, typeof(RuntimeException), this.NodeToken, "KeyTypeMismatch", (Exception)ex, (object)dictionary.GetType().Name, (object)index.GetType().Name); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); throw InterpreterError.NewInterpreterExceptionWithInnerException(index, typeof(RuntimeException), this.NodeToken, "ArrayAssignmentFailed", ex, index, (object)ex.Message); } }
internal Pipe GetRedirectionPipe(ExecutionContext context, System.Management.Automation.Internal.PipelineProcessor parentPipelineProcessor) { if (string.IsNullOrWhiteSpace(this.File)) { return(new Pipe { NullPipe = true }); } CommandProcessorBase commandProcessor = context.CreateCommand("out-file", false); CommandParameterInternal parameter = CommandParameterInternal.CreateParameterWithArgument(PositionUtilities.EmptyExtent, "Encoding", "-Encoding:", PositionUtilities.EmptyExtent, "Unicode", false); commandProcessor.AddParameter(parameter); if (this.Appending) { parameter = CommandParameterInternal.CreateParameterWithArgument(PositionUtilities.EmptyExtent, "Append", "-Append:", PositionUtilities.EmptyExtent, true, false); commandProcessor.AddParameter(parameter); } parameter = CommandParameterInternal.CreateParameterWithArgument(PositionUtilities.EmptyExtent, "Filepath", "-Filepath:", PositionUtilities.EmptyExtent, this.File, false); commandProcessor.AddParameter(parameter); this.PipelineProcessor = new System.Management.Automation.Internal.PipelineProcessor(); this.PipelineProcessor.Add(commandProcessor); try { this.PipelineProcessor.StartStepping(true); } catch (RuntimeException exception) { if (exception.ErrorRecord.Exception is ArgumentException) { throw InterpreterError.NewInterpreterExceptionWithInnerException(null, typeof(RuntimeException), null, "RedirectionFailed", ParserStrings.RedirectionFailed, exception.ErrorRecord.Exception, new object[] { this.File, exception.ErrorRecord.Exception.Message }); } throw; } if (parentPipelineProcessor != null) { parentPipelineProcessor.AddRedirectionPipe(this.PipelineProcessor); } return(new Pipe(context, this.PipelineProcessor)); }
private object GetItemPropertyValue(object obj, object index, ExecutionContext context) { IEnumerator enumerator = LanguagePrimitives.GetEnumerator(index); if (enumerator != null) { ArrayList arrayList = new ArrayList(); while (ParserOps.MoveNext(context, this.NodeToken, enumerator)) { try { object obj1 = this.GetItem(obj, enumerator.Current); arrayList.Add(obj1); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); if (this.IsMethodNotFoundException(ex)) { throw InterpreterError.NewInterpreterExceptionWithInnerException(index, typeof(RuntimeException), this.NodeToken, "CannotIndex", ex, (object)obj.GetType().FullName); } } } return((object)arrayList.ToArray()); } try { return(this.GetItem(obj, index)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); if (this.IsMethodNotFoundException(ex)) { throw InterpreterError.NewInterpreterExceptionWithInnerException(index, typeof(RuntimeException), this.NodeToken, "CannotIndex", ex, (object)obj.GetType().FullName); } return((object)null); } }
internal static object ReplaceOperator(System.Management.Automation.ExecutionContext context, IScriptExtent errorPosition, object lval, object rval, bool ignoreCase) { string replacement = ""; object obj2 = ""; rval = PSObject.Base(rval); IList list = rval as IList; if (list != null) { if (list.Count > 2) { throw InterpreterError.NewInterpreterException(rval, typeof(RuntimeException), errorPosition, "BadReplaceArgument", ParserStrings.BadReplaceArgument, new object[] { ignoreCase ? "-ireplace" : "-replace", list.Count }); } if (list.Count > 0) { obj2 = list[0]; if (list.Count > 1) { replacement = PSObject.ToStringParser(context, list[1]); } } } else { obj2 = rval; } RegexOptions none = RegexOptions.None; if (ignoreCase) { none = RegexOptions.IgnoreCase; } Regex regex = obj2 as Regex; if (regex == null) { try { regex = NewRegex(PSObject.ToStringParser(context, obj2), none); } catch (ArgumentException exception) { throw InterpreterError.NewInterpreterExceptionWithInnerException(obj2, typeof(RuntimeException), null, "InvalidRegularExpression", ParserStrings.InvalidRegularExpression, exception, new object[] { obj2 }); } } IEnumerator enumerator = LanguagePrimitives.GetEnumerator(lval); if (enumerator == null) { string input = ((lval == null) ? string.Empty : lval).ToString(); return(regex.Replace(input, replacement)); } ArrayList list2 = new ArrayList(); while (MoveNext(context, errorPosition, enumerator)) { string str3 = PSObject.ToStringParser(context, Current(errorPosition, enumerator)); list2.Add(regex.Replace(str3, replacement)); } return(list2.ToArray()); }
private static object ConvertToNumber(string str, Tokenizer tokenizer) { bool flag1 = false; bool flag2 = false; bool flag3 = false; bool flag4 = false; long num = 1; str = NumberTokenReader.ConvertDash(str); if (str.IndexOf("0x", 0, StringComparison.OrdinalIgnoreCase) >= 0) { flag1 = true; } if (!flag1 && (str.IndexOf('.', 0) >= 0 || str.IndexOf("e", 0, StringComparison.OrdinalIgnoreCase) >= 0)) { flag4 = true; } if (NumberTokenReader.IsMultiplier(str, str.Length - 2)) { switch (char.ToUpperInvariant(str[str.Length - 2])) { case 'G': num = 1073741824L; str = str.Substring(0, str.Length - 2); break; case 'K': num = 1024L; str = str.Substring(0, str.Length - 2); break; case 'M': num = 1048576L; str = str.Substring(0, str.Length - 2); break; case 'P': num = 1125899906842624L; str = str.Substring(0, str.Length - 2); break; case 'T': num = 1099511627776L; str = str.Substring(0, str.Length - 2); break; } } char upperInvariant = char.ToUpperInvariant(str[str.Length - 1]); if (upperInvariant == 'L') { flag2 = true; str = str.Substring(0, str.Length - 1); } else if (!flag1 && upperInvariant == 'D') { flag3 = true; str = str.Substring(0, str.Length - 1); } Exception innerException; try { if (flag3) { return((object)(Decimal.Parse(str, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, (IFormatProvider)NumberFormatInfo.InvariantInfo) * (Decimal)num)); } if (flag2) { return((object)checked ((long)LanguagePrimitives.ConvertTo((object)str, typeof(long), (IFormatProvider)NumberFormatInfo.InvariantInfo) * num)); } if (flag4) { return((object)(double.Parse(str, (IFormatProvider)NumberFormatInfo.InvariantInfo) * (double)num)); } try { return((object)checked ((int)LanguagePrimitives.ConvertTo((object)str, typeof(int), (IFormatProvider)NumberFormatInfo.InvariantInfo) * (int)num)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); } try { return((object)checked ((long)LanguagePrimitives.ConvertTo((object)str, typeof(long), (IFormatProvider)NumberFormatInfo.InvariantInfo) * num)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); } try { return((object)((Decimal)LanguagePrimitives.ConvertTo((object)str, typeof(Decimal), (IFormatProvider)NumberFormatInfo.InvariantInfo) * (Decimal)num)); } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); } return((object)((double)LanguagePrimitives.ConvertTo((object)str, typeof(double), (IFormatProvider)NumberFormatInfo.InvariantInfo) * (double)num)); } catch (OverflowException ex) { innerException = (Exception)ex; } catch (FormatException ex) { innerException = (Exception)ex; } catch (PSInvalidCastException ex) { innerException = (Exception)ex; } if (innerException != null) { if (tokenizer != null) { tokenizer.Parser.ReportExceptionWithInnerException((object)str, typeof(ParseException), tokenizer.PositionToken(), "BadNumericConstant", innerException, (object)innerException.Message); } else { throw InterpreterError.NewInterpreterExceptionWithInnerException((object)str, typeof(RuntimeException), (Token)null, "BadNumericConstant", innerException, (object)innerException.Message); } } return((object)null); }
private void ExecuteFileSwitch( Array input, Pipe outputPipe, ref ArrayList resultList, ExecutionContext context) { string filePath = this.GetFilePath(context); try { using (StreamReader streamReader = new StreamReader(filePath)) { string str; while ((str = streamReader.ReadLine()) != null) { try { this.ProcessClauses((object)str, outputPipe, ref resultList, context); } catch (BreakException ex) { if (this.MatchLabel(ex.Label)) { break; } throw; } catch (ContinueException ex) { if (!this.MatchLabel(ex.Label)) { throw; } } } } } catch (BreakException ex) { throw; } catch (ContinueException ex) { throw; } catch (ReturnException ex) { throw; } catch (ExitException ex) { throw; } catch (TerminateException ex) { throw; } catch (Exception ex) { CommandProcessorBase.CheckForSevereException(ex); throw InterpreterError.NewInterpreterExceptionWithInnerException((object)filePath, typeof(RuntimeException), this._expression.NodeToken, "FileReadError", ex, (object)ex.Message); } }
private void ExecuteStatement( ParseTreeNode statement, Array input, Pipe outputPipe, ref ArrayList resultList, ExecutionContext context) { ScriptTrace.TraceLine(context, statement); Exception e = (Exception)null; try { try { if (statement.IsVoidable) { statement.Execute(input, (Pipe)null, context); } else { statement.Execute(input, outputPipe, ref resultList, context); } ParseTreeNode parseTreeNode = statement; while (parseTreeNode is AssignmentStatementNode assignmentStatementNode) { parseTreeNode = assignmentStatementNode.RightHandSide; } if (parseTreeNode.IsExpression) { context.QuestionMarkVariableValue = true; } else if (parseTreeNode is PipelineNode pipelineNode) { context.QuestionMarkVariableValue = !pipelineNode.ExecutionFailed(context); } } catch (COMException ex) { throw InterpreterError.NewInterpreterExceptionWithInnerException((object)null, typeof(RuntimeException), statement.NodeToken, "COMException", (Exception)ex, (object)ex.Message); } catch (InvalidComObjectException ex) { throw InterpreterError.NewInterpreterExceptionWithInnerException((object)null, typeof(RuntimeException), statement.NodeToken, "InvalidComObjectException", (Exception)ex, (object)ex.Message); } } catch (ReturnException ex) { if (resultList == null || resultList.Count == 0) { e = (Exception)ex; } else { ParseTreeNode.AppendResult(context, ex.Argument, (Pipe)null, ref resultList); ex.SetArgument((object)resultList.ToArray()); resultList = (ArrayList)null; e = (Exception)ex; } } catch (RuntimeException ex) { e = this.HandleException(statement.NodeToken, ex, outputPipe, ref resultList, context); } if (e != null) { RuntimeException.LockStackTrace(e); throw e; } }
internal static object MatchOperator(System.Management.Automation.ExecutionContext context, IScriptExtent errorPosition, object lval, object rval, bool notMatch, bool ignoreCase) { object obj3; RegexOptions options = ignoreCase ? RegexOptions.IgnoreCase : RegexOptions.None; Regex regex = PSObject.Base(rval) as Regex; if (regex == null) { regex = NewRegex(PSObject.ToStringParser(context, rval), options); } IEnumerator targetObject = LanguagePrimitives.GetEnumerator(lval); if (targetObject == null) { string input = (lval == null) ? string.Empty : PSObject.ToStringParser(context, lval); Match match = regex.Match(input); if (match.Success) { GroupCollection groups = match.Groups; if (groups.Count > 0) { Hashtable newValue = new Hashtable(StringComparer.CurrentCultureIgnoreCase); foreach (string str2 in regex.GetGroupNames()) { Group group = groups[str2]; if (group.Success) { int num; if (int.TryParse(str2, out num)) { newValue.Add(num, group.ToString()); } else { newValue.Add(str2, group.ToString()); } } } context.SetVariable(SpecialVariables.MatchesVarPath, newValue); } } return(BoolToObject(match.Success ^ notMatch)); } ArrayList list = new ArrayList(); int num2 = 0; try { while (targetObject.MoveNext()) { object current = targetObject.Current; string str3 = (current == null) ? string.Empty : PSObject.ToStringParser(context, current); if (regex.Match(str3).Success ^ notMatch) { list.Add(current); } if (num2++ > 0x3e8) { if ((context != null) && context.CurrentPipelineStopping) { throw new PipelineStoppedException(); } num2 = 0; } } obj3 = list.ToArray(); } catch (RuntimeException) { throw; } catch (FlowControlException) { throw; } catch (ScriptCallDepthException) { throw; } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); throw InterpreterError.NewInterpreterExceptionWithInnerException(targetObject, typeof(RuntimeException), errorPosition, "BadEnumeration", ParserStrings.BadEnumeration, exception, new object[] { exception.Message }); } return(obj3); }