Exemplo n.º 1
0
        public static NativeMethods.IAssemblyCache GetAssemblyCacheInterface(string CLRVersionString, bool FetchRuntimeHost, out NativeMethods.CCorRuntimeHost RuntimeHost)
        {
            NativeMethods.IClrMetaHostPolicy ClrMetaHostPolicy = (NativeMethods.IClrMetaHostPolicy)null;

            RuntimeHost = (NativeMethods.CCorRuntimeHost)null;
            NativeMethods.GetClrMetaHostPolicy(ref NativeMethods._metaHostPolicyClsIdGuid, ref NativeMethods._metaHostPolicyGuid, out ClrMetaHostPolicy);
            if (ClrMetaHostPolicy == null)
            {
                return((NativeMethods.IAssemblyCache)null);
            }
            StringBuilder version = new StringBuilder("v", "v65535.65535.65535".Length);

            version.Append(CLRVersionString);
            int versionLength      = version.Capacity;
            int imageVersionLength = 0;
            int pdwConfigFlags     = 0;

            NativeMethods.IClrRuntimeInfo requestedRuntime = (NativeMethods.IClrRuntimeInfo)ClrMetaHostPolicy.GetRequestedRuntime(NativeMethods.MetaHostPolicyFlags.MetaHostPolicyApplyUpgradePolicy, (string)null, (IStream)null, version, out versionLength, (StringBuilder)null, out imageVersionLength, out pdwConfigFlags, NativeMethods._clrRuntimeInfoGuid);
            if (requestedRuntime == null)
            {
                return((NativeMethods.IAssemblyCache)null);
            }
            Marshal.ThrowExceptionForHR(((NativeMethods.CoInitializeEEDelegate)Marshal.GetDelegateForFunctionPointer(requestedRuntime.GetProcAddress("CoInitializeEE"), typeof(NativeMethods.CoInitializeEEDelegate)))(0U));
            if (FetchRuntimeHost)
            {
                RuntimeHost = new NativeMethods.CCorRuntimeHost(requestedRuntime);
            }
            NativeMethods.CreateAssemblyCacheDelegate forFunctionPointer = (NativeMethods.CreateAssemblyCacheDelegate)Marshal.GetDelegateForFunctionPointer(requestedRuntime.GetProcAddress("CreateAssemblyCache"), typeof(NativeMethods.CreateAssemblyCacheDelegate));
            NativeMethods.IAssemblyCache ppAsmCache = (NativeMethods.IAssemblyCache)null;
            Marshal.ThrowExceptionForHR(forFunctionPointer(out ppAsmCache, 0U));
            return(ppAsmCache);
        }
Exemplo n.º 2
0
 public static bool VerifyGACDependency(NativeMethods.IAssemblyCache AssemblyCache, bool targetOtherClr, NativeMethods.CCorRuntimeHost RuntimeHost, ReferenceIdentity refId, string tempDir)
 {
     if (string.Compare(refId.ProcessorArchitecture, "msil", StringComparison.OrdinalIgnoreCase) == 0 || !PlatformDetector.VerifyGACDependencyXP(refId, tempDir))
     {
         return(PlatformDetector.VerifyGACDependencyWhidbey(AssemblyCache, targetOtherClr, RuntimeHost, refId));
     }
     return(true);
 }
Exemplo n.º 3
0
        public static bool VerifyGACDependencyWhidbey(NativeMethods.IAssemblyCache AssemblyCache, bool targetOtherClr, NativeMethods.CCorRuntimeHost RuntimeHost, ReferenceIdentity refId)
        {
            string str = refId.ToString();
            string text;

            if (targetOtherClr)
            {
                try
                {
                    text = RuntimeHost.ApplyPolicyInOtherRuntime(str);
                }
                catch (ArgumentException ex)
                {
                    return(false);
                }
                catch (COMException ex)
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    text = AppDomain.CurrentDomain.ApplyPolicy(str);
                }
                catch (ArgumentException ex)
                {
                    return(false);
                }
                catch (COMException ex)
                {
                    return(false);
                }
            }
            ReferenceIdentity referenceIdentity = new ReferenceIdentity(text);

            referenceIdentity.ProcessorArchitecture = refId.ProcessorArchitecture;
            string assemblyName = referenceIdentity.ToString();

            Logger.AddPhaseInformation(Resources.GetString("DetectingDependentAssembly"), (object)str, (object)assemblyName);
            SystemUtils.AssemblyInfo assemblyInfo = SystemUtils.QueryAssemblyInfo(AssemblyCache, SystemUtils.QueryAssemblyInfoFlags.All, assemblyName);
            if (assemblyInfo != null || referenceIdentity.ProcessorArchitecture != null)
            {
                return(assemblyInfo != null);
            }
            NativeMethods.IAssemblyName pName;
            NativeMethods.CreateAssemblyNameObject(out pName, referenceIdentity.ToString(), 1U, IntPtr.Zero);
            NativeMethods.IAssemblyEnum ppEnum;
            NativeMethods.CreateAssemblyEnum(out ppEnum, (NativeMethods.IApplicationContext)null, pName, 2U, IntPtr.Zero);
            return(ppEnum.GetNextAssembly((NativeMethods.IApplicationContext)null, out pName, 0U) == 0);
        }
