// Looks up a .resources file in the assembly manifest using // case-insensitive lookup rules. Yes, this is slow. The metadata // dev lead refuses to make all assembly manifest resource lookups case-insensitive, // even optionally case-insensitive. private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, string name) { Debug.Assert(satellite != null, "satellite shouldn't be null; check caller"); Debug.Assert(name != null, "name shouldn't be null; check caller"); string nameSpace = _mediator.LocationInfo?.Namespace; string delimiter = (nameSpace != null && name != null) ? Type.Delimiter.ToString() : null; string resourceName = string.Concat(nameSpace, delimiter, name); string canonicalName = null; foreach (string existingName in satellite.GetManifestResourceNames()) { if (string.Equals(existingName, resourceName, StringComparison.InvariantCultureIgnoreCase)) { if (canonicalName == null) { canonicalName = existingName; } else { throw new MissingManifestResourceException(SR.Format(SR.MissingManifestResource_MultipleBlobs, resourceName, satellite.ToString())); } } } if (canonicalName == null) { return(null); } return(satellite.GetManifestResourceStream(canonicalName)); }
private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, string name) { StringBuilder builder = new StringBuilder(); if (this._mediator.LocationInfo != null) { string str = this._mediator.LocationInfo.Namespace; if (str != null) { builder.Append(str); if (name != null) { builder.Append(Type.Delimiter); } } } builder.Append(name); string str2 = builder.ToString(); CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo; string str3 = null; foreach (string str4 in satellite.GetManifestResourceNames()) { if (compareInfo.Compare(str4, str2, CompareOptions.IgnoreCase) == 0) { if (str3 != null) { throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_MultipleBlobs", new object[] { str2, satellite.ToString() })); } str3 = str4; } } if (FrameworkEventSource.IsInitialized) { if (str3 != null) { FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), str2); } else { FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupFailed(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), str2); } } if (str3 == null) { return(null); } bool skipSecurityCheck = (this._mediator.MainAssembly == satellite) && (this._mediator.CallingAssembly == this._mediator.MainAssembly); StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; Stream stream = satellite.GetManifestResourceStream(str3, ref lookForMyCaller, skipSecurityCheck); if ((stream != null) && FrameworkEventSource.IsInitialized) { FrameworkEventSource.Log.ResourceManagerManifestResourceAccessDenied(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), str3); } return(stream); }
private Stream GetManifestResourceStream(RuntimeAssembly satellite, string fileName, ref StackCrawlMark stackMark) { bool skipSecurityCheck = (this._mediator.MainAssembly == satellite) && (this._mediator.CallingAssembly == this._mediator.MainAssembly); Stream stream = satellite.GetManifestResourceStream(this._mediator.LocationInfo, fileName, skipSecurityCheck, ref stackMark); if (stream == null) { stream = this.CaseInsensitiveManifestResourceStreamLookup(satellite, fileName); } return(stream); }
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, String name) { Contract.Requires(satellite != null, "satellite shouldn't be null; check caller"); Contract.Requires(name != null, "name shouldn't be null; check caller"); StringBuilder sb = new StringBuilder(); if (_mediator.LocationInfo != null) { String nameSpace = _mediator.LocationInfo.Namespace; if (nameSpace != null) { sb.Append(nameSpace); if (name != null) { sb.Append(Type.Delimiter); } } } sb.Append(name); String givenName = sb.ToString(); CompareInfo comparer = CultureInfo.InvariantCulture.CompareInfo; String canonicalName = null; foreach (String existingName in satellite.GetManifestResourceNames()) { if (comparer.Compare(existingName, givenName, CompareOptions.IgnoreCase) == 0) { if (canonicalName == null) { canonicalName = existingName; } else { throw new MissingManifestResourceException(SR.Format(SR.MissingManifestResource_MultipleBlobs, givenName, satellite.ToString())); } } } if (canonicalName == null) { return(null); } // If we're looking in the main assembly AND if the main // assembly was the person who created the ResourceManager, // skip a security check for private manifest resources. bool canSkipSecurityCheck = _mediator.MainAssembly == satellite && _mediator.CallingAssembly == _mediator.MainAssembly; StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(satellite.GetManifestResourceStream(canonicalName, ref stackMark, canSkipSecurityCheck)); }
private Stream GetManifestResourceStream(RuntimeAssembly satellite, string fileName) { Debug.Assert(satellite != null, "satellite shouldn't be null; check caller"); Debug.Assert(fileName != null, "fileName shouldn't be null; check caller"); Stream stream = satellite.GetManifestResourceStream(_mediator.LocationInfo, fileName); if (stream == null) { stream = CaseInsensitiveManifestResourceStreamLookup(satellite, fileName); } return(stream); }
private Stream GetManifestResourceStream(RuntimeAssembly satellite, string fileName, ref StackCrawlMark stackMark) { Debug.Assert(satellite != null, "satellite shouldn't be null; check caller"); Debug.Assert(fileName != null, "fileName shouldn't be null; check caller"); // If we're looking in the main assembly AND if the main assembly was the person who // created the ResourceManager, skip a security check for private manifest resources. bool canSkipSecurityCheck = (_mediator.MainAssembly == satellite) && (_mediator.CallingAssembly == _mediator.MainAssembly); Stream stream = satellite.GetManifestResourceStream(_mediator.LocationInfo, fileName, canSkipSecurityCheck, ref stackMark); if (stream == null) { stream = CaseInsensitiveManifestResourceStreamLookup(satellite, fileName); } return(stream); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, String name) { Contract.Requires(satellite != null, "satellite shouldn't be null; check caller"); Contract.Requires(name != null, "name shouldn't be null; check caller"); StringBuilder sb = new StringBuilder(); if (_mediator.LocationInfo != null) { String nameSpace = _mediator.LocationInfo.Namespace; if (nameSpace != null) { sb.Append(nameSpace); if (name != null) { sb.Append(Type.Delimiter); } } } sb.Append(name); String givenName = sb.ToString(); CompareInfo comparer = CultureInfo.InvariantCulture.CompareInfo; String canonicalName = null; foreach (String existingName in satellite.GetManifestResourceNames()) { if (comparer.Compare(existingName, givenName, CompareOptions.IgnoreCase) == 0) { if (canonicalName == null) { canonicalName = existingName; } else { throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_MultipleBlobs", givenName, satellite.ToString())); } } } #if !FEATURE_CORECLR if (FrameworkEventSource.IsInitialized) { if (canonicalName != null) { FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), givenName); } else { FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupFailed(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), givenName); } } #endif if (canonicalName == null) { return(null); } // If we're looking in the main assembly AND if the main // assembly was the person who created the ResourceManager, // skip a security check for private manifest resources. bool canSkipSecurityCheck = _mediator.MainAssembly == satellite && _mediator.CallingAssembly == _mediator.MainAssembly; StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Stream s = satellite.GetManifestResourceStream(canonicalName, ref stackMark, canSkipSecurityCheck); // GetManifestResourceStream will return null if we don't have // permission to read this stream from the assembly. For example, // if the stream is private and we're trying to access it from another // assembly (ie, ResMgr in mscorlib accessing anything else), we // require Reflection TypeInformation permission to be able to read // this. <STRIP>This meaning of private in satellite assemblies is a really // odd concept, and is orthogonal to the ResourceManager. // We should not assume we can skip this security check, // which means satellites must always use public manifest resources // if you want to support semi-trusted code. </STRIP> #if !FEATURE_CORECLR if (s != null) { if (FrameworkEventSource.IsInitialized) { FrameworkEventSource.Log.ResourceManagerManifestResourceAccessDenied(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), canonicalName); } } #endif return(s); }
private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, string name) { StringBuilder stringBuilder = new StringBuilder(); if (this._mediator.LocationInfo != (Type)null) { string @namespace = this._mediator.LocationInfo.Namespace; if (@namespace != null) { stringBuilder.Append(@namespace); if (name != null) { stringBuilder.Append(Type.Delimiter); } } } stringBuilder.Append(name); string @string = stringBuilder.ToString(); CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo; string str = (string)null; foreach (string manifestResourceName in satellite.GetManifestResourceNames()) { if (compareInfo.Compare(manifestResourceName, @string, CompareOptions.IgnoreCase) == 0) { if (str == null) { str = manifestResourceName; } else { throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_MultipleBlobs", (object)@string, (object)satellite.ToString())); } } } if (FrameworkEventSource.IsInitialized) { if (str != null) { FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(this._mediator.BaseName, (Assembly)this._mediator.MainAssembly, satellite.GetSimpleName(), @string); } else { FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupFailed(this._mediator.BaseName, (Assembly)this._mediator.MainAssembly, satellite.GetSimpleName(), @string); } } if (str == null) { return((Stream)null); } bool skipSecurityCheck = (Assembly)this._mediator.MainAssembly == (Assembly)satellite && (Assembly)this._mediator.CallingAssembly == (Assembly)this._mediator.MainAssembly; StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; Stream manifestResourceStream = satellite.GetManifestResourceStream(str, ref stackMark, skipSecurityCheck); if (manifestResourceStream == null || !FrameworkEventSource.IsInitialized) { return(manifestResourceStream); } FrameworkEventSource.Log.ResourceManagerManifestResourceAccessDenied(this._mediator.BaseName, (Assembly)this._mediator.MainAssembly, satellite.GetSimpleName(), str); return(manifestResourceStream); }
private Stream GetManifestResourceStream(RuntimeAssembly satellite, string fileName, ref StackCrawlMark stackMark) { bool skipSecurityCheck = (Assembly)this._mediator.MainAssembly == (Assembly)satellite && (Assembly)this._mediator.CallingAssembly == (Assembly)this._mediator.MainAssembly; return(satellite.GetManifestResourceStream(this._mediator.LocationInfo, fileName, skipSecurityCheck, ref stackMark) ?? this.CaseInsensitiveManifestResourceStreamLookup(satellite, fileName)); }
private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, string name) { StringBuilder stringBuilder = new StringBuilder(); if (this._mediator.LocationInfo != null) { string @namespace = this._mediator.LocationInfo.Namespace; if (@namespace != null) { stringBuilder.Append(@namespace); if (name != null) { stringBuilder.Append(Type.Delimiter); } } } stringBuilder.Append(name); string text = stringBuilder.ToString(); CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo; string text2 = null; foreach (string text3 in satellite.GetManifestResourceNames()) { if (compareInfo.Compare(text3, text, CompareOptions.IgnoreCase) == 0) { if (text2 != null) { throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_MultipleBlobs", new object[] { text, satellite.ToString() })); } text2 = text3; } } if (FrameworkEventSource.IsInitialized) { if (text2 != null) { FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), text); } else { FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupFailed(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), text); } } if (text2 == null) { return(null); } bool skipSecurityCheck = this._mediator.MainAssembly == satellite && this._mediator.CallingAssembly == this._mediator.MainAssembly; StackCrawlMark stackCrawlMark = StackCrawlMark.LookForMyCaller; Stream manifestResourceStream = satellite.GetManifestResourceStream(text2, ref stackCrawlMark, skipSecurityCheck); if (manifestResourceStream != null && FrameworkEventSource.IsInitialized) { FrameworkEventSource.Log.ResourceManagerManifestResourceAccessDenied(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), text2); } return(manifestResourceStream); }