mscorlib(4.0.0.0) API with additions
AppDomainSetup.cs
4 using System.IO;
9 using System.Security;
11 using System.Security.Policy;
12 using System.Security.Util;
13 using System.Text;
14 
15 namespace System
16 {
18  [Serializable]
19  [ClassInterface(ClassInterfaceType.None)]
20  [ComVisible(true)]
21  public sealed class AppDomainSetup : IAppDomainSetup
22  {
23  [Serializable]
24  internal enum LoaderInformation
25  {
26  ApplicationBaseValue = 0,
27  ConfigurationFileValue = 1,
28  DynamicBaseValue = 2,
29  DevPathValue = 3,
30  ApplicationNameValue = 4,
31  PrivateBinPathValue = 5,
32  PrivateBinPathProbeValue = 6,
33  ShadowCopyDirectoriesValue = 7,
34  ShadowCopyFilesValue = 8,
35  CachePathValue = 9,
36  LicenseFileValue = 10,
37  DisallowPublisherPolicyValue = 11,
38  DisallowCodeDownloadValue = 12,
39  DisallowBindingRedirectsValue = 13,
40  DisallowAppBaseProbingValue = 14,
41  ConfigurationBytesValue = 0xF,
42  LoaderMaximum = 18
43  }
44 
45  private string[] _Entries;
46 
47  private LoaderOptimization _LoaderOptimization;
48 
49  private string _AppBase;
50 
51  [OptionalField(VersionAdded = 2)]
52  private AppDomainInitializer _AppDomainInitializer;
53 
54  [OptionalField(VersionAdded = 2)]
55  private string[] _AppDomainInitializerArguments;
56 
57  [OptionalField(VersionAdded = 2)]
58  private ActivationArguments _ActivationArguments;
59 
60  [OptionalField(VersionAdded = 2)]
61  private string _ApplicationTrust;
62 
63  [OptionalField(VersionAdded = 2)]
64  private byte[] _ConfigurationBytes;
65 
66  [OptionalField(VersionAdded = 3)]
67  private bool _DisableInterfaceCache;
68 
69  [OptionalField(VersionAdded = 4)]
70  private string _AppDomainManagerAssembly;
71 
72  [OptionalField(VersionAdded = 4)]
73  private string _AppDomainManagerType;
74 
75  [OptionalField(VersionAdded = 4)]
76  private string[] _AptcaVisibleAssemblies;
77 
78  [OptionalField(VersionAdded = 4)]
79  private Dictionary<string, object> _CompatFlags;
80 
81  [OptionalField(VersionAdded = 5)]
82  private string _TargetFrameworkName;
83 
84  [NonSerialized]
85  internal AppDomainSortingSetupInfo _AppDomainSortingSetupInfo;
86 
87  [OptionalField(VersionAdded = 5)]
88  private bool _CheckedForTargetFrameworkName;
89 
90  [OptionalField(VersionAdded = 5)]
91  private bool _UseRandomizedStringHashing;
92 
93  internal string[] Value
94  {
95  get
96  {
97  if (_Entries == null)
98  {
99  _Entries = new string[18];
100  }
101  return _Entries;
102  }
103  }
104 
107  public string AppDomainManagerAssembly
108  {
109  get
110  {
111  return _AppDomainManagerAssembly;
112  }
113  set
114  {
115  _AppDomainManagerAssembly = value;
116  }
117  }
118 
121  public string AppDomainManagerType
122  {
123  get
124  {
125  return _AppDomainManagerType;
126  }
127  set
128  {
129  _AppDomainManagerType = value;
130  }
131  }
132 
135  public string[] PartialTrustVisibleAssemblies
136  {
137  get
138  {
139  return _AptcaVisibleAssemblies;
140  }
141  set
142  {
143  if (value != null)
144  {
145  _AptcaVisibleAssemblies = (string[])value.Clone();
146  Array.Sort(_AptcaVisibleAssemblies, StringComparer.OrdinalIgnoreCase);
147  }
148  else
149  {
150  _AptcaVisibleAssemblies = null;
151  }
152  }
153  }
154 
157  public string ApplicationBase
158  {
159  [SecuritySafeCritical]
160  get
161  {
162  return VerifyDir(GetUnsecureApplicationBase(), normalize: false);
163  }
164  set
165  {
166  Value[0] = NormalizePath(value, useAppBase: false);
167  }
168  }
169 
170  internal static string ApplicationBaseKey => "APPBASE";
171 
174  public string ConfigurationFile
175  {
176  [SecuritySafeCritical]
177  get
178  {
179  return VerifyDir(Value[1], normalize: true);
180  }
181  set
182  {
183  Value[1] = value;
184  }
185  }
186 
187  internal string ConfigurationFileInternal => NormalizePath(Value[1], useAppBase: true);
188 
189  internal static string ConfigurationFileKey => "APP_CONFIG_FILE";
190 
191  private static string ConfigurationBytesKey => "APP_CONFIG_BLOB";
192 
195  public string TargetFrameworkName
196  {
197  get
198  {
199  return _TargetFrameworkName;
200  }
201  set
202  {
203  _TargetFrameworkName = value;
204  }
205  }
206 
207  internal bool CheckedForTargetFrameworkName
208  {
209  get
210  {
211  return _CheckedForTargetFrameworkName;
212  }
213  set
214  {
215  _CheckedForTargetFrameworkName = value;
216  }
217  }
218 
223  public string DynamicBase
224  {
225  [SecuritySafeCritical]
226  get
227  {
228  return VerifyDir(Value[2], normalize: true);
229  }
230  [SecuritySafeCritical]
231  set
232  {
233  if (value == null)
234  {
235  Value[2] = null;
236  return;
237  }
238  if (ApplicationName == null)
239  {
240  throw new MemberAccessException(Environment.GetResourceString("AppDomain_RequireApplicationName"));
241  }
242  StringBuilder stringBuilder = new StringBuilder(NormalizePath(value, useAppBase: false));
243  stringBuilder.Append('\\');
244  string value2 = ParseNumbers.IntToString(ApplicationName.GetLegacyNonRandomizedHashCode(), 16, 8, '0', 256);
245  stringBuilder.Append(value2);
246  Value[2] = stringBuilder.ToString();
247  }
248  }
249 
250  internal static string DynamicBaseKey => "DYNAMIC_BASE";
251 
255  public bool DisallowPublisherPolicy
256  {
257  get
258  {
259  return Value[11] != null;
260  }
261  set
262  {
263  if (value)
264  {
265  Value[11] = "true";
266  }
267  else
268  {
269  Value[11] = null;
270  }
271  }
272  }
273 
277  public bool DisallowBindingRedirects
278  {
279  get
280  {
281  return Value[13] != null;
282  }
283  set
284  {
285  if (value)
286  {
287  Value[13] = "true";
288  }
289  else
290  {
291  Value[13] = null;
292  }
293  }
294  }
295 
299  public bool DisallowCodeDownload
300  {
301  get
302  {
303  return Value[12] != null;
304  }
305  set
306  {
307  if (value)
308  {
309  Value[12] = "true";
310  }
311  else
312  {
313  Value[12] = null;
314  }
315  }
316  }
317 
322  {
323  get
324  {
325  return Value[14] != null;
326  }
327  set
328  {
329  if (value)
330  {
331  Value[14] = "true";
332  }
333  else
334  {
335  Value[14] = null;
336  }
337  }
338  }
339 
340  internal string DeveloperPath
341  {
342  [SecurityCritical]
343  get
344  {
345  string text = Value[3];
346  VerifyDirList(text);
347  return text;
348  }
349  set
350  {
351  if (value == null)
352  {
353  Value[3] = null;
354  return;
355  }
356  string[] array = value.Split(';');
357  int num = array.Length;
358  StringBuilder stringBuilder = StringBuilderCache.Acquire();
359  bool flag = false;
360  for (int i = 0; i < num; i++)
361  {
362  if (array[i].Length != 0)
363  {
364  if (flag)
365  {
366  stringBuilder.Append(";");
367  }
368  else
369  {
370  flag = true;
371  }
372  stringBuilder.Append(Path.GetFullPathInternal(array[i]));
373  }
374  }
375  string stringAndRelease = StringBuilderCache.GetStringAndRelease(stringBuilder);
376  if (stringAndRelease.Length == 0)
377  {
378  Value[3] = null;
379  }
380  else
381  {
382  Value[3] = stringAndRelease;
383  }
384  }
385  }
386 
387  internal static string DisallowPublisherPolicyKey => "DISALLOW_APP";
388 
389  internal static string DisallowCodeDownloadKey => "CODE_DOWNLOAD_DISABLED";
390 
391  internal static string DisallowBindingRedirectsKey => "DISALLOW_APP_REDIRECTS";
392 
393  internal static string DeveloperPathKey => "DEV_PATH";
394 
395  internal static string DisallowAppBaseProbingKey => "DISALLOW_APP_BASE_PROBING";
396 
399  public string ApplicationName
400  {
401  get
402  {
403  return Value[4];
404  }
405  set
406  {
407  Value[4] = value;
408  }
409  }
410 
411  internal static string ApplicationNameKey => "APP_NAME";
412 
415  [XmlIgnoreMember]
417  {
418  get
419  {
420  return _AppDomainInitializer;
421  }
422  set
423  {
424  _AppDomainInitializer = value;
425  }
426  }
427 
430  public string[] AppDomainInitializerArguments
431  {
432  get
433  {
434  return _AppDomainInitializerArguments;
435  }
436  set
437  {
438  _AppDomainInitializerArguments = value;
439  }
440  }
441 
445  [XmlIgnoreMember]
447  {
448  get
449  {
450  return _ActivationArguments;
451  }
452  set
453  {
454  _ActivationArguments = value;
455  }
456  }
457 
462  [XmlIgnoreMember]
464  {
465  get
466  {
467  return InternalGetApplicationTrust();
468  }
469  set
470  {
471  InternalSetApplicationTrust(value);
472  }
473  }
474 
477  public string PrivateBinPath
478  {
479  [SecuritySafeCritical]
480  get
481  {
482  string text = Value[5];
483  VerifyDirList(text);
484  return text;
485  }
486  set
487  {
488  Value[5] = value;
489  }
490  }
491 
492  internal static string PrivateBinPathKey => "PRIVATE_BINPATH";
493 
497  public string PrivateBinPathProbe
498  {
499  get
500  {
501  return Value[6];
502  }
503  set
504  {
505  Value[6] = value;
506  }
507  }
508 
509  internal static string PrivateBinPathProbeKey => "BINPATH_PROBE_ONLY";
510 
513  public string ShadowCopyDirectories
514  {
515  [SecuritySafeCritical]
516  get
517  {
518  string text = Value[7];
519  VerifyDirList(text);
520  return text;
521  }
522  set
523  {
524  Value[7] = value;
525  }
526  }
527 
528  internal static string ShadowCopyDirectoriesKey => "SHADOW_COPY_DIRS";
529 
532  public string ShadowCopyFiles
533  {
534  get
535  {
536  return Value[8];
537  }
538  set
539  {
540  if (value != null && string.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0)
541  {
542  Value[8] = value;
543  }
544  else
545  {
546  Value[8] = null;
547  }
548  }
549  }
550 
551  internal static string ShadowCopyFilesKey => "FORCE_CACHE_INSTALL";
552 
555  public string CachePath
556  {
557  [SecuritySafeCritical]
558  get
559  {
560  return VerifyDir(Value[9], normalize: false);
561  }
562  set
563  {
564  Value[9] = NormalizePath(value, useAppBase: false);
565  }
566  }
567 
568  internal static string CachePathKey => "CACHE_BASE";
569 
572  public string LicenseFile
573  {
574  [SecuritySafeCritical]
575  get
576  {
577  return VerifyDir(Value[10], normalize: true);
578  }
579  set
580  {
581  Value[10] = value;
582  }
583  }
584 
588  {
589  get
590  {
591  return _LoaderOptimization;
592  }
593  set
594  {
595  _LoaderOptimization = value;
596  }
597  }
598 
599  internal static string LoaderOptimizationKey => "LOADER_OPTIMIZATION";
600 
601  internal static string ConfigurationExtension => ".config";
602 
603  internal static string PrivateBinPathEnvironmentVariable => "RELPATH";
604 
605  internal static string RuntimeConfigurationFile => "config\\machine.config";
606 
607  internal static string MachineConfigKey => "MACHINE_CONFIG";
608 
609  internal static string HostBindingKey => "HOST_CONFIG";
610 
614  public bool SandboxInterop
615  {
616  get
617  {
618  return _DisableInterfaceCache;
619  }
620  set
621  {
622  _DisableInterfaceCache = value;
623  }
624  }
625 
626  [SecuritySafeCritical]
627  internal AppDomainSetup(AppDomainSetup copy, bool copyDomainBoundData)
628  {
629  string[] value = Value;
630  if (copy != null)
631  {
632  string[] value2 = copy.Value;
633  int num = _Entries.Length;
634  int num2 = value2.Length;
635  int num3 = (num2 < num) ? num2 : num;
636  for (int i = 0; i < num3; i++)
637  {
638  value[i] = value2[i];
639  }
640  if (num3 < num)
641  {
642  for (int j = num3; j < num; j++)
643  {
644  value[j] = null;
645  }
646  }
647  _LoaderOptimization = copy._LoaderOptimization;
648  _AppDomainInitializerArguments = copy.AppDomainInitializerArguments;
649  _ActivationArguments = copy.ActivationArguments;
650  _ApplicationTrust = copy._ApplicationTrust;
651  if (copyDomainBoundData)
652  {
653  _AppDomainInitializer = copy.AppDomainInitializer;
654  }
655  else
656  {
657  _AppDomainInitializer = null;
658  }
659  _ConfigurationBytes = copy.GetConfigurationBytes();
660  _DisableInterfaceCache = copy._DisableInterfaceCache;
661  _AppDomainManagerAssembly = copy.AppDomainManagerAssembly;
662  _AppDomainManagerType = copy.AppDomainManagerType;
663  _AptcaVisibleAssemblies = copy.PartialTrustVisibleAssemblies;
664  if (copy._CompatFlags != null)
665  {
666  SetCompatibilitySwitches(copy._CompatFlags.Keys);
667  }
668  if (copy._AppDomainSortingSetupInfo != null)
669  {
670  _AppDomainSortingSetupInfo = new AppDomainSortingSetupInfo(copy._AppDomainSortingSetupInfo);
671  }
672  _TargetFrameworkName = copy._TargetFrameworkName;
673  _UseRandomizedStringHashing = copy._UseRandomizedStringHashing;
674  }
675  else
676  {
677  _LoaderOptimization = LoaderOptimization.NotSpecified;
678  }
679  }
680 
682  public AppDomainSetup()
683  {
684  _LoaderOptimization = LoaderOptimization.NotSpecified;
685  }
686 
691  public AppDomainSetup(ActivationContext activationContext)
692  : this(new ActivationArguments(activationContext))
693  {
694  }
695 
700  [SecuritySafeCritical]
701  public AppDomainSetup(ActivationArguments activationArguments)
702  {
703  if (activationArguments == null)
704  {
705  throw new ArgumentNullException("activationArguments");
706  }
707  _LoaderOptimization = LoaderOptimization.NotSpecified;
708  ActivationArguments = activationArguments;
709  string entryPointFullPath = CmsUtils.GetEntryPointFullPath(activationArguments);
710  if (!string.IsNullOrEmpty(entryPointFullPath))
711  {
712  SetupDefaults(entryPointFullPath);
713  }
714  else
715  {
716  ApplicationBase = activationArguments.ActivationContext.ApplicationDirectory;
717  }
718  }
719 
720  internal void SetupDefaults(string imageLocation, bool imageLocationAlreadyNormalized = false)
721  {
722  char[] anyOf = new char[2]
723  {
724  '\\',
725  '/'
726  };
727  int num = imageLocation.LastIndexOfAny(anyOf);
728  if (num == -1)
729  {
730  ApplicationName = imageLocation;
731  }
732  else
733  {
734  ApplicationName = imageLocation.Substring(num + 1);
735  string text = imageLocation.Substring(0, num + 1);
736  if (imageLocationAlreadyNormalized)
737  {
738  Value[0] = text;
739  }
740  else
741  {
742  ApplicationBase = text;
743  }
744  }
745  ConfigurationFile = ApplicationName + ConfigurationExtension;
746  }
747 
748  internal string GetUnsecureApplicationBase()
749  {
750  return Value[0];
751  }
752 
753  [SecuritySafeCritical]
754  private string NormalizePath(string path, bool useAppBase)
755  {
756  if (path == null)
757  {
758  return null;
759  }
760  if (!useAppBase)
761  {
762  path = URLString.PreProcessForExtendedPathRemoval(checkPathLength: false, path, isFileUrl: false);
763  }
764  int num = path.Length;
765  if (num == 0)
766  {
767  return null;
768  }
769  bool flag = false;
770  if (num > 7 && string.Compare(path, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) == 0)
771  {
772  int num2;
773  if (path[6] == '\\')
774  {
775  if (path[7] == '\\' || path[7] == '/')
776  {
777  if (num > 8 && (path[8] == '\\' || path[8] == '/'))
778  {
779  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPathChars"));
780  }
781  num2 = 8;
782  }
783  else
784  {
785  num2 = 5;
786  flag = true;
787  }
788  }
789  else if (path[7] == '/')
790  {
791  num2 = 8;
792  }
793  else
794  {
795  if (num > 8 && path[7] == '\\' && path[8] == '\\')
796  {
797  num2 = 7;
798  }
799  else
800  {
801  num2 = 5;
802  StringBuilder stringBuilder = new StringBuilder(num);
803  for (int i = 0; i < num; i++)
804  {
805  char c = path[i];
806  if (c == '/')
807  {
808  stringBuilder.Append('\\');
809  }
810  else
811  {
812  stringBuilder.Append(c);
813  }
814  }
815  path = stringBuilder.ToString();
816  }
817  flag = true;
818  }
819  path = path.Substring(num2);
820  num -= num2;
821  }
822  bool flag2;
823  if (flag || (num > 1 && (path[0] == '/' || path[0] == '\\') && (path[1] == '/' || path[1] == '\\')))
824  {
825  flag2 = false;
826  }
827  else
828  {
829  int num3 = path.IndexOf(':') + 1;
830  flag2 = ((num3 == 0 || num <= num3 + 1 || (path[num3] != '/' && path[num3] != '\\') || (path[num3 + 1] != '/' && path[num3 + 1] != '\\')) ? true : false);
831  }
832  if (flag2)
833  {
834  if (useAppBase && (num == 1 || path[1] != ':'))
835  {
836  string text = Value[0];
837  if (text == null || text.Length == 0)
838  {
839  throw new MemberAccessException(Environment.GetResourceString("AppDomain_AppBaseNotSet"));
840  }
841  StringBuilder stringBuilder2 = StringBuilderCache.Acquire();
842  bool flag3 = false;
843  if (path[0] == '/' || path[0] == '\\')
844  {
845  string text2 = AppDomain.NormalizePath(text, fullCheck: false);
846  text2 = text2.Substring(0, PathInternal.GetRootLength(text2));
847  if (text2.Length == 0)
848  {
849  int num4 = text.IndexOf(":/", StringComparison.Ordinal);
850  if (num4 == -1)
851  {
852  num4 = text.IndexOf(":\\", StringComparison.Ordinal);
853  }
854  int length = text.Length;
855  for (num4++; num4 < length && (text[num4] == '/' || text[num4] == '\\'); num4++)
856  {
857  }
858  for (; num4 < length && text[num4] != '/' && text[num4] != '\\'; num4++)
859  {
860  }
861  text2 = text.Substring(0, num4);
862  }
863  stringBuilder2.Append(text2);
864  flag3 = true;
865  }
866  else
867  {
868  stringBuilder2.Append(text);
869  }
870  int num5 = stringBuilder2.Length - 1;
871  if (stringBuilder2[num5] != '/' && stringBuilder2[num5] != '\\')
872  {
873  if (!flag3)
874  {
875  if (text.IndexOf(":/", StringComparison.Ordinal) == -1)
876  {
877  stringBuilder2.Append('\\');
878  }
879  else
880  {
881  stringBuilder2.Append('/');
882  }
883  }
884  }
885  else if (flag3)
886  {
887  stringBuilder2.Remove(num5, 1);
888  }
889  stringBuilder2.Append(path);
890  path = StringBuilderCache.GetStringAndRelease(stringBuilder2);
891  }
892  else
893  {
894  path = AppDomain.NormalizePath(path, fullCheck: true);
895  }
896  }
897  return path;
898  }
899 
900  private bool IsFilePath(string path)
901  {
902  if (path[1] != ':')
903  {
904  if (path[0] == '\\')
905  {
906  return path[1] == '\\';
907  }
908  return false;
909  }
910  return true;
911  }
912 
915  public byte[] GetConfigurationBytes()
916  {
917  if (_ConfigurationBytes == null)
918  {
919  return null;
920  }
921  return (byte[])_ConfigurationBytes.Clone();
922  }
923 
926  public void SetConfigurationBytes(byte[] value)
927  {
928  _ConfigurationBytes = value;
929  }
930 
931  internal Dictionary<string, object> GetCompatibilityFlags()
932  {
933  return _CompatFlags;
934  }
935 
939  {
940  if (_AppDomainSortingSetupInfo != null)
941  {
942  _AppDomainSortingSetupInfo._useV2LegacySorting = false;
943  _AppDomainSortingSetupInfo._useV4LegacySorting = false;
944  }
945  _UseRandomizedStringHashing = false;
946  if (switches != null)
947  {
948  _CompatFlags = new Dictionary<string, object>();
949  foreach (string @switch in switches)
950  {
951  if (StringComparer.OrdinalIgnoreCase.Equals("NetFx40_Legacy20SortingBehavior", @switch))
952  {
953  if (_AppDomainSortingSetupInfo == null)
954  {
955  _AppDomainSortingSetupInfo = new AppDomainSortingSetupInfo();
956  }
957  _AppDomainSortingSetupInfo._useV2LegacySorting = true;
958  }
959  if (StringComparer.OrdinalIgnoreCase.Equals("NetFx45_Legacy40SortingBehavior", @switch))
960  {
961  if (_AppDomainSortingSetupInfo == null)
962  {
963  _AppDomainSortingSetupInfo = new AppDomainSortingSetupInfo();
964  }
965  _AppDomainSortingSetupInfo._useV4LegacySorting = true;
966  }
967  if (StringComparer.OrdinalIgnoreCase.Equals("UseRandomizedStringHashAlgorithm", @switch))
968  {
969  _UseRandomizedStringHashing = true;
970  }
971  _CompatFlags.Add(@switch, null);
972  }
973  }
974  else
975  {
976  _CompatFlags = null;
977  }
978  }
979 
989  [SecurityCritical]
990  public void SetNativeFunction(string functionName, int functionVersion, IntPtr functionPointer)
991  {
992  if (functionName == null)
993  {
994  throw new ArgumentNullException("functionName");
995  }
996  if (functionPointer == IntPtr.Zero)
997  {
998  throw new ArgumentNullException("functionPointer");
999  }
1000  if (string.IsNullOrWhiteSpace(functionName))
1001  {
1002  throw new ArgumentException(Environment.GetResourceString("Argument_NPMSInvalidName"), "functionName");
1003  }
1004  if (functionVersion < 1)
1005  {
1006  throw new ArgumentException(Environment.GetResourceString("ArgumentException_MinSortingVersion", 1, functionName));
1007  }
1008  if (_AppDomainSortingSetupInfo == null)
1009  {
1010  _AppDomainSortingSetupInfo = new AppDomainSortingSetupInfo();
1011  }
1012  if (string.Equals(functionName, "IsNLSDefinedString", StringComparison.OrdinalIgnoreCase))
1013  {
1014  _AppDomainSortingSetupInfo._pfnIsNLSDefinedString = functionPointer;
1015  }
1016  if (string.Equals(functionName, "CompareStringEx", StringComparison.OrdinalIgnoreCase))
1017  {
1018  _AppDomainSortingSetupInfo._pfnCompareStringEx = functionPointer;
1019  }
1020  if (string.Equals(functionName, "LCMapStringEx", StringComparison.OrdinalIgnoreCase))
1021  {
1022  _AppDomainSortingSetupInfo._pfnLCMapStringEx = functionPointer;
1023  }
1024  if (string.Equals(functionName, "FindNLSStringEx", StringComparison.OrdinalIgnoreCase))
1025  {
1026  _AppDomainSortingSetupInfo._pfnFindNLSStringEx = functionPointer;
1027  }
1028  if (string.Equals(functionName, "CompareStringOrdinal", StringComparison.OrdinalIgnoreCase))
1029  {
1030  _AppDomainSortingSetupInfo._pfnCompareStringOrdinal = functionPointer;
1031  }
1032  if (string.Equals(functionName, "GetNLSVersionEx", StringComparison.OrdinalIgnoreCase))
1033  {
1034  _AppDomainSortingSetupInfo._pfnGetNLSVersionEx = functionPointer;
1035  }
1036  if (string.Equals(functionName, "FindStringOrdinal", StringComparison.OrdinalIgnoreCase))
1037  {
1038  _AppDomainSortingSetupInfo._pfnFindStringOrdinal = functionPointer;
1039  }
1040  }
1041 
1042  [SecurityCritical]
1043  private string VerifyDir(string dir, bool normalize)
1044  {
1045  if (dir != null)
1046  {
1047  if (dir.Length == 0)
1048  {
1049  dir = null;
1050  }
1051  else
1052  {
1053  if (normalize)
1054  {
1055  dir = NormalizePath(dir, useAppBase: true);
1056  }
1057  if (IsFilePath(dir))
1058  {
1059  new FileIOPermission(FileIOPermissionAccess.PathDiscovery, new string[1]
1060  {
1061  dir
1062  }, checkForDuplicates: false, needFullPath: false).Demand();
1063  }
1064  }
1065  }
1066  return dir;
1067  }
1068 
1069  [SecurityCritical]
1070  private void VerifyDirList(string dirs)
1071  {
1072  if (dirs != null)
1073  {
1074  string[] array = dirs.Split(';');
1075  int num = array.Length;
1076  for (int i = 0; i < num; i++)
1077  {
1078  VerifyDir(array[i], normalize: true);
1079  }
1080  }
1081  }
1082 
1083  internal ApplicationTrust InternalGetApplicationTrust()
1084  {
1085  if (_ApplicationTrust == null)
1086  {
1087  return null;
1088  }
1089  SecurityElement element = SecurityElement.FromString(_ApplicationTrust);
1090  ApplicationTrust applicationTrust = new ApplicationTrust();
1091  applicationTrust.FromXml(element);
1092  return applicationTrust;
1093  }
1094 
1095  internal void InternalSetApplicationTrust(ApplicationTrust value)
1096  {
1097  if (value != null)
1098  {
1099  _ApplicationTrust = value.ToXml().ToString();
1100  }
1101  else
1102  {
1103  _ApplicationTrust = null;
1104  }
1105  }
1106 
1107  [SecurityCritical]
1108  internal bool UpdateContextPropertyIfNeeded(LoaderInformation FieldValue, string FieldKey, string UpdatedField, IntPtr fusionContext, AppDomainSetup oldADS)
1109  {
1110  string text = Value[(int)FieldValue];
1111  string b = (oldADS == null) ? null : oldADS.Value[(int)FieldValue];
1112  if (text != b)
1113  {
1114  UpdateContextProperty(fusionContext, FieldKey, (UpdatedField == null) ? text : UpdatedField);
1115  return true;
1116  }
1117  return false;
1118  }
1119 
1120  [SecurityCritical]
1121  internal void UpdateBooleanContextPropertyIfNeeded(LoaderInformation FieldValue, string FieldKey, IntPtr fusionContext, AppDomainSetup oldADS)
1122  {
1123  if (Value[(int)FieldValue] != null)
1124  {
1125  UpdateContextProperty(fusionContext, FieldKey, "true");
1126  }
1127  else if (oldADS != null && oldADS.Value[(int)FieldValue] != null)
1128  {
1129  UpdateContextProperty(fusionContext, FieldKey, "false");
1130  }
1131  }
1132 
1133  [SecurityCritical]
1134  internal static bool ByteArraysAreDifferent(byte[] A, byte[] B)
1135  {
1136  int num = A.Length;
1137  if (num != B.Length)
1138  {
1139  return true;
1140  }
1141  for (int i = 0; i < num; i++)
1142  {
1143  if (A[i] != B[i])
1144  {
1145  return true;
1146  }
1147  }
1148  return false;
1149  }
1150 
1151  [SecurityCritical]
1152  internal static void UpdateByteArrayContextPropertyIfNeeded(byte[] NewArray, byte[] OldArray, string FieldKey, IntPtr fusionContext)
1153  {
1154  if ((NewArray != null && OldArray == null) || (NewArray == null && OldArray != null) || (NewArray != null && OldArray != null && ByteArraysAreDifferent(NewArray, OldArray)))
1155  {
1156  UpdateContextProperty(fusionContext, FieldKey, NewArray);
1157  }
1158  }
1159 
1160  [SecurityCritical]
1161  internal void SetupFusionContext(IntPtr fusionContext, AppDomainSetup oldADS)
1162  {
1163  UpdateContextPropertyIfNeeded(LoaderInformation.ApplicationBaseValue, ApplicationBaseKey, null, fusionContext, oldADS);
1164  UpdateContextPropertyIfNeeded(LoaderInformation.PrivateBinPathValue, PrivateBinPathKey, null, fusionContext, oldADS);
1165  UpdateContextPropertyIfNeeded(LoaderInformation.DevPathValue, DeveloperPathKey, null, fusionContext, oldADS);
1166  UpdateBooleanContextPropertyIfNeeded(LoaderInformation.DisallowPublisherPolicyValue, DisallowPublisherPolicyKey, fusionContext, oldADS);
1167  UpdateBooleanContextPropertyIfNeeded(LoaderInformation.DisallowCodeDownloadValue, DisallowCodeDownloadKey, fusionContext, oldADS);
1168  UpdateBooleanContextPropertyIfNeeded(LoaderInformation.DisallowBindingRedirectsValue, DisallowBindingRedirectsKey, fusionContext, oldADS);
1169  UpdateBooleanContextPropertyIfNeeded(LoaderInformation.DisallowAppBaseProbingValue, DisallowAppBaseProbingKey, fusionContext, oldADS);
1170  if (UpdateContextPropertyIfNeeded(LoaderInformation.ShadowCopyFilesValue, ShadowCopyFilesKey, ShadowCopyFiles, fusionContext, oldADS))
1171  {
1172  if (Value[7] == null)
1173  {
1174  ShadowCopyDirectories = BuildShadowCopyDirectories();
1175  }
1176  UpdateContextPropertyIfNeeded(LoaderInformation.ShadowCopyDirectoriesValue, ShadowCopyDirectoriesKey, null, fusionContext, oldADS);
1177  }
1178  UpdateContextPropertyIfNeeded(LoaderInformation.CachePathValue, CachePathKey, null, fusionContext, oldADS);
1179  UpdateContextPropertyIfNeeded(LoaderInformation.PrivateBinPathProbeValue, PrivateBinPathProbeKey, PrivateBinPathProbe, fusionContext, oldADS);
1180  UpdateContextPropertyIfNeeded(LoaderInformation.ConfigurationFileValue, ConfigurationFileKey, null, fusionContext, oldADS);
1181  UpdateByteArrayContextPropertyIfNeeded(_ConfigurationBytes, oldADS?.GetConfigurationBytes(), ConfigurationBytesKey, fusionContext);
1182  UpdateContextPropertyIfNeeded(LoaderInformation.ApplicationNameValue, ApplicationNameKey, ApplicationName, fusionContext, oldADS);
1183  UpdateContextPropertyIfNeeded(LoaderInformation.DynamicBaseValue, DynamicBaseKey, null, fusionContext, oldADS);
1184  UpdateContextProperty(fusionContext, MachineConfigKey, RuntimeEnvironment.GetRuntimeDirectoryImpl() + RuntimeConfigurationFile);
1185  string hostBindingFile = RuntimeEnvironment.GetHostBindingFile();
1186  if (hostBindingFile != null || oldADS != null)
1187  {
1188  UpdateContextProperty(fusionContext, HostBindingKey, hostBindingFile);
1189  }
1190  }
1191 
1192  [MethodImpl(MethodImplOptions.InternalCall)]
1193  [SecurityCritical]
1194  internal static extern void UpdateContextProperty(IntPtr fusionContext, string key, object value);
1195 
1196  internal static int Locate(string s)
1197  {
1198  if (string.IsNullOrEmpty(s))
1199  {
1200  return -1;
1201  }
1202  switch (s[0])
1203  {
1204  case 'A':
1205  if (s == "APP_CONFIG_FILE")
1206  {
1207  return 1;
1208  }
1209  if (s == "APP_NAME")
1210  {
1211  return 4;
1212  }
1213  if (s == "APPBASE")
1214  {
1215  return 0;
1216  }
1217  if (s == "APP_CONFIG_BLOB")
1218  {
1219  return 15;
1220  }
1221  break;
1222  case 'B':
1223  if (s == "BINPATH_PROBE_ONLY")
1224  {
1225  return 6;
1226  }
1227  break;
1228  case 'C':
1229  if (s == "CACHE_BASE")
1230  {
1231  return 9;
1232  }
1233  if (s == "CODE_DOWNLOAD_DISABLED")
1234  {
1235  return 12;
1236  }
1237  break;
1238  case 'D':
1239  if (s == "DEV_PATH")
1240  {
1241  return 3;
1242  }
1243  if (s == "DYNAMIC_BASE")
1244  {
1245  return 2;
1246  }
1247  if (s == "DISALLOW_APP")
1248  {
1249  return 11;
1250  }
1251  if (s == "DISALLOW_APP_REDIRECTS")
1252  {
1253  return 13;
1254  }
1255  if (s == "DISALLOW_APP_BASE_PROBING")
1256  {
1257  return 14;
1258  }
1259  break;
1260  case 'F':
1261  if (s == "FORCE_CACHE_INSTALL")
1262  {
1263  return 8;
1264  }
1265  break;
1266  case 'L':
1267  if (s == "LICENSE_FILE")
1268  {
1269  return 10;
1270  }
1271  break;
1272  case 'P':
1273  if (s == "PRIVATE_BINPATH")
1274  {
1275  return 5;
1276  }
1277  break;
1278  case 'S':
1279  if (s == "SHADOW_COPY_DIRS")
1280  {
1281  return 7;
1282  }
1283  break;
1284  }
1285  return -1;
1286  }
1287 
1288  private string BuildShadowCopyDirectories()
1289  {
1290  string text = Value[5];
1291  if (text == null)
1292  {
1293  return null;
1294  }
1295  StringBuilder stringBuilder = StringBuilderCache.Acquire();
1296  string text2 = Value[0];
1297  if (text2 != null)
1298  {
1299  char[] separator = new char[1]
1300  {
1301  ';'
1302  };
1303  string[] array = text.Split(separator);
1304  int num = array.Length;
1305  bool flag = text2[text2.Length - 1] != '/' && text2[text2.Length - 1] != '\\';
1306  if (num == 0)
1307  {
1308  stringBuilder.Append(text2);
1309  if (flag)
1310  {
1311  stringBuilder.Append('\\');
1312  }
1313  stringBuilder.Append(text);
1314  }
1315  else
1316  {
1317  for (int i = 0; i < num; i++)
1318  {
1319  stringBuilder.Append(text2);
1320  if (flag)
1321  {
1322  stringBuilder.Append('\\');
1323  }
1324  stringBuilder.Append(array[i]);
1325  if (i < num - 1)
1326  {
1327  stringBuilder.Append(';');
1328  }
1329  }
1330  }
1331  }
1332  return StringBuilderCache.GetStringAndRelease(stringBuilder);
1333  }
1334  }
1335 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
void FromXml(SecurityElement element)
Reconstructs an T:System.Security.Policy.ApplicationTrust object with a given state from an XML encod...
Encapsulates security decisions about an application. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
AppDomainSetup(ActivationArguments activationArguments)
Initializes a new instance of the T:System.AppDomainSetup class with the specified activation argumen...
string TargetFrameworkName
Gets or sets a string that specifies the target version and profile of the .NET Framework for the app...
bool DisallowApplicationBaseProbing
Specifies whether the application base path and private binary path are probed when searching for ass...
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
string AppDomainManagerAssembly
Gets or sets the display name of the assembly that provides the type of the application domain manage...
LoaderOptimization
An enumeration used with the T:System.LoaderOptimizationAttribute class to specify loader optimizatio...
void SetNativeFunction(string functionName, int functionVersion, IntPtr functionPointer)
Provides the common language runtime with an alternate implementation of a string comparison function...
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
string ShadowCopyFiles
Gets or sets a string that indicates whether shadow copying is turned on or off.
Identifies the activation context for the current application. This class cannot be inherited.
ActivationArguments ActivationArguments
Gets or sets data about the activation of an application domain.
Definition: __Canon.cs:3
LoaderOptimization LoaderOptimization
Specifies the optimization policy used to load an executable.
bool DisallowCodeDownload
Gets or sets a value that indicates whether HTTP download of assemblies is allowed for an application...
string [] AppDomainInitializerArguments
Gets or sets the arguments passed to the callback method represented by the T:System....
Provides a collection of static methods that return information about the common language runtime env...
new bool Equals(object x, object y)
When overridden in a derived class, indicates whether two objects are equal.
string ConfigurationFile
Gets or sets the name of the configuration file for an application domain.
string ApplicationBase
Gets or sets the name of the directory containing the application.
Represents assembly binding information that can be added to an instance of T:System....
void SetCompatibilitySwitches(IEnumerable< string > switches)
Sets the specified switches, making the application domain compatible with previous versions of the ....
string [] PartialTrustVisibleAssemblies
Gets or sets a list of assemblies marked with the F:System.Security.PartialTrustVisibilityLevel....
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
KeyCollection Keys
Gets a collection containing the keys in the T:System.Collections.Generic.Dictionary`2.
Definition: Dictionary.cs:902
string AppDomainManagerType
Gets or sets the full name of the type that provides the application domain manager for application d...
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
static void Sort(Array array)
Sorts the elements in an entire one-dimensional T:System.Array using the T:System....
Definition: Array.cs:3259
AppDomainSetup(ActivationContext activationContext)
Initializes a new instance of the T:System.AppDomainSetup class with the specified activation context...
Represents the XML object model for encoding security objects. This class cannot be inherited.
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
string DynamicBase
Gets or sets the base directory where the directory for dynamically generated files is located.
string PrivateBinPathProbe
Gets or sets a string value that includes or excludes P:System.AppDomainSetup.ApplicationBase from th...
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
bool DisallowBindingRedirects
Gets or sets a value that indicates whether an application domain allows assembly binding redirection...
MethodImplOptions
Defines the details of how a method is implemented.
string PrivateBinPath
Gets or sets the list of directories under the application base directory that are probed for private...
ApplicationTrust ApplicationTrust
Gets or sets an object containing security and trust information.
Provides data for manifest-based activation of an application. This class cannot be inherited.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
bool SandboxInterop
Gets or sets a value that indicates whether interface caching is disabled for interop calls in the ap...
AppDomainInitializer AppDomainInitializer
Gets or sets the T:System.AppDomainInitializer delegate, which represents a callback method that is i...
AppDomainSetup()
Initializes a new instance of the T:System.AppDomainSetup class.
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
static SecurityElement FromString(string xml)
Creates a security element from an XML-encoded string.
string ShadowCopyDirectories
Gets or sets the names of the directories containing assemblies to be shadow copied.
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Definition: IntPtr.cs:20
Represents assembly binding information that can be added to an instance of T:System....
bool DisallowPublisherPolicy
Gets or sets a value that indicates whether the <publisherPolicy> section of the configuration file i...
ActivationContext ActivationContext
Gets the activation context for manifest-based activation of an application.
Specifies that the class can be serialized.
static StringComparer OrdinalIgnoreCase
Gets a T:System.StringComparer object that performs a case-insensitive ordinal string comparison.
string ApplicationName
Gets or sets the name of the application.
void Add(TKey key, TValue value)
Adds the specified key and value to the dictionary.
Definition: Dictionary.cs:1244
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
string CachePath
Gets or sets the name of an area specific to the application where files are shadow copied.
Controls the ability to access files and folders. This class cannot be inherited.
byte [] GetConfigurationBytes()
Returns the XML configuration information set by the M:System.AppDomainSetup.SetConfigurationBytes(Sy...
The exception that is thrown when an attempt to access a class member fails.
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
Represents a string comparison operation that uses specific case and culture-based or ordinal compari...
StringBuilder Remove(int startIndex, int length)
Removes the specified range of characters from this instance.
void SetConfigurationBytes(byte[] value)
Provides XML configuration information for the application domain, replacing the application's XML co...
string LicenseFile
Gets or sets the location of the license file associated with this domain.