Exemplo n.º 4
0
 public static string QueryAssemblyInfo(string assemblyName)
 {
     if (assemblyName == null)
     {
         throw new ArgumentException(Resources.INVALID_ASSEMBLYNAME, "assemblyName");
     }
     NativeMethods.AssemblyInfo assemblyInfo = new NativeMethods.AssemblyInfo();
     assemblyInfo.cchBuf = 1024;
     assemblyInfo.currentAssemblyPath = new string(char.MinValue, assemblyInfo.cchBuf);
     NativeMethods.IAssemblyCache ppAsmCache = (NativeMethods.IAssemblyCache)null;
     NativeMethods.CreateAssemblyCache(out ppAsmCache, 0);
     ppAsmCache.QueryAssemblyInfo(0, assemblyName, ref assemblyInfo);
     return(assemblyInfo.currentAssemblyPath);
 }
Exemplo n.º 5
0
        private void Uninstall(string name)
        {
            // Get the IAssemblyCache interface
            NativeMethods.IAssemblyCache assemblyCache = this.GetIAssemblyCache();

            // Uninstall the assembly from the cache
            int disposition;
            int result = assemblyCache.UninstallAssembly(0, name, IntPtr.Zero, out disposition);

            // If the result is not zero or the disposition is not 1 then throw an exception
            if (result != 0)
            {
                // If result is not 0 then something happened. Check the value of disposition to see if we should throw an error.
                // Determined the values of the codes returned in disposition from
                switch (disposition)
                {
                case 1:
                    // Assembly was removed from GAC.
                    break;

                case 2:
                    this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "An application is using: {0} so it could not be uninstalled.", name));
                    return;

                case 3:
                    // Assembly is not in the assembly. Don't throw an error, just proceed to install it.
                    break;

                case 4:
                    // Not used.
                    break;

                case 5:
                    this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "{0} was not uninstalled from the GAC because another reference exists to it.", name));
                    return;

                case 6:
                    // Problem where a reference doesn't exist to the pointer. We aren't using the pointer so this shouldn't be a problem.
                    break;

                default:
                    this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Failed to uninstall: {0} from the GAC.", name));
                    return;
                }
            }
        }
Exemplo n.º 6
0
        private void Install(string path, bool force)
        {
            // Get the IAssemblyCache interface
            NativeMethods.IAssemblyCache assemblyCache = this.GetIAssemblyCache();

            // Set the flag depending on the value of force
            int flag = force ? 2 : 1;

            // Install the assembly in the cache
            int result = assemblyCache.InstallAssembly(flag, path, IntPtr.Zero);

            // If the result is not zero throw an exception
            if (result != 0)
            {
                Log.LogError(string.Format(CultureInfo.CurrentCulture, "Failed to install assembly into the global assembly cache. Result Code: {0}", result));
            }
        }
Exemplo n.º 7
0
        private static PlatformDetector.NetFX35SP1SKU GetPlatformNetFx35SKU(NativeMethods.IAssemblyCache AssemblyCache, bool targetOtherCLR, NativeMethods.CCorRuntimeHost RuntimeHost, string tempDir)
        {
            ReferenceIdentity refId1 = new ReferenceIdentity("Sentinel.v3.5Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,processorArchitecture=msil");
            ReferenceIdentity refId2 = new ReferenceIdentity("System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089,processorArchitecture=msil");
            bool flag1 = false;
            bool flag2 = false;

            if (PlatformDetector.VerifyGACDependency(AssemblyCache, targetOtherCLR, RuntimeHost, refId1, tempDir))
            {
                flag1 = true;
            }
            if (PlatformDetector.VerifyGACDependency(AssemblyCache, targetOtherCLR, RuntimeHost, refId2, tempDir))
            {
                flag2 = true;
            }
            if (flag1 && !flag2)
            {
                return(PlatformDetector.NetFX35SP1SKU.Client35SP1);
            }
            return(flag1 & flag2 ? PlatformDetector.NetFX35SP1SKU.Full35SP1 : PlatformDetector.NetFX35SP1SKU.No35SP1);
        }
