#if CORECLR /********************************************************************++ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System; using System.Globalization; using System.Reflection; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Win32; using System.Management.Automation.Remoting; #pragma warning disable 1591, 1572, 1571, 1573, 1587, 1570, 0067 #region CLR_STUBS // This namespace contains stubs for some .NET types that are not in CoreCLR, such as ISerializable and SerializableAttribute. // We use the stubs in this namespace to reduce #if/def in the code as much as possible. namespace Microsoft.PowerShell.CoreClr.Stubs { using System.Runtime.InteropServices; // We create some stub attribute types to make some attribute markers work in CoreCLR. // The purpose of this is to avoid #if/def in powershell code as much as possible. #region Attribute_Related /// /// Stub for SpecialNameAttribute /// public sealed class SpecialNameAttribute : Attribute { /// /// /// public SpecialNameAttribute() {} } /// /// Stub for SerializableAttribute /// public sealed class SerializableAttribute : Attribute { /// /// /// public SerializableAttribute() {} } /// /// Stub for NonSerializedAttribute /// public sealed class NonSerializedAttribute : Attribute { /// /// /// public NonSerializedAttribute() {} } /// /// Stub for SecurityAction /// public enum SecurityAction { Assert = 3, Demand = 2, InheritanceDemand = 7, LinkDemand = 6, PermitOnly = 5 } /// /// Stub for SecurityPermissionAttribute /// public sealed class SecurityPermissionAttribute : Attribute { public SecurityPermissionAttribute(SecurityAction action) {} public bool SerializationFormatter { get; set; } public bool UnmanagedCode { get; set; } } /// /// Stub for TypeLibTypeAttribute /// public sealed class TypeLibTypeAttribute : Attribute { /// /// /// /// public TypeLibTypeAttribute(short flags) {} } /// /// Stub for SuppressUnmanagedCodeSecurityAttribute /// public class SuppressUnmanagedCodeSecurityAttribute : Attribute { } /// /// Stub for HostProtectionAttribute /// public sealed class HostProtectionAttribute : Attribute { public HostProtectionAttribute(SecurityAction action) {} public bool MayLeakOnAbort { get; set; } } /// /// Stub for ResourceExposureAttribute /// public sealed class ResourceExposureAttribute : Attribute { private ResourceScope _resourceExposureLevel; public ResourceExposureAttribute(ResourceScope exposureLevel) { _resourceExposureLevel = exposureLevel; } public ResourceScope ResourceExposureLevel { get { return _resourceExposureLevel; } } } /// /// Stub for ResourceScope /// public enum ResourceScope { None = 0, // Resource type Machine = 0x1, Process = 0x2, AppDomain = 0x4, Library = 0x8, // Visibility Private = 0x10, // Private to this one class. Assembly = 0x20, // Assembly-level, like C#'s "internal" } /// /// Stub for ReliabilityContractAttribute /// public sealed class ReliabilityContractAttribute : Attribute { /// /// /// public ReliabilityContractAttribute(Consistency consistencyGuarantee, Cer cer) { } } /// /// Stub for Cer /// public enum Cer { /// /// None /// None, /// /// MayFail /// MayFail, /// /// Success /// Success } /// /// Stub for Consistency /// public enum Consistency { /// /// MayCorruptProcess /// MayCorruptProcess, /// /// MayCorruptAppDomain /// MayCorruptAppDomain, /// /// MayCorruptInstance /// MayCorruptInstance, /// /// WillNotCorruptState /// WillNotCorruptState } #endregion Attribute_Related #region Serialization_Related /// /// Stub for SerializationInfo /// public sealed class SerializationInfo { /// /// /// public SerializationInfo() {} /// /// /// /// /// public void AddValue(string name, object value) { throw new NotImplementedException("AddValue(string name, object value)"); } /// /// /// /// /// public void AddValue(string name, bool value) { throw new NotImplementedException("AddValue(string name, bool value)"); } /// /// /// /// /// /// public void AddValue(string name, Object value, Type type) { throw new NotImplementedException("AddValue(string name, Object value, Type type)"); } /// /// /// /// /// public void AddValue(string name, int value) { throw new NotImplementedException("AddValue(string name, int value)"); } /// /// /// /// /// /// public object GetValue(string name, Type type) { throw new NotImplementedException("GetValue(string name, Type type)"); } /// /// /// /// /// public string GetString(string name) { throw new NotImplementedException("GetString(string name)"); } /// /// /// /// /// public bool GetBoolean(string name) { throw new NotImplementedException("GetBoolean(string name)"); } /// /// /// /// /// public int GetInt32(string name) { throw new NotImplementedException("GetInt32(string name)"); } /// /// /// /// public void SetType(System.Type type) { throw new NotImplementedException("SetType(System.Type type)"); } /// /// /// /// /// public long GetInt64(string name) { throw new NotImplementedException("GetInt64(string name)"); } } #endregion Serialization_Related #region Interface_Related /// /// Stub for ISerializable /// public interface ISerializable { /// /// /// /// /// void GetObjectData(SerializationInfo info, System.Runtime.Serialization.StreamingContext context); } /// /// Stub for ICloneable /// public interface ICloneable { /// /// /// /// object Clone(); } /// /// Stub for IObjectReference /// public interface IObjectReference { /// /// /// /// /// Object GetRealObject(System.Runtime.Serialization.StreamingContext context); } /// /// Stub for IRuntimeVariables /// public interface IRuntimeVariables { /// /// /// int Count { get; } /// /// /// /// /// object this[int index] { get; set; } } #endregion Interface_Related #region Exception_Related /// /// Stub for SystemException /// public class SystemException : Exception { /// /// SystemException constructor /// public SystemException() : base() { } /// /// SystemException constructor /// /// public SystemException(string message) : base(message) { } /// /// SystemException constructor /// /// /// public SystemException(string message, Exception innerException) : base(message, innerException) {} /// /// SystemException constructor /// /// /// protected SystemException(SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } /// /// SystemException constructor /// /// /// public virtual void GetObjectData(SerializationInfo info, System.Runtime.Serialization.StreamingContext context) {} } /// /// Stub for AccessViolationException /// public class AccessViolationException : Exception { /// /// AccessViolationException constructor /// public AccessViolationException() : base() { } /// /// AccessViolationException constructor /// /// public AccessViolationException(string message) : base(message) { } /// /// AccessViolationException constructor /// /// /// public AccessViolationException(string message, Exception innerException) : base(message, innerException) {} /// /// AccessViolationException constructor /// /// /// protected AccessViolationException(SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } /// /// AccessViolationException constructor /// /// /// public virtual void GetObjectData(SerializationInfo info, System.Runtime.Serialization.StreamingContext context) {} } /// /// Stub for ThreadAbortException /// public sealed class ThreadAbortException : Exception { } /// /// Stub for AppDomainUnloadedException /// public sealed class AppDomainUnloadedException : Exception { } #endregion Exception_Related #region SafeHandle_Related /// /// Stub for SafeHandleZeroOrMinusOneIsInvalid /// public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle { /// /// Constructor /// protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle) { } /// /// IsInvalid /// public override bool IsInvalid { get { return handle == IntPtr.Zero || handle == new IntPtr(-1); } } } #endregion SafeHandle_Related #region Misc_Types /// /// Stub for SecurityZone /// public enum SecurityZone { MyComputer = 0, Intranet = 1, Trusted = 2, Internet = 3, Untrusted = 4, NoZone = -1, } /// /// Stub for MailAddress /// public class MailAddress { public MailAddress(string address) {} } #endregion Misc_Types #region SystemManagementStubs // Summary: // Describes the authentication level to be used to connect to WMI. This is // used for the COM connection to WMI. public enum AuthenticationLevel { // Summary: // Authentication level should remain as it was before. Unchanged = -1, // // Summary: // The default COM authentication level. WMI uses the default Windows Authentication // setting. Default = 0, // // Summary: // No COM authentication. None = 1, // // Summary: // Connect-level COM authentication. Connect = 2, // // Summary: // Call-level COM authentication. Call = 3, // // Summary: // Packet-level COM authentication. Packet = 4, // // Summary: // Packet Integrity-level COM authentication. PacketIntegrity = 5, // // Summary: // Packet Privacy-level COM authentication. PacketPrivacy = 6, } // Summary: // Describes the impersonation level to be used to connect to WMI. public enum ImpersonationLevel { // Summary: // Default impersonation. Default = 0, // // Summary: // Anonymous COM impersonation level that hides the identity of the caller. // Calls to WMI may fail with this impersonation level. Anonymous = 1, // // Summary: // Identify-level COM impersonation level that allows objects to query the credentials // of the caller. Calls to WMI may fail with this impersonation level. Identify = 2, // // Summary: // Impersonate-level COM impersonation level that allows objects to use the // credentials of the caller. This is the recommended impersonation level for // WMI calls. Impersonate = 3, // // Summary: // Delegate-level COM impersonation level that allows objects to permit other // objects to use the credentials of the caller. This level, which will work // with WMI calls but may constitute an unnecessary security risk, is supported // only under Windows 2000. Delegate = 4, } #endregion } //TODO:CORECLR Put Stubs to System.Management.Core.dll namespace System { /// /// TODO:CORECLR Inspection of the binary module needs to be re-write without using AppDomain /// internal sealed class AppDomain { /// /// /// public static System.AppDomain CreateDomain(string friendlyName) { return null; } /// /// /// public static void Unload(System.AppDomain domain) { } } } namespace System.Net { internal class WebClient //: Component { public WebClient() { } public void Dispose() { } public bool UseDefaultCredentials { get; set; } } } namespace System.Security { using System.Text; /// /// /// sealed public class SecurityElement { private static readonly string[] s_escapeStringPairs = new string[] { // these must be all once character escape sequences or a new escaping algorithm is needed "<", "<", ">", ">", "\"", """, "\'", "'", "&", "&" }; private static readonly char[] s_escapeChars = new char[] { '<', '>', '\"', '\'', '&' }; /// /// Replaces invalid XML characters in a string with their valid XML equivalent. /// public static string Escape(string str) { if (str == null) return null; StringBuilder sb = null; int strLen = str.Length; int index; // Pointer into the string that indicates the location of the current '&' character int newIndex = 0; // Pointer into the string that indicates the start index of the "remaining" string (that still needs to be processed). do { index = str.IndexOfAny(s_escapeChars, newIndex); if (index == -1) { if (sb == null) return str; else { sb.Append(str, newIndex, strLen - newIndex); return sb.ToString(); } } else { if (sb == null) sb = new StringBuilder(); sb.Append(str, newIndex, index - newIndex); sb.Append(GetEscapeSequence(str[index])); newIndex = (index + 1); } } while (true); } private static string GetEscapeSequence(char c) { int iMax = s_escapeStringPairs.Length; for (int i = 0; i < iMax; i += 2) { String strEscSeq = s_escapeStringPairs[i]; String strEscValue = s_escapeStringPairs[i + 1]; if (strEscSeq[0] == c) return strEscValue; } Diagnostics.Debug.Assert(false, "Unable to find escape sequence for this character"); return c.ToString(); } } } #endregion CLR_STUBS #region PS_STUBS // Include PS types that are not needed for PowerShell on CSS namespace System.Management.Automation { #region PSTransaction /// /// We don't need PSTransaction related types on CSS because System.Transactions /// namespace is not available in CoreCLR /// public sealed class PSTransactionContext : IDisposable { internal PSTransactionContext(Internal.PSTransactionManager transactionManager) { } public void Dispose() { } } /// /// The severity of error that causes PowerShell to automatically /// rollback the transaction. /// public enum RollbackSeverity { /// /// Non-terminating errors or worse /// Error, /// /// Terminating errors or worse /// TerminatingError, /// /// Do not rollback the transaction on error /// Never } #endregion PSTransaction #region CMS internal static class CmsUtils { internal static string BEGIN_CERTIFICATE_SIGIL = "-----BEGIN CERTIFICATE-----"; internal static string END_CERTIFICATE_SIGIL = "-----END CERTIFICATE-----"; internal static string Encrypt(byte[] contentBytes, CmsMessageRecipient[] recipients, SessionState sessionState, out ErrorRecord error) { throw new NotImplementedException("CmsUtils.Encrypt(...) is not implemented in CoreCLR powershell."); } internal static string GetAsciiArmor(byte[] bytes) { throw new NotImplementedException("CmsUtils.GetAsciiArmor(...) is not implemented in CoreCLR powershell."); } internal static byte[] RemoveAsciiArmor(string actualContent, string beginMarker, string endMarker, out int startIndex, out int endIndex) { throw new NotImplementedException("CmsUtils.RemoveAsciiArmor(...) is not implemented in CoreCLR powershell."); } } #endregion CMS #region ApartmentState internal enum ApartmentState { // // Summary: // The System.Threading.Thread will create and enter a single-threaded apartment. STA = 0, // // Summary: // The System.Threading.Thread will create and enter a multithreaded apartment. MTA = 1, // // Summary: // The System.Threading.Thread.ApartmentState property has not been set. Unknown = 2 } #endregion ApartmentState } namespace System.Management.Automation.Internal { /// /// We don't need PSTransaction related types on CSS because System.Transactions /// namespace is not available in CoreCLR /// internal sealed class PSTransactionManager : IDisposable { /// /// Determines if you have a transaction that you can set active and work on. /// /// /// Always return false in CoreCLR /// internal bool HasTransaction { get { return false; } } /// /// Determines if the last transaction has been committed. /// internal bool IsLastTransactionCommitted { get { throw new NotImplementedException("IsLastTransactionCommitted"); } } /// /// Determines if the last transaction has been rolled back. /// internal bool IsLastTransactionRolledBack { get { throw new NotImplementedException("IsLastTransactionRolledBack"); } } /// /// Gets the rollback preference for the active transaction /// internal RollbackSeverity RollbackPreference { get { throw new NotImplementedException("RollbackPreference"); } } /// /// Called by engine APIs to ensure they are protected from /// ambient transactions. /// /// /// Always return null in CoreCLR /// internal static IDisposable GetEngineProtectionScope() { return null; } /// /// Aborts the current transaction, no matter how many subscribers are part of it. /// internal void Rollback(bool suppressErrors) { throw new NotImplementedException("Rollback"); } public void Dispose() {} } } namespace System.Management.Automation.ComInterop { using System.Dynamic; using System.Diagnostics; using System.Runtime.InteropServices; /// /// Provides helper methods to bind COM objects dynamically. /// /// /// COM is not supported in core powershell. So this is a stub type. /// internal static class ComBinder { /// /// Tries to perform binding of the dynamic get index operation. /// /// /// Always return false in CoreCLR. /// public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) { result = null; return false; } /// /// Tries to perform binding of the dynamic set index operation. /// /// /// Always return false in CoreCLR. /// public static bool TryBindSetIndex(SetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, DynamicMetaObject value, out DynamicMetaObject result) { result = null; return false; } /// /// Tries to perform binding of the dynamic get member operation. /// /// /// Always return false in CoreCLR. /// public static bool TryBindGetMember(GetMemberBinder binder, DynamicMetaObject instance, out DynamicMetaObject result) { result = null; return false; } /// /// Tries to perform binding of the dynamic set member operation. /// /// /// Always return false in CoreCLR. /// public static bool TryBindSetMember(SetMemberBinder binder, DynamicMetaObject instance, DynamicMetaObject value, out DynamicMetaObject result) { result = null; return false; } /// /// Tries to perform binding of the dynamic invoke member operation. /// /// /// Always return false in CoreCLR. /// public static bool TryBindInvokeMember(InvokeMemberBinder binder, bool isSetProperty, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) { result = null; return false; } } #pragma warning disable 618 // Disable obsolete warning about VarEnum in CoreCLR internal class VarEnumSelector { private static readonly Dictionary _ComToManagedPrimitiveTypes = CreateComToManagedPrimitiveTypes(); internal static Type GetTypeForVarEnum(VarEnum vt) { Type type; switch (vt) { // VarEnums which can be used in VARIANTs, but which cannot occur in a TYPEDESC case VarEnum.VT_EMPTY: case VarEnum.VT_NULL: case VarEnum.VT_RECORD: type = typeof(void); break; // VarEnums which are not used in VARIANTs, but which can occur in a TYPEDESC case VarEnum.VT_VOID: type = typeof(void); break; case VarEnum.VT_HRESULT: type = typeof(int); break; case ((VarEnum)37): // VT_INT_PTR: type = typeof(IntPtr); break; case ((VarEnum)38): // VT_UINT_PTR: type = typeof(UIntPtr); break; case VarEnum.VT_SAFEARRAY: case VarEnum.VT_CARRAY: type = typeof(Array); break; case VarEnum.VT_LPSTR: case VarEnum.VT_LPWSTR: type = typeof(string); break; case VarEnum.VT_PTR: case VarEnum.VT_USERDEFINED: type = typeof(object); break; // For VarEnums that can be used in VARIANTs and well as TYPEDESCs, just use VarEnumSelector default: type = VarEnumSelector.GetManagedMarshalType(vt); break; } return type; } /// /// Gets the managed type that an object needs to be coverted to in order for it to be able /// to be represented as a Variant. /// /// In general, there is a many-to-many mapping between Type and VarEnum. However, this method /// returns a simple mapping that is needed for the current implementation. The reason for the /// many-to-many relation is: /// 1. Int32 maps to VT_I4 as well as VT_ERROR, and Decimal maps to VT_DECIMAL and VT_CY. However, /// this changes if you throw the wrapper types into the mix. /// 2. There is no Type to represent COM types. __ComObject is a private type, and Object is too /// general. /// internal static Type GetManagedMarshalType(VarEnum varEnum) { Debug.Assert((varEnum & VarEnum.VT_BYREF) == 0); if (varEnum == VarEnum.VT_CY) { return typeof(CurrencyWrapper); } if (IsPrimitiveType(varEnum)) { return _ComToManagedPrimitiveTypes[varEnum]; } switch (varEnum) { case VarEnum.VT_EMPTY: case VarEnum.VT_NULL: case VarEnum.VT_UNKNOWN: case VarEnum.VT_DISPATCH: case VarEnum.VT_VARIANT: return typeof(Object); case VarEnum.VT_ERROR: return typeof(ErrorWrapper); default: throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, ParserStrings.UnexpectedVarEnum, varEnum));; } } private static Dictionary CreateComToManagedPrimitiveTypes() { Dictionary dict = new Dictionary(); // *** BEGIN GENERATED CODE *** // generated by function: gen_ComToManagedPrimitiveTypes from: generate_comdispatch.py dict[VarEnum.VT_I1] = typeof(SByte); dict[VarEnum.VT_I2] = typeof(Int16); dict[VarEnum.VT_I4] = typeof(Int32); dict[VarEnum.VT_I8] = typeof(Int64); dict[VarEnum.VT_UI1] = typeof(Byte); dict[VarEnum.VT_UI2] = typeof(UInt16); dict[VarEnum.VT_UI4] = typeof(UInt32); dict[VarEnum.VT_UI8] = typeof(UInt64); dict[VarEnum.VT_INT] = typeof(Int32); dict[VarEnum.VT_UINT] = typeof(UInt32); dict[VarEnum.VT_PTR] = typeof(IntPtr); dict[VarEnum.VT_BOOL] = typeof(Boolean); dict[VarEnum.VT_R4] = typeof(Single); dict[VarEnum.VT_R8] = typeof(Double); dict[VarEnum.VT_DECIMAL] = typeof(Decimal); dict[VarEnum.VT_DATE] = typeof(DateTime); dict[VarEnum.VT_BSTR] = typeof(String); dict[VarEnum.VT_CLSID] = typeof(Guid); // *** END GENERATED CODE *** dict[VarEnum.VT_CY] = typeof(CurrencyWrapper); dict[VarEnum.VT_ERROR] = typeof(ErrorWrapper); return dict; } /// /// Primitive types are the basic COM types. It includes valuetypes like ints, but also reference types /// like BStrs. It does not include composite types like arrays and user-defined COM types (IUnknown/IDispatch). /// internal static bool IsPrimitiveType(VarEnum varEnum) { switch (varEnum) { // *** BEGIN GENERATED CODE *** // generated by function: gen_IsPrimitiveType from: generate_comdispatch.py case VarEnum.VT_I1: case VarEnum.VT_I2: case VarEnum.VT_I4: case VarEnum.VT_I8: case VarEnum.VT_UI1: case VarEnum.VT_UI2: case VarEnum.VT_UI4: case VarEnum.VT_UI8: case VarEnum.VT_INT: case VarEnum.VT_UINT: case VarEnum.VT_BOOL: case VarEnum.VT_ERROR: case VarEnum.VT_R4: case VarEnum.VT_R8: case VarEnum.VT_DECIMAL: case VarEnum.VT_CY: case VarEnum.VT_DATE: case VarEnum.VT_BSTR: // *** END GENERATED CODE *** return true; } return false; } } #pragma warning restore 618 } namespace Microsoft.PowerShell.Commands.Internal { using System.Security.AccessControl; using System.Security.Principal; #region TransactedRegistryKey internal abstract class TransactedRegistryKey : IDisposable { public void Dispose() { } public void SetValue(string name, object value) { throw new NotImplementedException("SetValue(string name, obj value) is not implemented. TransactedRegistry related APIs should not be hitten."); } public void SetValue(string name, object value, RegistryValueKind valueKind) { throw new NotImplementedException("SetValue(string name, obj value, RegistryValueKind valueKind) is not implemented. TransactedRegistry related APIs should not be hitten."); } public string[] GetValueNames() { throw new NotImplementedException("GetValueNames() is not implemented. TransactedRegistry related APIs should not be hitten."); } public void DeleteValue(string name) { throw new NotImplementedException("DeleteValue(string name) is not implemented. TransactedRegistry related APIs should not be hitten."); } public string[] GetSubKeyNames() { throw new NotImplementedException("GetSubKeyNames() is not implemented. TransactedRegistry related APIs should not be hitten."); } public TransactedRegistryKey CreateSubKey(string subkey) { throw new NotImplementedException("CreateSubKey(string subkey) is not implemented. TransactedRegistry related APIs should not be hitten."); } public TransactedRegistryKey OpenSubKey(string name, bool writable) { throw new NotImplementedException("OpenSubKey(string name, bool writeable) is not implemented. TransactedRegistry related APIs should not be hitten."); } public void DeleteSubKeyTree(string subkey) { throw new NotImplementedException("DeleteSubKeyTree(string subkey) is not implemented. TransactedRegistry related APIs should not be hitten."); } public object GetValue(string name) { throw new NotImplementedException("GetValue(string name) is not implemented. TransactedRegistry related APIs should not be hitten."); } public object GetValue(string name, object defaultValue, RegistryValueOptions options) { throw new NotImplementedException("GetValue(string name, object defaultValue, RegistryValueOptions options) is not implemented. TransactedRegistry related APIs should not be hitten."); } public RegistryValueKind GetValueKind(string name) { throw new NotImplementedException("GetValueKind(string name) is not implemented. TransactedRegistry related APIs should not be hitten."); } public void Close() { throw new NotImplementedException("Close() is not implemented. TransactedRegistry related APIs should not be hitten."); } public abstract string Name { get; } public abstract int SubKeyCount { get; } public void SetAccessControl(ObjectSecurity securityDescriptor) { throw new NotImplementedException("SetAccessControl(ObjectSecurity securityDescriptor) is not implemented. TransactedRegistry related APIs should not be hitten."); } public ObjectSecurity GetAccessControl(AccessControlSections includeSections) { throw new NotImplementedException("GetAccessControl(AccessControlSections includeSections) is not implemented. TransactedRegistry related APIs should not be hitten."); } } internal sealed class TransactedRegistry { internal static readonly TransactedRegistryKey LocalMachine; internal static readonly TransactedRegistryKey ClassesRoot; internal static readonly TransactedRegistryKey Users; internal static readonly TransactedRegistryKey CurrentConfig; internal static readonly TransactedRegistryKey CurrentUser; } internal sealed class TransactedRegistrySecurity : ObjectSecurity { public override Type AccessRightType { get { throw new NotImplementedException(); } } public override Type AccessRuleType { get { throw new NotImplementedException(); } } public override Type AuditRuleType { get { throw new NotImplementedException(); } } public override AccessRule AccessRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType type) { throw new NotImplementedException(); } public override AuditRule AuditRuleFactory(IdentityReference identityReference, int accessMask, bool isInherited, InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AuditFlags flags) { throw new NotImplementedException(); } protected override bool ModifyAccess(AccessControlModification modification, AccessRule rule, out bool modified) { throw new NotImplementedException(); } protected override bool ModifyAudit(AccessControlModification modification, AuditRule rule, out bool modified) { throw new NotImplementedException(); } } #endregion TransactedRegistryKey } #endregion PS_STUBS #region TEMPORARY -- Will port the actual PS component [update: Not necessarily porting all PS components listed here] namespace System.Management.Automation.Internal { using Microsoft.PowerShell.Commands; /// /// TODO:CORECLR - The actual PowerShellModuleAssemblyAnalyzer cannot be enabled because we don't have 'System.Reflection.Metadata.dll' in our branch yet. /// This stub will be removed once we enable the actual 'PowerShellModuleAssemblyAnalyzer'. /// internal static class PowerShellModuleAssemblyAnalyzer { internal static BinaryAnalysisResult AnalyzeModuleAssembly(string path, out Version assemblyVersion) { assemblyVersion = new Version("0.0.0.0"); return null; } } } namespace System.Management.Automation { using Microsoft.Win32; #region RegistryStringResourceIndirect internal sealed class RegistryStringResourceIndirect : IDisposable { internal static RegistryStringResourceIndirect GetResourceIndirectReader() { return new RegistryStringResourceIndirect(); } /// /// Dispose method unloads the app domain that was /// created in the constructor. /// public void Dispose() { } internal string GetResourceStringIndirect( string assemblyName, string modulePath, string baseNameRIDPair) { throw new NotImplementedException("RegistryStringResourceIndirect.GetResourceStringIndirect - 3 params"); } internal string GetResourceStringIndirect( RegistryKey key, string valueName, string assemblyName, string modulePath) { throw new NotImplementedException("RegistryStringResourceIndirect.GetResourceStringIndirect - 4 params"); } } #endregion #region Environment internal static partial class Environment { //TODO:CORECLR Need to be removed once we decide what will be the replacement internal static void Exit(int exitCode) { } } #endregion Environment } namespace System.Management.Automation.Security { /// /// We don't need Windows Lockdown Policy related types on CSS because CSS is /// amd64 only and is used internally. /// internal sealed class SystemPolicy { private SystemPolicy() {} /// /// Gets the system lockdown policy /// /// Always return SystemEnforcementMode.None in CSS (trusted) public static SystemEnforcementMode GetSystemLockdownPolicy() { return SystemEnforcementMode.None; } /// /// Gets lockdown policy as applied to a file /// /// Always return SystemEnforcementMode.None in CSS (trusted) public static SystemEnforcementMode GetLockdownPolicy(string path, System.Runtime.InteropServices.SafeHandle handle) { return SystemEnforcementMode.None; } internal static bool IsClassInApprovedList(Guid clsid) { throw new NotImplementedException("SystemPolicy.IsClassInApprovedList not implemented"); } } /// /// How the policy is being enforced /// internal enum SystemEnforcementMode { /// Not enforced at all None = 0, /// Enabled - allow, but audit Audit = 1, /// Enabled, enforce restrictions Enforce = 2 } } #if NOETW || LINUX // Porting note: Tracing is absolutely not available on Linux namespace System.Management.Automation.Tracing { using System.Management.Automation.Internal; /// /// /// [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")] public abstract class EtwActivity { /// /// /// /// /// public static bool SetActivityId(Guid activityId) { return false; } /// /// /// /// public static Guid CreateActivityId() { return Guid.Empty; } /// /// /// /// public static Guid GetActivityId() { return Guid.Empty; } } internal static class PSEtwLog { static internal void LogAnalyticError(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } static internal void LogAnalyticWarning(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } static internal void LogAnalyticVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, Int64 objectId, Int64 fragmentId, int isStartFragment, int isEndFragment, UInt32 fragmentLength, PSETWBinaryBlob fragmentData) { } static internal void LogAnalyticVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } static internal void SetActivityIdForCurrentThread(Guid newActivityId) { } static internal void LogOperationalVerbose(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args){ } static internal void LogOperationalWarning(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args){ } static internal void ReplaceActivityIdForCurrentThread(Guid newActivityId, PSEventId eventForOperationalChannel, PSEventId eventForAnalyticChannel, PSKeyword keyword, PSTask task) { } static internal void LogOperationalError(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args) { } static internal void LogOperationalError(PSEventId id, PSOpcode opcode, PSTask task, LogContext logContext, string payLoad) { } static internal void LogAnalyticInformational(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args){ } static internal void LogOperationalInformation(PSEventId id, PSOpcode opcode, PSTask task, PSKeyword keyword, params object[] args){ } } public enum PowerShellTraceTask { /// /// None /// None = 0, /// /// CreateRunspace /// CreateRunspace = 1, /// /// ExecuteCommand /// ExecuteCommand = 2, /// /// Serialization /// Serialization = 3, /// /// PowerShellConsoleStartup /// PowerShellConsoleStartup = 4, } /// /// Defines Keywords. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1028")] [Flags] public enum PowerShellTraceKeywords : ulong { /// /// None /// None = 0, /// /// Runspace /// Runspace = 0x1, /// /// Pipeline /// Pipeline = 0x2, /// /// Protocol /// Protocol = 0x4, /// /// Transport /// Transport = 0x8, /// /// Host /// Host = 0x10, /// /// Cmdlets /// Cmdlets = 0x20, /// /// Serializer /// Serializer = 0x40, /// /// Session /// Session = 0x80, /// /// ManagedPlugIn /// ManagedPlugIn = 0x100, /// /// /// UseAlwaysDebug = 0x2000000000000000, /// /// /// UseAlwaysOperational = 0x8000000000000000, /// /// /// UseAlwaysAnalytic = 0x4000000000000000, } public sealed partial class Tracer : System.Management.Automation.Tracing.EtwActivity { static Tracer() {} public void EndpointRegistered(string endpointName, string endpointType, string registeredBy) { } public void EndpointUnregistered(string endpointName, string unregisteredBy) { } public void EndpointDisabled(string endpointName, string disabledBy) { } public void EndpointEnabled(string endpointName, string enabledBy) { } public void EndpointModified(string endpointName, string modifiedBy) { } public void BeginContainerParentJobExecution(Guid containerParentJobInstanceId) { } public void BeginProxyJobExecution(Guid proxyJobInstanceId) { } public void ProxyJobRemoteJobAssociation(Guid proxyJobInstanceId, Guid containerParentJobInstanceId) { } public void EndProxyJobExecution(Guid proxyJobInstanceId) { } public void BeginProxyJobEventHandler(Guid proxyJobInstanceId) { } public void EndProxyJobEventHandler(Guid proxyJobInstanceId) { } public void BeginProxyChildJobEventHandler(Guid proxyChildJobInstanceId) { } public void EndContainerParentJobExecution(Guid containerParentJobInstanceId) { } } public sealed class PowerShellTraceSource : IDisposable { internal PowerShellTraceSource(PowerShellTraceTask task, PowerShellTraceKeywords keywords) { } public void Dispose() { } public bool WriteMessage(String message) { return false; } /// /// /// /// /// /// public bool WriteMessage(string message1, string message2) { return false; } /// /// /// /// /// /// public bool WriteMessage(string message, Guid instanceId) { return false; } /// /// /// /// /// /// /// /// /// public void WriteMessage(string className, string methodName, Guid workflowId, string message, params string[] parameters) { return ; } /// /// /// /// /// /// /// /// /// /// public void WriteMessage(string className, string methodName, Guid workflowId, Job job, string message, params string[] parameters) { return; } public bool TraceException(Exception exception) { return false; } } /// /// TraceSourceFactory will return an instance of TraceSource every time GetTraceSource method is called. /// public static class PowerShellTraceSourceFactory { /// /// Returns an instance of BaseChannelWriter. /// If the Etw is not supported by the platform it will return NullWriter.Instance /// /// A Task and a set of Keywords can be specified in the GetTraceSource method (See overloads). /// The supplied task and keywords are used to pass to the Etw provider in case they are /// not defined in the manifest file. /// public static PowerShellTraceSource GetTraceSource() { return new PowerShellTraceSource(PowerShellTraceTask.None, PowerShellTraceKeywords.None); } /// /// Returns an instance of BaseChannelWriter. /// If the Etw is not supported by the platform it will return NullWriter.Instance /// /// A Task and a set of Keywords can be specified in the GetTraceSource method (See overloads). /// The supplied task and keywords are used to pass to the Etw provider in case they are /// not defined in the manifest file. /// public static PowerShellTraceSource GetTraceSource(PowerShellTraceTask task) { return new PowerShellTraceSource(task, PowerShellTraceKeywords.None); } /// /// Returns an instance of BaseChannelWriter. /// If the Etw is not supported by the platform it will return NullWriter.Instance /// /// A Task and a set of Keywords can be specified in the GetTraceSource method (See overloads). /// The supplied task and keywords are used to pass to the Etw provider in case they are /// not defined in the manifest file. /// public static PowerShellTraceSource GetTraceSource(PowerShellTraceTask task, PowerShellTraceKeywords keywords) { return new PowerShellTraceSource(task, keywords); } } } #endif namespace Microsoft.PowerShell.Commands { using System.Management.Automation; /// /// /// public sealed class GetPSSnapinCommand : PSCmdlet { /// /// Name(s) of PSSnapIn(s). /// [Parameter(Position = 0, Mandatory = false)] public string[] Name { get { return _pssnapins; } set { _pssnapins = value; } } private string[] _pssnapins; /// /// /// protected override void EndProcessing() { } } } namespace Microsoft.PowerShell { internal static class NativeCultureResolver { internal static void SetThreadUILanguage(Int16 langId) {} internal static CultureInfo UICulture { get { 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. } } internal static CultureInfo Culture { get { 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. } } } } #endregion TEMPORARY #region Timer namespace System { // Summary: // Provides data for the event that is raised when there is an exception that // is not handled in any application domain. //[Serializable] //[ComVisible(true)] internal class UnhandledExceptionEventArgs : EventArgs { // Summary: // Initializes a new instance of the System.UnhandledExceptionEventArgs class // with the exception object and a common language runtime termination flag. //PS_STUBS_FOR_REMOTE // Parameters: // exception: // The exception that is not handled. // // isTerminating: // true if the runtime is terminating; otherwise, false. public UnhandledExceptionEventArgs(object exception, bool isTerminating) {} // Summary: // Gets the unhandled exception object. // // Returns: // The unhandled exception object. public object ExceptionObject { get { return null; } } // // Summary: // Indicates whether the common language runtime is terminating. // // Returns: // true if the runtime is terminating; otherwise, false. public bool IsTerminating { get { return false; } } } } #endregion Timer #pragma warning restore 1591, 1572, 1571, 1573, 1587, 1570, 0067 #endif