/// <summary> /// Returns a CultureInfo if and only if one is registered matching IetfLanguageTag /// </summary> /// <exception cref="InvalidOperationException"> /// There is no registered CultureInfo with given IetfLanguageTag. /// </exception> public CultureInfo GetEquivalentCulture() { if (_equivalentCulture == null) { string lowerCaseTag = _lowerCaseTag; // xml:lang="und" // see http://www.w3.org/International/questions/qa-no-language // // Just treat it the same as xml:lang="" if (String.CompareOrdinal(lowerCaseTag, "und") == 0) { lowerCaseTag = String.Empty; } try { // Even if we previously failed to find an EquivalentCulture, we retry, if only to // capture inner exception. _equivalentCulture = SafeSecurityHelper.GetCultureInfoByIetfLanguageTag(lowerCaseTag); } catch (ArgumentException e) { _equivalentCultureFailed = true; throw new InvalidOperationException(SR.Get(SRID.XmlLangGetCultureFailure, lowerCaseTag), e); } } return(_equivalentCulture); }
/// <summary> /// This is the method that responds to the MouseEvent event. /// </summary> /// <param name="e"></param> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (IsDragging) { if (e.MouseDevice.LeftButton == MouseButtonState.Pressed) { Point thumbCoordPosition = e.GetPosition(this); // Get client point then convert to screen point Point screenCoordPosition = SafeSecurityHelper.ClientToScreen(this, thumbCoordPosition); // We will fire DragDelta event only when the mouse is really moved if (screenCoordPosition != _previousScreenCoordPosition) { _previousScreenCoordPosition = screenCoordPosition; e.Handled = true; RaiseEvent(new DragDeltaEventArgs(thumbCoordPosition.X - _originThumbPoint.X, thumbCoordPosition.Y - _originThumbPoint.Y)); } } else { if (e.MouseDevice.Captured == this) { ReleaseMouseCapture(); } ClearValue(IsDraggingPropertyKey); _originThumbPoint.X = 0; _originThumbPoint.Y = 0; } } }
internal CultureInfo GetCompatibleCulture() { if (_compatibleCulture == null) { CultureInfo culture = null; if (!TryGetEquivalentCulture(out culture)) { string languageTag = IetfLanguageTag; do { languageTag = Shorten(languageTag); if (languageTag == null) { // Should never happen, because GetCultureinfoByIetfLanguageTag("") should // return InvariantCulture! culture = CultureInfo.InvariantCulture; } else { try { culture = SafeSecurityHelper.GetCultureInfoByIetfLanguageTag(languageTag); } catch (ArgumentException) { } } } while (culture == null); } _compatibleCulture = culture; } return(_compatibleCulture); }
/// <summary>Provides class handling for the <see cref="E:System.Windows.UIElement.MouseMove" /> event. </summary> /// <param name="e">The event data.</param> // Token: 0x060060C2 RID: 24770 RVA: 0x001B1D40 File Offset: 0x001AFF40 protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (this.IsDragging) { if (e.MouseDevice.LeftButton == MouseButtonState.Pressed) { Point position = e.GetPosition(this); Point point = SafeSecurityHelper.ClientToScreen(this, position); if (point != this._previousScreenCoordPosition) { this._previousScreenCoordPosition = point; e.Handled = true; base.RaiseEvent(new DragDeltaEventArgs(position.X - this._originThumbPoint.X, position.Y - this._originThumbPoint.Y)); return; } } else { if (e.MouseDevice.Captured == this) { base.ReleaseMouseCapture(); } base.ClearValue(Thumb.IsDraggingPropertyKey); this._originThumbPoint.X = 0.0; this._originThumbPoint.Y = 0.0; } } }
/// <summary> /// Updates the IsLoadedCache on the current FrameworkElement /// </summary> private static void UpdateIsLoadedCache( FrameworkElement fe, DependencyObject parent) { if (fe.GetValue(FrameworkElement.LoadedPendingProperty) == null) { // Propagate the change to your visual ancestry if (parent != null) { fe.IsLoadedCache = IsLoadedHelper(parent); } // This is the root visual. else if (SafeSecurityHelper.IsConnectedToPresentationSource(fe)) { fe.IsLoadedCache = true; } else { fe.IsLoadedCache = false; } } else { // Clear the cache if Loaded is pending fe.IsLoadedCache = false; } }
internal static Assembly GetLoadedAssembly(string assemblyName, string assemblyVersion, string assemblyKey) { Assembly assembly; AssemblyName asmName = new AssemblyName(assemblyName); // We always use the primary assembly (culture neutral) for resource manager. // if the required resource lives in satellite assembly, ResourceManager can find // the right satellite assembly later. asmName.CultureInfo = new CultureInfo(String.Empty); if (!String.IsNullOrEmpty(assemblyVersion)) { asmName.Version = new Version(assemblyVersion); } byte[] keyToken = ParseAssemblyKey(assemblyKey); if (keyToken != null) { asmName.SetPublicKeyToken(keyToken); } assembly = SafeSecurityHelper.GetLoadedAssembly(asmName); if (assembly == null) { // The assembly is not yet loaded to the AppDomain, try to load it with information specified in resource Uri. assembly = Assembly.Load(asmName); } return(assembly); }
static internal bool IsComponentEntryAssembly(string component) { if (component.EndsWith(COMPONENT, StringComparison.OrdinalIgnoreCase)) { string[] assemblyInfo = component.Split(new Char[] { COMPONENT_DELIMITER }); // Check whether the assembly name is the same as the EntryAssembly. int count = assemblyInfo.Length; if ((count >= 2) && (count <= 4)) { string assemblyName = Uri.UnescapeDataString(assemblyInfo[0]); Assembly assembly = ResourceAssembly; if (assembly != null) { return(String.Compare(SafeSecurityHelper.GetAssemblyPartialName(assembly), assemblyName, StringComparison.OrdinalIgnoreCase) == 0); } else { return(false); } } } return(false); }
private static bool AssemblyMatchesKeyString(AssemblyName asmName, string assemblyKey) { byte[] parsedKeyToken = ParseAssemblyKey(assemblyKey); byte[] assemblyKeyToken = asmName.GetPublicKeyToken(); return(SafeSecurityHelper.IsSameKeyToken(assemblyKeyToken, parsedKeyToken)); }
public DocumentsTrace(string switchName) { #if DEBUG string name = SafeSecurityHelper.GetAssemblyPartialName(Assembly.GetCallingAssembly()); _switch = new BooleanSwitch(switchName, "[" + name + "]"); #endif }
/// <summary> /// This is the method that responds to the MouseButtonEvent event. /// </summary> /// <param name="e"></param> protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (!IsDragging) { e.Handled = true; Focus(); CaptureMouse(); SetValue(IsDraggingPropertyKey, true); _originThumbPoint = e.GetPosition(this); _previousScreenCoordPosition = _originScreenCoordPosition = SafeSecurityHelper.ClientToScreen(this, _originThumbPoint); bool exceptionThrown = true; try { RaiseEvent(new DragStartedEventArgs(_originThumbPoint.X, _originThumbPoint.Y)); exceptionThrown = false; } finally { if (exceptionThrown) { CancelDrag(); } } } else { // This is weird, Thumb shouldn't get MouseLeftButtonDown event while dragging. // This may be the case that something ate MouseLeftButtonUp event, so Thumb never had a chance to // reset IsDragging property Debug.Assert(false, "Got MouseLeftButtonDown event while dragging!"); } base.OnMouseLeftButtonDown(e); }
/// <summary> /// Returns a specific culture given an arbitrary CultureInfo, which may be null, the invariant /// culture, or a neutral culture. /// </summary> public static CultureInfo GetSpecificCulture(CultureInfo runCulture) { // Assume default culture unless we can do better. CultureInfo specificCulture = TypeConverterHelper.InvariantEnglishUS; if (runCulture != null) { // Assign _cachedCultureMap to a local variable for thread safety. The reference assignment // is atomic and the CachedCultureMap class is immutable. CachedCultureMap cachedCultureMap = _cachedCultureMap; if (cachedCultureMap != null && object.ReferenceEquals(cachedCultureMap.OriginalCulture, runCulture)) { return(cachedCultureMap.SpecificCulture); } // Unfortunately we cannot use reference comparison here because, for example, new CultureInfo("") // creates an invariant culture which (being a new object) is obviously not the same instance as // CultureInfo.InvariantCulture. if (runCulture != CultureInfo.InvariantCulture) { if (!runCulture.IsNeutralCulture) { // It's already a specific culture (neither neutral nor InvariantCulture) specificCulture = runCulture; } else { // Get the culture name. Note that the string expected by CreateSpecificCulture corresponds // to the Name property, not IetfLanguageTag, so that's what we use. string cultureName = runCulture.Name; if (!string.IsNullOrEmpty(cultureName)) { try { CultureInfo culture = CultureInfo.CreateSpecificCulture(cultureName); specificCulture = SafeSecurityHelper.GetCultureInfoByIetfLanguageTag(culture.IetfLanguageTag); } catch (ArgumentException) { // This exception occurs if the culture name is invalid or has no corresponding specific // culture. we can safely ignore the exception and fall back to TypeConverterHelper.InvariantEnglishUS. specificCulture = TypeConverterHelper.InvariantEnglishUS; } } } } // Save the mapping so the next call will be fast if we're given the same runCulture. // Again, the reference assignment is atomic so this is thread safe. _cachedCultureMap = new CachedCultureMap(runCulture, specificCulture); } return(specificCulture); }
public static void SafeSecurityTest() { var sss = "asdfa"; var yy = SafeSecurityHelper.Sha1(sss); sss = "我的"; yy = SafeSecurityHelper.Sha1(sss); sss = "我的"; Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); yy = SafeSecurityHelper.Md5Encrypt(sss, Encoding.GetEncoding("GB2312")); }
/// <summary> /// This is the method that responds to the MouseButtonEvent event. /// </summary> /// <param name="e"></param> protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { if (IsMouseCaptured && IsDragging) { e.Handled = true; ClearValue(IsDraggingPropertyKey); ReleaseMouseCapture(); Point pt = SafeSecurityHelper.ClientToScreen(this, e.MouseDevice.GetPosition(this)); RaiseEvent(new DragCompletedEventArgs(pt.X - _originScreenCoordPosition.X, pt.Y - _originScreenCoordPosition.Y, false)); } base.OnMouseLeftButtonUp(e); }
private void CheckMediaDisabledFlags() { if (SafeSecurityHelper.IsFeatureDisabled(SafeSecurityHelper.KeyToRead.MediaAudioOrVideoDisable)) { // in case the registry key is '1' then demand //Demand media permission here for Video or Audio // Issue: 1232606 need to fix once clr has the media permissions SecurityHelper.DemandMediaPermission(MediaPermissionAudio.AllAudio, MediaPermissionVideo.AllVideo, MediaPermissionImage.NoImage); } }
private static void EnsureScriptInteropAllowed() { if (BrowserInteropHelper._isScriptInteropDisabled.Value == null) { BrowserInteropHelper._isScriptInteropDisabled.Value = new bool?(SafeSecurityHelper.IsFeatureDisabled(SafeSecurityHelper.KeyToRead.ScriptInteropDisable)); } if (BrowserInteropHelper._isScriptInteropDisabled.Value.Value) { SecurityHelper.DemandWebBrowserPermission(); return; } new WebBrowserPermission(WebBrowserPermissionLevel.Safe).Demand(); }
private static Assembly LoadAssemblyHelper(string assemblyGivenName, string assemblyPath) { AssemblyName assemblyName = new AssemblyName(assemblyGivenName); string name = assemblyName.Name; name = name.ToUpper(CultureInfo.InvariantCulture); Assembly assembly = (Assembly)_loadedAssembliesHash[name]; if (assembly != null) { if (assemblyName.Version != null) { AssemblyName assemblyName2 = new AssemblyName(assembly.FullName); if (!AssemblyName.ReferenceMatchesDefinition(assemblyName, assemblyName2)) { string text = assemblyName.ToString(); string text2 = assemblyName2.ToString(); throw new InvalidOperationException(SR.Get("ParserAssemblyLoadVersionMismatch", text, text2)); } } } else { if (string.IsNullOrEmpty(assemblyPath)) { assembly = SafeSecurityHelper.GetLoadedAssembly(assemblyName); } if (assembly == null) { if (string.IsNullOrEmpty(assemblyPath)) { try { assembly = Assembly.Load(assemblyGivenName); } catch (FileNotFoundException) { assembly = null; } } else { assembly = Assembly.LoadFile(assemblyPath); } } if (assembly != null) { _loadedAssembliesHash[name] = assembly; } } return(assembly); }
public WebBrowser() : base(new Guid("8856f961-340a-11d0-a96b-00c04fd705a2"), true) { if (SafeSecurityHelper.IsFeatureDisabled(SafeSecurityHelper.KeyToRead.WebBrowserDisable)) { SecurityHelper.DemandWebBrowserPermission(); } else { new WebBrowserPermission(WebBrowserPermissionLevel.Safe).Demand(); } if (WebBrowser.IsWebOCPermissionRestricted) { base.Loaded += this.LoadedHandler; } this._hostingAdaptor = (WebBrowser.IsWebOCHostedInBrowserProcess ? new WebBrowser.WebOCHostedInBrowserAdaptor(this) : new WebBrowser.WebOCHostingAdaptor(this)); }
// Get bounding rectangle, relative to screen internal static Rect GetScreenRect(IntPtr hwnd, UIElement el) { Rect rc = GetLocalRect(el); // Map from local to screen coords... NativeMethods.RECT rcWin32 = new NativeMethods.RECT((int)rc.Left, (int)rc.Top, (int)rc.Right, (int)rc.Bottom); try { SafeSecurityHelper.TransformLocalRectToScreen(new HandleRef(null, hwnd), ref rcWin32); } catch (System.ComponentModel.Win32Exception) { return(Rect.Empty); } rc = new Rect(rcWin32.left, rcWin32.top, rcWin32.right - rcWin32.left, rcWin32.bottom - rcWin32.top); return(rc); }
// Token: 0x06000319 RID: 793 RVA: 0x00008CA5 File Offset: 0x00006EA5 private static void UpdateIsLoadedCache(FrameworkElement fe, DependencyObject parent) { if (fe.GetValue(FrameworkElement.LoadedPendingProperty) != null) { fe.IsLoadedCache = false; return; } if (parent != null) { fe.IsLoadedCache = BroadcastEventHelper.IsLoadedHelper(parent); return; } if (SafeSecurityHelper.IsConnectedToPresentationSource(fe)) { fe.IsLoadedCache = true; return; } fe.IsLoadedCache = false; }
internal static bool IsComponentEntryAssembly(string component) { if (component.EndsWith(";component", StringComparison.OrdinalIgnoreCase)) { string[] array = component.Split(';'); int num = array.Length; if (num >= 2 && num <= 4) { string strB = Uri.UnescapeDataString(array[0]); Assembly resourceAssembly = ResourceAssembly; if (resourceAssembly != null) { return(string.Compare(SafeSecurityHelper.GetAssemblyPartialName(resourceAssembly), strB, StringComparison.OrdinalIgnoreCase) == 0); } return(false); } } return(false); }
/// <summary> /// Finds the most-closely-related non-neutral registered CultureInfo, if one is available. /// </summary> /// <returns> /// A non-Neutral CultureInfo. /// </returns> /// <exception cref="InvalidOperationException"> /// There is no related non-Neutral CultureInfo registered. /// </exception> /// <remarks> /// Will return CultureInfo.InvariantCulture if-and-only-if this.Equals(XmlLanguage.Empty). /// Finds the registered CultureInfo matching the longest-possible prefix of this XmlLanguage. /// If that registered CultureInfo is Neutral, then relies on /// CultureInfo.CreateSpecificCulture() to map from a Neutral CultureInfo to a Specific one. /// </remarks> public CultureInfo GetSpecificCulture() { if (_specificCulture == null) { if (_lowerCaseTag.Length == 0 || String.CompareOrdinal(_lowerCaseTag, "und") == 0) { _specificCulture = GetEquivalentCulture(); } else { CultureInfo culture = GetCompatibleCulture(); if (culture.IetfLanguageTag.Length == 0) { throw new InvalidOperationException(SR.Get(SRID.XmlLangGetSpecificCulture, _lowerCaseTag)); } if (!culture.IsNeutralCulture) { _specificCulture = culture; } else { try { // note that it's important that we use culture.Name, not culture.IetfLanguageTag, here culture = CultureInfo.CreateSpecificCulture(culture.Name); _specificCulture = SafeSecurityHelper.GetCultureInfoByIetfLanguageTag(culture.IetfLanguageTag); } catch (ArgumentException e) { throw new InvalidOperationException(SR.Get(SRID.XmlLangGetSpecificCulture, _lowerCaseTag), e); } } } } return(_specificCulture); }
internal static Assembly GetLoadedAssembly(string assemblyName, string assemblyVersion, string assemblyKey) { Assembly assembly; AssemblyName asmName = new AssemblyName(assemblyName); // We always use the primary assembly (culture neutral) for resource manager. // if the required resource lives in satellite assembly, ResourceManager can find // the right satellite assembly later. asmName.CultureInfo = new CultureInfo(String.Empty); if (!String.IsNullOrEmpty(assemblyVersion)) { asmName.Version = new Version(assemblyVersion); } if (!String.IsNullOrEmpty(assemblyKey)) { int byteCount = assemblyKey.Length / 2; byte[] keyToken = new byte[byteCount]; for (int i = 0; i < byteCount; i++) { string byteString = assemblyKey.Substring(i * 2, 2); keyToken[i] = byte.Parse(byteString, NumberStyles.HexNumber, CultureInfo.InvariantCulture); } asmName.SetPublicKeyToken(keyToken); } assembly = SafeSecurityHelper.GetLoadedAssembly(asmName); if (assembly == null) { // The assembly is not yet loaded to the AppDomain, try to load it with information specified in resource Uri. assembly = Assembly.Load(asmName); } return(assembly); }
// Helper method that recursively queries the parents to see if they are loaded. // This method is invoked only when the loaded cache on the given node isn't valid. internal static bool IsParentLoaded(DependencyObject d) { FrameworkObject fo = new FrameworkObject(d); DependencyObject parent = fo.EffectiveParent; Visual visual; Visual3D visual3D; if (parent != null) { return(IsLoadedHelper(parent)); } else if ((visual = d as Visual) != null) { // If parent is null then this is the root element return(SafeSecurityHelper.IsConnectedToPresentationSource(visual)); } else if ((visual3D = d as Visual3D) != null) { // IsConnectedToPresentationSource could also be modified to take // a DO - instead though we'll just get the containing visual2D for // this 3D object. visual = VisualTreeHelper.GetContainingVisual2D(visual3D); if (visual != null) { return(SafeSecurityHelper.IsConnectedToPresentationSource(visual)); } else { return(false); } } else { return(false); } }
internal static Assembly GetLoadedAssembly(string assemblyName, string assemblyVersion, string assemblyKey) { AssemblyName assemblyName2 = new AssemblyName(assemblyName) { CultureInfo = new CultureInfo(string.Empty) }; if (!string.IsNullOrEmpty(assemblyVersion)) { assemblyName2.Version = new Version(assemblyVersion); } byte[] array = ParseAssemblyKey(assemblyKey); if (array != null) { assemblyName2.SetPublicKeyToken(array); } Assembly assembly = SafeSecurityHelper.GetLoadedAssembly(assemblyName2); if (assembly == null) { assembly = Assembly.Load(assemblyName2); } return(assembly); }
// Token: 0x06000312 RID: 786 RVA: 0x000089EC File Offset: 0x00006BEC internal static bool IsParentLoaded(DependencyObject d) { FrameworkObject frameworkObject = new FrameworkObject(d); DependencyObject effectiveParent = frameworkObject.EffectiveParent; if (effectiveParent != null) { return(BroadcastEventHelper.IsLoadedHelper(effectiveParent)); } Visual visual; if ((visual = (d as Visual)) != null) { return(SafeSecurityHelper.IsConnectedToPresentationSource(visual)); } Visual3D reference; if ((reference = (d as Visual3D)) != null) { visual = VisualTreeHelper.GetContainingVisual2D(reference); return(visual != null && SafeSecurityHelper.IsConnectedToPresentationSource(visual)); } return(false); }
public MediaTrace(string switchName) { _switch = new BooleanSwitch(switchName, "[" + SafeSecurityHelper.GetAssemblyPartialName(Assembly.GetCallingAssembly()) + "]"); }
// Loads the Assembly with the specified name at the specified optional location. // // assemblyName is either short name or full name. // assemblyPath is either full file path or null. // private static Assembly LoadAssemblyHelper(string assemblyGivenName, string assemblyPath) { AssemblyName assemblyName = new AssemblyName(assemblyGivenName); string assemblyShortName = assemblyName.Name; assemblyShortName = assemblyShortName.ToUpper(CultureInfo.InvariantCulture); // Check if the assembly has already been loaded. Assembly retassem = (Assembly)_loadedAssembliesHash[assemblyShortName]; if (retassem != null) { if (assemblyName.Version != null) { AssemblyName cachedName = new AssemblyName(retassem.FullName); if (!AssemblyName.ReferenceMatchesDefinition(assemblyName, cachedName)) { string request = assemblyName.ToString(); string found = cachedName.ToString(); throw new InvalidOperationException(SR.Get(SRID.ParserAssemblyLoadVersionMismatch, request, found)); } } } else { // Check if the current AppDomain has this assembly loaded for some other reason. // If so, then just use that assembly and don't attempt to load another copy of it. // Only do this if no path is provided. if (String.IsNullOrEmpty(assemblyPath)) { retassem = SafeSecurityHelper.GetLoadedAssembly(assemblyName); } if (retassem == null) { if (!String.IsNullOrEmpty(assemblyPath)) { // assemblyPath is set, Load the assembly from this specified place. // the path must be full file path which contains directory, file name and extension. Debug.Assert(!assemblyPath.EndsWith("\\", StringComparison.Ordinal), "the assembly path should be a full file path containing file extension"); // LoadFile will only override your request only if it is in the GAC retassem = Assembly.LoadFile(assemblyPath); } // // At compile time, the build task should always pass the full path of the referenced assembly, even if it // comes from GAC. But below code snippet can run if parser wants to try loading an assembly w/o a path. // This also makes run-time assembly load consistent with compile-time semantics. else { try { retassem = Assembly.Load(assemblyGivenName); } catch (System.IO.FileNotFoundException) { // This may be a locally defined assembly that has not been created yet. // To support these cases, just set a null assembly and return. This // will fail downstream if it really was an assembly miss. retassem = null; } } } // Cache the assembly if (retassem != null) { _loadedAssembliesHash[assemblyShortName] = retassem; } } return(retassem); }
/// <summary>Provides class handling for the <see cref="E:System.Windows.ContentElement.MouseLeftButtonDown" /> event. </summary> /// <param name="e">The event data.</param> // Token: 0x060060BF RID: 24767 RVA: 0x001B1BF0 File Offset: 0x001AFDF0 protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { if (!this.IsDragging) { e.Handled = true; base.Focus(); base.CaptureMouse(); base.SetValue(Thumb.IsDraggingPropertyKey, true); this._originThumbPoint = e.GetPosition(this); this._previousScreenCoordPosition = (this._originScreenCoordPosition = SafeSecurityHelper.ClientToScreen(this, this._originThumbPoint)); bool flag = true; try { base.RaiseEvent(new DragStartedEventArgs(this._originThumbPoint.X, this._originThumbPoint.Y)); flag = false; } finally { if (flag) { this.CancelDrag(); } } } base.OnMouseLeftButtonDown(e); }