Exemplo n.º 8
0
 internal static extern void CreateAssemblyCache(out NativeMethods.IAssemblyCache ppAsmCache, int reserved);
Exemplo n.º 9
0
        public static void VerifyPlatformDependencies(AssemblyManifest appManifest, AssemblyManifest deployManifest, string tempDir)
        {
            Logger.AddMethodCall("VerifyPlatformDependencies called.");
            string      str1        = (string)null;
            Uri         supportUrl1 = deployManifest.Description.SupportUri;
            bool        flag1       = false;
            DependentOS dependentOs = appManifest.DependentOS;

            if (dependentOs != null)
            {
                PlatformDetector.OSDependency osd = new PlatformDetector.OSDependency((uint)dependentOs.MajorVersion, (uint)dependentOs.MinorVersion, (uint)dependentOs.BuildNumber, (ushort)dependentOs.ServicePackMajor, (ushort)dependentOs.ServicePackMinor, (string)null, (string)null);
                if (!PlatformDetector.VerifyOSDependency(ref osd))
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    string        str2          = ((int)dependentOs.MajorVersion).ToString() + "." + (object)dependentOs.MinorVersion + "." + (object)dependentOs.BuildNumber + "." + (object)dependentOs.ServicePackMajor + (object)dependentOs.ServicePackMinor;
                    stringBuilder.AppendFormat(Resources.GetString("PlatformMicrosoftWindowsOperatingSystem"), (object)str2);
                    string str3 = stringBuilder.ToString();
                    if (dependentOs.SupportUrl != (Uri)null)
                    {
                        supportUrl1 = dependentOs.SupportUrl;
                    }
                    throw new DependentPlatformMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[1] {
                        (object)str3
                    }), supportUrl1);
                }
            }
            if (PlatformDetector.IsWin8orLater() && !appManifest.EntryPoints[0].HostInBrowser)
            {
                flag1 = true;
            }
            Version clrVersion            = Constants.V2CLRVersion;
            string  clrVersionString      = clrVersion.ToString(3);
            string  processorArchitecture = appManifest.Identity.ProcessorArchitecture;
            Uri     supportUrl2           = supportUrl1;

            if (appManifest.CLRDependentAssembly != null)
            {
                clrVersion            = appManifest.CLRDependentAssembly.Identity.Version;
                clrVersionString      = clrVersion.ToString(3);
                processorArchitecture = appManifest.CLRDependentAssembly.Identity.ProcessorArchitecture;
                if (appManifest.CLRDependentAssembly.SupportUrl != (Uri)null)
                {
                    supportUrl2 = appManifest.CLRDependentAssembly.SupportUrl;
                }
                if (appManifest.CLRDependentAssembly.Description != null)
                {
                    str1 = appManifest.CLRDependentAssembly.Description;
                }
            }
            if (deployManifest.CompatibleFrameworks != null)
            {
                bool flag2 = false;
                for (int index = 0; index < deployManifest.CompatibleFrameworks.Frameworks.Count; ++index)
                {
                    if (PlatformDetector.CheckCompatibleFramework(deployManifest.CompatibleFrameworks.Frameworks[index], ref clrVersion, ref clrVersionString, processorArchitecture))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    Uri supportUrl3 = !(deployManifest.CompatibleFrameworks.SupportUrl != (Uri)null) ? supportUrl2 : deployManifest.CompatibleFrameworks.SupportUrl;
                    if (flag1)
                    {
                        return;
                    }
                    throw new CompatibleFrameworkMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_CompatiblePlatformDetectionFailed"), new object[1]
                    {
                        (object)PlatformDetector.FormatFrameworkString(deployManifest.CompatibleFrameworks.Frameworks[0])
                    }), supportUrl3, deployManifest.CompatibleFrameworks);
                }
            }
            else
            {
                if (clrVersion >= Constants.V4CLRVersion)
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, Resources.GetString("Ex_SemanticallyInvalidDeploymentManifest"), (Exception) new InvalidDeploymentException(ExceptionTypes.InvalidManifest, Resources.GetString("Ex_DepMissingCompatibleFrameworks")));
                }
                if (!NativeMethods.VerifyCLRVersionInfo(clrVersion, processorArchitecture))
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    if (str1 == null)
                    {
                        stringBuilder.AppendFormat(Resources.GetString("PlatformMicrosoftCommonLanguageRuntime"), (object)clrVersionString);
                        str1 = stringBuilder.ToString();
                    }
                    Uri supportUrl3 = supportUrl2;
                    if (flag1)
                    {
                        return;
                    }
                    throw new SupportedRuntimeMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[1] {
                        (object)str1
                    }), supportUrl3, clrVersionString);
                }
            }
            Logger.AddPhaseInformation(Resources.GetString("CompatibleRuntimeFound"), new object[1]
            {
                (object)clrVersionString
            });
            bool flag3 = false;

            if (clrVersion < Constants.V4CLRVersion)
            {
                flag3 = true;
            }
            NativeMethods.CCorRuntimeHost RuntimeHost = (NativeMethods.CCorRuntimeHost)null;
            try
            {
                NativeMethods.IAssemblyCache assemblyCacheInterface = NativeMethods.GetAssemblyCacheInterface(clrVersionString, flag3, out RuntimeHost);
                if (assemblyCacheInterface == null || flag3 && RuntimeHost == null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendFormat(Resources.GetString("PlatformMicrosoftCommonLanguageRuntime"), (object)clrVersionString);
                    throw new DependentPlatformMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[1]
                    {
                        (object)stringBuilder.ToString()
                    }), supportUrl2);
                }
                bool flag2 = false;
                bool flag4 = false;
                if (flag3 && !PolicyKeys.SkipSKUDetection())
                {
                    foreach (DependentAssembly dependentAssembly in appManifest.DependentAssemblies)
                    {
                        if (dependentAssembly.IsPreRequisite && PlatformDetector.IsNetFX35SP1ClientSignatureAsm(dependentAssembly.Identity))
                        {
                            flag2 = true;
                        }
                        if (dependentAssembly.IsPreRequisite && PlatformDetector.IsNetFX35SP1FullSignatureAsm(dependentAssembly.Identity))
                        {
                            flag4 = true;
                        }
                    }
                    if (PlatformDetector.GetPlatformNetFx35SKU(assemblyCacheInterface, flag3, RuntimeHost, tempDir) == PlatformDetector.NetFX35SP1SKU.Client35SP1 && !flag2 && !flag4)
                    {
                        throw new DependentPlatformMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformDetectionFailed"), new object[1]
                        {
                            (object)".NET Framework 3.5 SP1"
                        }));
                    }
                }
                foreach (DependentAssembly dependentAssembly in appManifest.DependentAssemblies)
                {
                    if (dependentAssembly.IsPreRequisite && !PlatformDetector.IsCLRDependencyText(dependentAssembly.Identity.Name))
                    {
                        if (!flag3 && (PlatformDetector.IsNetFX35SP1ClientSignatureAsm(dependentAssembly.Identity) || PlatformDetector.IsNetFX35SP1FullSignatureAsm(dependentAssembly.Identity) || "framework".Equals(dependentAssembly.Group, StringComparison.OrdinalIgnoreCase)))
                        {
                            Logger.AddPhaseInformation(Resources.GetString("SkippingSentinalDependentAssembly"), new object[1]
                            {
                                (object)dependentAssembly.Identity.ToString()
                            });
                        }
                        else if (!PlatformDetector.VerifyGACDependency(assemblyCacheInterface, flag3, RuntimeHost, dependentAssembly.Identity, tempDir))
                        {
                            string description;
                            if (dependentAssembly.Description != null)
                            {
                                description = dependentAssembly.Description;
                            }
                            else
                            {
                                ReferenceIdentity identity      = dependentAssembly.Identity;
                                StringBuilder     stringBuilder = new StringBuilder();
                                stringBuilder.AppendFormat(Resources.GetString("PlatformDependentAssemblyVersion"), (object)identity.Name, (object)identity.Version);
                                description = stringBuilder.ToString();
                            }
                            if (dependentAssembly.SupportUrl != (Uri)null)
                            {
                                supportUrl1 = dependentAssembly.SupportUrl;
                            }
                            throw new DependentPlatformMissingException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("ErrorMessage_PlatformGACDetectionFailed"), new object[1]
                            {
                                (object)description
                            }), supportUrl1);
                        }
                    }
                }
            }
            finally
            {
                if (RuntimeHost != null)
                {
                    RuntimeHost.Dispose();
                }
            }
        }