Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
CorePsStub.cs875 linesDownload Raw Back to CoreCLR
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System;5using System.Collections.Generic;6using System.Globalization;7 8using Microsoft.Win32;9 10#pragma warning disable 1591, 1572, 1571, 1573, 1587, 1570, 006711 12#region PS_STUBS13// Include PS types that are not needed for PowerShell on CSS14 15namespace System.Management.Automation16{17    #region PSTransaction18 19    /// <summary>20    /// We don't need PSTransaction related types on CSS because System.Transactions21    /// namespace is not available in CoreCLR.22    /// </summary>23    public sealed class PSTransactionContext : IDisposable24    {25        internal PSTransactionContext(Internal.PSTransactionManager transactionManager) { }26 27        public void Dispose() { }28    }29 30    /// <summary>31    /// The severity of error that causes PowerShell to automatically32    /// rollback the transaction.33    /// </summary>34    public enum RollbackSeverity35    {36        /// <summary>37        /// Non-terminating errors or worse.38        /// </summary>39        Error,40 41        /// <summary>42        /// Terminating errors or worse.43        /// </summary>44        TerminatingError,45 46        /// <summary>47        /// Do not rollback the transaction on error.48        /// </summary>49        Never50    }51 52    #endregion PSTransaction53}54 55namespace System.Management.Automation.Internal56{57    /// <summary>58    /// We don't need PSTransaction related types on CSS because System.Transactions59    /// namespace is not available in CoreCLR.60    /// </summary>61    internal sealed class PSTransactionManager : IDisposable62    {63        /// <summary>64        /// Determines if you have a transaction that you can set active and work on.65        /// </summary>66        /// <remarks>67        /// Always return false in CoreCLR68        /// </remarks>69        internal bool HasTransaction70        {71            get72            {73                return false;74            }75        }76 77        /// <summary>78        /// Determines if the last transaction has been committed.79        /// </summary>80        internal bool IsLastTransactionCommitted81        {82            get83            {84                throw new NotImplementedException("IsLastTransactionCommitted");85            }86        }87 88        /// <summary>89        /// Determines if the last transaction has been rolled back.90        /// </summary>91        internal bool IsLastTransactionRolledBack92        {93            get94            {95                throw new NotImplementedException("IsLastTransactionRolledBack");96            }97        }98 99        /// <summary>100        /// Gets the rollback preference for the active transaction.101        /// </summary>102        internal RollbackSeverity RollbackPreference103        {104            get105            {106                throw new NotImplementedException("RollbackPreference");107            }108        }109 110        /// <summary>111        /// Called by engine APIs to ensure they are protected from112        /// ambient transactions.113        /// </summary>114        /// <remarks>115        /// Always return null in CoreCLR116        /// </remarks>117        internal static IDisposable GetEngineProtectionScope()118        {119            return null;120        }121 122        /// <summary>123        /// Aborts the current transaction, no matter how many subscribers are part of it.124        /// </summary>125        internal void Rollback(bool suppressErrors)126        {127            throw new NotImplementedException("Rollback");128        }129 130        public void Dispose() { }131    }132}133 134namespace Microsoft.PowerShell.Commands.Internal135{136    using System.Security.AccessControl;137    using System.Security.Principal;138 139    #region TransactedRegistryKey140 141    internal abstract class TransactedRegistryKey : IDisposable142    {143        public void Dispose() { }144 145        public void SetValue(string name, object value)146        {147            throw new NotImplementedException("SetValue(string name, obj value) is not implemented. TransactedRegistry related APIs should not be used.");148        }149 150        public void SetValue(string name, object value, RegistryValueKind valueKind)151        {152            throw new NotImplementedException("SetValue(string name, obj value, RegistryValueKind valueKind) is not implemented. TransactedRegistry related APIs should not be used.");153        }154 155        public string[] GetValueNames()156        {157            throw new NotImplementedException("GetValueNames() is not implemented. TransactedRegistry related APIs should not be used.");158        }159 160        public void DeleteValue(string name)161        {162            throw new NotImplementedException("DeleteValue(string name) is not implemented. TransactedRegistry related APIs should not be used.");163        }164 165        public string[] GetSubKeyNames()166        {167            throw new NotImplementedException("GetSubKeyNames() is not implemented. TransactedRegistry related APIs should not be used.");168        }169 170        public TransactedRegistryKey CreateSubKey(string subkey)171        {172            throw new NotImplementedException("CreateSubKey(string subkey) is not implemented. TransactedRegistry related APIs should not be used.");173        }174 175        public TransactedRegistryKey OpenSubKey(string name, bool writable)176        {177            throw new NotImplementedException("OpenSubKey(string name, bool writeable) is not implemented. TransactedRegistry related APIs should not be used.");178        }179 180        public void DeleteSubKeyTree(string subkey)181        {182            throw new NotImplementedException("DeleteSubKeyTree(string subkey) is not implemented. TransactedRegistry related APIs should not be used.");183        }184 185        public object GetValue(string name)186        {187            throw new NotImplementedException("GetValue(string name) is not implemented. TransactedRegistry related APIs should not be used.");188        }189 190        public object GetValue(string name, object defaultValue, RegistryValueOptions options)191        {192            throw new NotImplementedException("GetValue(string name, object defaultValue, RegistryValueOptions options) is not implemented. TransactedRegistry related APIs should not be used.");193        }194 195        public RegistryValueKind GetValueKind(string name)196        {197            throw new NotImplementedException("GetValueKind(string name) is not implemented. TransactedRegistry related APIs should not be used.");198        }199 200        public void Close()201        {202            throw new NotImplementedException("Close() is not implemented. TransactedRegistry related APIs should not be used.");203        }204 205        public abstract string Name { get; }206 207        public abstract int SubKeyCount { get; }208 209        public void SetAccessControl(ObjectSecurity securityDescriptor)210        {211            throw new NotImplementedException("SetAccessControl(ObjectSecurity securityDescriptor) is not implemented. TransactedRegistry related APIs should not be used.");212        }213 214        public ObjectSecurity GetAccessControl(AccessControlSections includeSections)215        {216            throw new NotImplementedException("GetAccessControl(AccessControlSections includeSections) is not implemented. TransactedRegistry related APIs should not be used.");217        }218    }219 220    internal sealed class TransactedRegistry221    {222        internal static readonly TransactedRegistryKey LocalMachine;223        internal static readonly TransactedRegistryKey ClassesRoot;224        internal static readonly TransactedRegistryKey Users;225        internal static readonly TransactedRegistryKey CurrentConfig;226        internal static readonly TransactedRegistryKey CurrentUser;227    }228 229    internal sealed class TransactedRegistrySecurity : ObjectSecurity230    {231        public override Type AccessRightType232        {233            get234            {235                throw new NotImplementedException();236            }237        }238 239        public override Type AccessRuleType240        {241            get242            {243                throw new NotImplementedException();244            }245        }246 247        public override Type AuditRuleType248        {249            get250            {251                throw new NotImplementedException();252            }253        }254 255        public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type)256        {257            throw new NotImplementedException();258        }259 260        public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags)261        {262            throw new NotImplementedException();263        }264 265        protected override bool ModifyAccess(AccessControlModification modification, AccessRule rule, out bool modified)266        {267            throw new NotImplementedException();268        }269 270        protected override bool ModifyAudit(AccessControlModification modification, AuditRule rule, out bool modified)271        {272            throw new NotImplementedException();273        }274    }275 276    #endregion TransactedRegistryKey277}278 279#endregion PS_STUBS280 281// -- Will port the actual PS component [update: Not necessarily porting all PS components listed here]282#region TEMPORARY283 284namespace System.Management.Automation.Internal285{286    using Microsoft.PowerShell.Commands;287 288    /// <summary>289    /// TODO:CORECLR - The actual PowerShellModuleAssemblyAnalyzer cannot be enabled because we don't have 'System.Reflection.Metadata.dll' in our branch yet.290    /// This stub will be removed once we enable the actual 'PowerShellModuleAssemblyAnalyzer'.291    /// </summary>292    internal static class PowerShellModuleAssemblyAnalyzer293    {294        internal static BinaryAnalysisResult AnalyzeModuleAssembly(string path, out Version assemblyVersion)295        {296            assemblyVersion = new Version("0.0.0.0");297            return null;298        }299    }300}301 302namespace System.Management.Automation303{304    using Microsoft.Win32;305 306    #region RegistryStringResourceIndirect307 308    internal sealed class RegistryStringResourceIndirect : IDisposable309    {310        internal static RegistryStringResourceIndirect GetResourceIndirectReader()311        {312            return new RegistryStringResourceIndirect();313        }314 315        /// <summary>316        /// Dispose method unloads the app domain that was317        /// created in the constructor.318        /// </summary>319        public void Dispose()320        {321        }322 323        internal string GetResourceStringIndirect(324            string assemblyName,325            string modulePath,326            string baseNameRIDPair)327        {328            throw new NotImplementedException("RegistryStringResourceIndirect.GetResourceStringIndirect - 3 params");329        }330 331        internal string GetResourceStringIndirect(332            RegistryKey key,333            string valueName,334            string assemblyName,335            string modulePath)336        {337            throw new NotImplementedException("RegistryStringResourceIndirect.GetResourceStringIndirect - 4 params");338        }339    }340 341    #endregion342}343 344#if UNIX345 346namespace System.Management.Automation.ComInterop347{348    using System.Dynamic;349    using System.Runtime.InteropServices;350 351    /// <summary>352    /// Provides helper methods to bind COM objects dynamically.353    /// </summary>354    /// <remarks>355    /// COM is not supported on Unix platforms. So this is a stub type.356    /// </remarks>357    internal static class ComBinder358    {359        /// <summary>360        /// Tries to perform binding of the dynamic get index operation.361        /// </summary>362        /// <remarks>363        /// Always return false in CoreCLR.364        /// </remarks>365        public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)366        {367            result = null;368            return false;369        }370 371        /// <summary>372        /// Tries to perform binding of the dynamic set index operation.373        /// </summary>374        /// <remarks>375        /// Always return false in CoreCLR.376        /// </remarks>377        public static bool TryBindSetIndex(SetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, DynamicMetaObject value, out DynamicMetaObject result)378        {379            result = null;380            return false;381        }382 383        /// <summary>384        /// Tries to perform binding of the dynamic get member operation.385        /// </summary>386        /// <remarks>387        /// Always return false in CoreCLR.388        /// </remarks>389        public static bool TryBindGetMember(GetMemberBinder binder, DynamicMetaObject instance, out DynamicMetaObject result, bool delayInvocation)390        {391            result = null;392            return false;393        }394 395        /// <summary>396        /// Tries to perform binding of the dynamic set member operation.397        /// </summary>398        /// <remarks>399        /// Always return false in CoreCLR.400        /// </remarks>401        public static bool TryBindSetMember(SetMemberBinder binder, DynamicMetaObject instance, DynamicMetaObject value, out DynamicMetaObject result)402        {403            result = null;404            return false;405        }406 407        /// <summary>408        /// Tries to perform binding of the dynamic invoke member operation.409        /// </summary>410        /// <remarks>411        /// Always return false in CoreCLR.412        /// </remarks>413        public static bool TryBindInvokeMember(InvokeMemberBinder binder, bool isSetProperty, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result)414        {415            result = null;416            return false;417        }418    }419 420    internal static class VarEnumSelector421    {422        internal static Type GetTypeForVarEnum(VarEnum vt)423        {424            throw new PlatformNotSupportedException();425        }426    }427}428 429namespace System.Management.Automation.Security430{431    /// <summary>432    /// Application white listing security policies only affect Windows OSs.433    /// </summary>434    public sealed class SystemPolicy435    {436        private SystemPolicy() { }437 438        /// <summary>439        /// Writes to PowerShell WDAC Audit mode ETW log.440        /// </summary>441        /// <param name="context">Current execution context.</param>442        /// <param name="title">Audit message title.</param>443        /// <param name="message">Audit message message.</param>444        /// <param name="fqid">Fully Qualified ID.</param>445        /// <param name="dropIntoDebugger">Stops code execution and goes into debugger mode.</param>446        internal static void LogWDACAuditMessage(447            ExecutionContext context,448            string title,449            string message,450            string fqid,451            bool dropIntoDebugger = false)452        {453        }454 455        /// <summary>456        /// Gets the system lockdown policy.457        /// </summary>458        /// <remarks>Always return SystemEnforcementMode.None on non-Windows platforms.</remarks>459        public static SystemEnforcementMode GetSystemLockdownPolicy()460        {461            return SystemEnforcementMode.None;462        }463 464        /// <summary>465        /// Gets lockdown policy as applied to a file.466        /// </summary>467        /// <remarks>Always return SystemEnforcementMode.None on non-Windows platforms.</remarks>468        public static SystemEnforcementMode GetLockdownPolicy(string path, System.Runtime.InteropServices.SafeHandle handle)469        {470            return SystemEnforcementMode.None;471        }472 473        internal static bool IsClassInApprovedList(Guid clsid)474        {475            throw new NotImplementedException("SystemPolicy.IsClassInApprovedList not implemented");476        }477 478        /// <summary>479        /// Gets the system wide script file policy enforcement for an open file.480        /// Based on system WDAC (Windows Defender Application Control) or AppLocker policies.481        /// </summary>482        /// <param name="filePath">Script file path for policy check.</param>483        /// <param name="fileStream">FileStream object to script file path.</param>484        /// <returns>Policy check result for script file.</returns>485        public static SystemScriptFileEnforcement GetFilePolicyEnforcement(486            string filePath,487            System.IO.FileStream fileStream)488        {489            return SystemScriptFileEnforcement.None;490        }491    }492 493    /// <summary>494    /// How the policy is being enforced.495    /// </summary>496    public enum SystemEnforcementMode497    {498        /// Not enforced at all499        None = 0,500 501        /// Enabled - allow, but audit502        Audit = 1,503 504        /// Enabled, enforce restrictions505        Enforce = 2506    }507 508    /// <summary>509    /// System wide policy enforcement for a specific script file.510    /// </summary>511    public enum SystemScriptFileEnforcement512    {513        /// <summary>514        /// No policy enforcement.515        /// </summary>516        None = 0,517 518        /// <summary>519        /// Script file is blocked from running.520        /// </summary>521        Block = 1,522 523        /// <summary>524        /// Script file is allowed to run without restrictions (FullLanguage mode).525        /// </summary>526        Allow = 2,527 528        /// <summary>529        /// Script file is allowed to run in ConstrainedLanguage mode only.530        /// </summary>531        AllowConstrained = 3,532 533        /// <summary>534        /// Script file is allowed to run in FullLanguage mode but will emit ConstrainedLanguage restriction audit logs.535        /// </summary>536        AllowConstrainedAudit = 4537    }538}539 540// Porting note: Tracing is absolutely not available on Linux541namespace System.Management.Automation.Tracing542{543    using System.Diagnostics.CodeAnalysis;544    using System.Management.Automation.Internal;545 546    /// <summary>547    /// </summary>548    [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]549    public abstract class EtwActivity550    {551        /// <summary>552        /// </summary>553        /// <param name="activityId"></param>554        /// <returns></returns>555        public static bool SetActivityId(Guid activityId)556        {557            return false;558        }559 560        /// <summary>561        /// </summary>562        /// <returns></returns>563        public static Guid CreateActivityId()564        {565            return Guid.Empty;566        }567 568        /// <summary>569        /// </summary>570        /// <returns></returns>571        public static Guid GetActivityId()572        {573            return Guid.Empty;574        }575    }576 577    public enum PowerShellTraceTask578    {579        /// <summary>580        /// None.581        /// </summary>582        None = 0,583 584        /// <summary>585        /// CreateRunspace.586        /// </summary>587        CreateRunspace = 1,588 589        /// <summary>590        /// ExecuteCommand.591        /// </summary>592        ExecuteCommand = 2,593 594        /// <summary>595        /// Serialization.596        /// </summary>597        Serialization = 3,598 599        /// <summary>600        /// PowerShellConsoleStartup.601        /// </summary>602        PowerShellConsoleStartup = 4,603    }604 605    /// <summary>606    /// Defines Keywords.607    /// </summary>608    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1028")]609    [Flags]610    public enum PowerShellTraceKeywords : ulong611    {612        /// <summary>613        /// None.614        /// </summary>615        None = 0,616 617        /// <summary>618        /// Runspace.619        /// </summary>620        Runspace = 0x1,621 622        /// <summary>623        /// Pipeline.624        /// </summary>625        Pipeline = 0x2,626 627        /// <summary>628        /// Protocol.629        /// </summary>630        Protocol = 0x4,631 632        /// <summary>633        /// Transport.634        /// </summary>635        Transport = 0x8,636 637        /// <summary>638        /// Host.639        /// </summary>640        Host = 0x10,641 642        /// <summary>643        /// Cmdlets.644        /// </summary>645        Cmdlets = 0x20,646 647        /// <summary>648        /// Serializer.649        /// </summary>650        Serializer = 0x40,651 652        /// <summary>653        /// Session.654        /// </summary>655        Session = 0x80,656 657        /// <summary>658        /// ManagedPlugIn.659        /// </summary>660        ManagedPlugIn = 0x100,661 662        /// <summary>663        /// </summary>664        UseAlwaysDebug = 0x2000000000000000,665 666        /// <summary>667        /// </summary>668        UseAlwaysOperational = 0x8000000000000000,669 670        /// <summary>671        /// </summary>672        UseAlwaysAnalytic = 0x4000000000000000,673    }674 675    public sealed partial class Tracer : System.Management.Automation.Tracing.EtwActivity676    {677        static Tracer() { }678 679        public void EndpointRegistered(string endpointName, string endpointType, string registeredBy)680        {681        }682 683        public void EndpointUnregistered(string endpointName, string unregisteredBy)684        {685        }686 687        public void EndpointDisabled(string endpointName, string disabledBy)688        {689        }690 691        public void EndpointEnabled(string endpointName, string enabledBy)692        {693        }694 695        public void EndpointModified(string endpointName, string modifiedBy)696        {697        }698 699        public void BeginContainerParentJobExecution(Guid containerParentJobInstanceId)700        {701        }702 703        public void BeginProxyJobExecution(Guid proxyJobInstanceId)704        {705        }706 707        public void ProxyJobRemoteJobAssociation(Guid proxyJobInstanceId, Guid containerParentJobInstanceId)708        {709        }710 711        public void EndProxyJobExecution(Guid proxyJobInstanceId)712        {713        }714 715        public void BeginProxyJobEventHandler(Guid proxyJobInstanceId)716        {717        }718 719        public void EndProxyJobEventHandler(Guid proxyJobInstanceId)720        {721        }722 723        public void BeginProxyChildJobEventHandler(Guid proxyChildJobInstanceId)724        {725        }726 727        public void EndContainerParentJobExecution(Guid containerParentJobInstanceId)728        {729        }730    }731 732    public sealed class PowerShellTraceSource : IDisposable733    {734        internal PowerShellTraceSource(PowerShellTraceTask task, PowerShellTraceKeywords keywords)735        {736        }737 738        public void Dispose()739        {740        }741 742        public bool WriteMessage(string message)743        {744            return false;745        }746 747        /// <summary>748        /// </summary>749        /// <param name="message1"></param>750        /// <param name="message2"></param>751        /// <returns></returns>752        public bool WriteMessage(string message1, string message2)753        {754            return false;755        }756 757        /// <summary>758        /// </summary>759        /// <param name="message"></param>760        /// <param name="instanceId"></param>761        /// <returns></returns>762        public bool WriteMessage(string message, Guid instanceId)763        {764            return false;765        }766 767        /// <summary>768        /// </summary>769        /// <param name="className"></param>770        /// <param name="methodName"></param>771        /// <param name="workflowId"></param>772        /// <param name="message"></param>773        /// <param name="parameters"></param>774        /// <returns></returns>775        public void WriteMessage(string className, string methodName, Guid workflowId, string message, params string[] parameters)776        {777            return;778        }779 780        /// <summary>781        /// </summary>782        /// <param name="className"></param>783        /// <param name="methodName"></param>784        /// <param name="workflowId"></param>785        /// <param name="job"></param>786        /// <param name="message"></param>787        /// <param name="parameters"></param>788        /// <returns></returns>789        public void WriteMessage(string className, string methodName, Guid workflowId, Job job, string message, params string[] parameters)790        {791            return;792        }793 794        public bool TraceException(Exception exception)795        {796            return false;797        }798    }799 800    /// <summary>801    /// TraceSourceFactory will return an instance of TraceSource every time GetTraceSource method is called.802    /// </summary>803    public static class PowerShellTraceSourceFactory804    {805        /// <summary>806        /// Returns an instance of BaseChannelWriter.807        /// If the Etw is not supported by the platform it will return NullWriter.Instance808        ///809        /// A Task and a set of Keywords can be specified in the GetTraceSource method (See overloads).810        ///    The supplied task and keywords are used to pass to the Etw provider in case they are811        /// not defined in the manifest file.812        /// </summary>813        public static PowerShellTraceSource GetTraceSource()814        {815            return new PowerShellTraceSource(PowerShellTraceTask.None, PowerShellTraceKeywords.None);816        }817 818        /// <summary>819        /// Returns an instance of BaseChannelWriter.820        /// If the Etw is not supported by the platform it will return NullWriter.Instance821        ///822        /// A Task and a set of Keywords can be specified in the GetTraceSource method (See overloads).823        ///    The supplied task and keywords are used to pass to the Etw provider in case they are824        /// not defined in the manifest file.825        /// </summary>826        public static PowerShellTraceSource GetTraceSource(PowerShellTraceTask task)827        {828            return new PowerShellTraceSource(task, PowerShellTraceKeywords.None);829        }830 831        /// <summary>832        /// Returns an instance of BaseChannelWriter.833        /// If the Etw is not supported by the platform it will return NullWriter.Instance834        ///835        /// A Task and a set of Keywords can be specified in the GetTraceSource method (See overloads).836        ///    The supplied task and keywords are used to pass to the Etw provider in case they are837        /// not defined in the manifest file.838        /// </summary>839        public static PowerShellTraceSource GetTraceSource(PowerShellTraceTask task, PowerShellTraceKeywords keywords)840        {841            return new PowerShellTraceSource(task, keywords);842        }843    }844}845 846#endif847 848namespace Microsoft.PowerShell849{850    internal static class NativeCultureResolver851    {852        internal static void SetThreadUILanguage(Int16 langId) { }853 854        internal static CultureInfo UICulture855        {856            get857            {858                return CultureInfo.CurrentUICulture; // this is actually wrong, but until we port "hostifaces\NativeCultureResolver.cs" to Nano, this will do and will help avoid build break.859            }860        }861 862        internal static CultureInfo Culture863        {864            get865            {866                return CultureInfo.CurrentCulture; // this is actually wrong, but until we port "hostifaces\NativeCultureResolver.cs" to Nano, this will do and will help avoid build break.867            }868        }869    }870}871 872#endregion TEMPORARY873 874#pragma warning restore 1591, 1572, 1571, 1573, 1587, 1570, 0067875