Esempio n. 1
0
        /// <summary>
        ///     Uninstal the provided assembly names from the GAC
        /// </summary>
        /// <param name="assemblyNames"></param>
        /// <param name="reference"></param>
        /// <param name="disp"></param>
        public static void UninstallAssemblies(String[] assemblyNames, InstallReference reference, out AssemblyCacheUninstallDisposition[] disp)
        {
            var dispResult = AssemblyCacheUninstallDisposition.Uninstalled;

            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            disp = new AssemblyCacheUninstallDisposition[assemblyNames.Length];
            var hr = Utils.CreateAssemblyCache(out ac, 0);

            if (hr >= 0)
            {
                for (var i = 0; i < assemblyNames.Length; i++)
                {
                    hr = ac.UninstallAssembly(0, assemblyNames[i], reference, out dispResult);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }

                    disp[i] = dispResult;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Install the provided assemblies to GAC
        /// </summary>
        /// <param name="assemblyPaths"></param>
        /// <param name="reference"></param>
        /// <param name="flags"></param>
        public static void InstallAssemblies(String[] assemblyPaths, InstallReference reference, AssemblyCommitFlags flags)
        {
            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            var hr = 0;

            hr = Utils.CreateAssemblyCache(out ac, 0);
            if (hr >= 0)
            {
                foreach (var assemblyPath in assemblyPaths)
                {
                    hr = ac.InstallAssembly((int)flags, assemblyPath, reference);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }
            }
        }
Esempio n. 3
0
        // assemblyName has to be fully specified name.
        // A.k.a, for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx".
        // For v2.0 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx".
        // If assemblyName is not fully specified, a random matching assembly will be uninstalled.
        public static void UninstallAssembly(String assemblyName, InstallReference reference, out AssemblyCacheUninstallDisposition disp)
        {
            var dispResult = AssemblyCacheUninstallDisposition.Uninstalled;

            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            var hr = Utils.CreateAssemblyCache(out ac, 0);

            if (hr >= 0)
            {
                hr = ac.UninstallAssembly(0, assemblyName, reference, out dispResult);
            }

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            disp = dispResult;
        }
Esempio n. 4
0
            // See comments in UninstallAssembly
            public static String QueryAssemblyInfo(String assemblyName)
            {
                if (assemblyName == null)
                {
                    throw new ArgumentException("Invalid name", "assemblyName");
                }

                AssemblyInfo aInfo = new AssemblyInfo();

                aInfo.cchBuf = 1024;
                // Get a string with the desired length
                aInfo.currentAssemblyPath = new String('\0', aInfo.cchBuf);

                IAssemblyCache ac = null;
                int            hr = CreateAssemblyCache(out ac, 0);

                if (hr >= 0)
                {
                    hr = ac.QueryAssemblyInfo(0, assemblyName, ref aInfo);
                }
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                return(aInfo.currentAssemblyPath);
            }
Esempio n. 5
0
        /// <summary>
        /// Installs the assembly.
        /// </summary>
        /// <param name="assemblyPath">The assembly path.</param>
        /// <param name="force">if set to <c>true</c> force.</param>
        public static void InstallAssembly(string assemblyPath, bool force)
        {
            IAssemblyCache assemblyCache = null;

            int flags = force ? (int)CommitFlags.Force : (int)CommitFlags.Refresh;

            ThrowOnError(NativeMethods.CreateAssemblyCache(out assemblyCache, 0));
            ThrowOnError(assemblyCache.InstallAssembly(flags, assemblyPath, null));
        }
Esempio n. 6
0
        static internal int UninstallAssembly(string assembly)
        {
            assembly = System.Reflection.Assembly.LoadFrom(Path.GetFullPath(assembly)).FullName;
            uint           n;
            IAssemblyCache gac = null;
            int            hr  = CreateAssemblyCache(out gac, 0);

            return((hr != 0) ? hr : gac.UninstallAssembly(0, assembly, (IntPtr)0, out n));
        }
 public AssemblyLoader(IAppDomain appDomain,
                       IPluginLoaderSettings settings,
                       IAssemblyCache assemblyCache,
                       IAssemblyNameReader assemblyNameReader,
                       IPluginLoaderLogger logger)
 {
     _AppDomain          = appDomain ?? throw new ArgumentNullException(nameof(appDomain));
     _Settings           = settings ?? throw new ArgumentNullException(nameof(settings));
     _AssemblyCache      = assemblyCache ?? throw new ArgumentNullException(nameof(assemblyCache));
     _AssemblyNameReader = assemblyNameReader ?? throw new ArgumentNullException(nameof(assemblyNameReader));
     _Logger             = logger;
 }
        }// GetFusionString

        internal static int AddAssemblytoGac(String sAssemFilename)
        {
            IAssemblyCache ac = null;
            int            hr = CreateAssemblyCache(out ac, 0);

            if (hr != HRESULT.S_OK)
            {
                return(hr);
            }

            return(ac.InstallAssembly(0, sAssemFilename, (IntPtr)0));
        }// AddAssemblyToGac
Esempio n. 9
0
        static public int AddAssemblyToCache(string assemblyExecutionName)
        {
            IAssemblyCache ac = null;
            int            hr = CreateAssemblyCache(out ac, 0);

            if (hr != 0)
            {
                return(hr);
            }

            return(ac.InstallAssembly(0, assemblyExecutionName, (IntPtr)0));
        }
Esempio n. 10
0
        public void GacInstall(string assemblyPath)
        {
            IAssemblyCache ppAsmCache = null;
            int            num        = NativeMethods.CreateAssemblyCache(out ppAsmCache, 0);

            if (num == 0)
            {
                num = ppAsmCache.InstallAssembly(0, assemblyPath, IntPtr.Zero);
            }
            if (num != 0)
            {
                throw new Exception(System.Web.SR.GetString("Failed_gac_install"));
            }
        }
Esempio n. 11
0
        private void BrowseFilesButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.SetUIState(false);

                DialogResult result = this.BrowseFilesDialog.ShowDialog();

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    this.AssemblyComboBox.Items.Clear();
                    this.ClassComboBox.Items.Clear();
                    this.TypesCheckedListBox.Items.Clear();

                    string selectedFile = this.BrowseFilesDialog.FileName;

                    FileInfo assemblyFile = new FileInfo(selectedFile);

                    DirectoryInfo gac = new DirectoryInfo(@"c:\windows\assembly\GAC_MSIL");

                    FileInfo[] results = gac.GetFiles(assemblyFile.Name, SearchOption.AllDirectories);

                    if (MessageBox.Show(this, string.Format("The selected assembly was {0} in the GAC. Event receivers must be registered in the GAC and do not require Safe Control entries. Do you want to register the selected copy of this assembly?", (results.Length > 0 ? "found" : "not found")), "Register Selected Assembly in GAC?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        Assembly assembly = Assembly.LoadFile(assemblyFile.FullName);

                        FUSION_INSTALL_REFERENCE[] gacSettings = new FUSION_INSTALL_REFERENCE[1];
                        gacSettings[0].dwFlags             = 0;
                        gacSettings[0].guidScheme          = AssemblyCache.FUSION_REFCOUNT_OPAQUE_STRING_GUID;
                        gacSettings[0].szIdentifier        = assembly.GetName().Name;
                        gacSettings[0].szNonCannonicalData = assembly.FullName;

                        IAssemblyCache cache = AssemblyCache.CreateAssemblyCache();

                        cache.InstallAssembly(0, assemblyFile.FullName, gacSettings);
                    }

                    this.AssemblyComboBox.Items.Add(assemblyFile);

                    this.AssemblyComboBox.SelectedIndex = 1;
                }

                this.SetUIState(true);
            }
            catch (Exception ex)
            {
                this.HandleException(ex);
            }
        }
        public void Load(IServiceProvider serviceProvider)
        {
            CodeMetricWindow codeMetricWindow = new CodeMetricWindow(serviceProvider);

            this.windowManager       = (IWindowManager)serviceProvider.GetService(typeof(IWindowManager));
            this.windowManager.Load += new EventHandler(this.WindowManager_Load);
            this.windowManager.Windows.Add("CodeMetricWindow", codeMetricWindow, "Code Metrics");

            this.assemblyManager = (IAssemblyManager)serviceProvider.GetService(typeof(IAssemblyManager));
            this.assemblyCache   = (IAssemblyCache)serviceProvider.GetService(typeof(IAssemblyCache));

            this.commandBarManager = (ICommandBarManager)serviceProvider.GetService(typeof(ICommandBarManager));
            this.separator         = this.commandBarManager.CommandBars["Tools"].Items.AddSeparator();
            this.button            = this.commandBarManager.CommandBars["Tools"].Items.AddButton("&Code Metrics", new EventHandler(this.Button_Click), Keys.Control | Keys.E);
        }
Esempio n. 13
0
        static internal int AddAssemblyToCache(string assembly)
        {
            IAssemblyCache ac = null;

            var hr = CreateAssemblyCache(out ac, 0);

            if (hr != IntPtr.Zero)
            {
                return((int)hr);
            }
            else
            {
                return(ac.InstallAssembly(0, assembly, (IntPtr)0));
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Installs an assembly into the GAC. Adds a reference to the installing applicaiton.
        /// </summary>
        /// <param name="assemblyPath">The path to the assembly to be installed</param>
        /// <param name="flags">see AssemblyCommitFlags</param>
        internal static void InstallAssembly(String assemblyPath, AssemblyCommitFlags flags)
        {
            IAssemblyCache ac = null;
            int            hr = 0;

            hr = GacUtils.CreateAssemblyCache(out ac, 0);
            if (hr >= 0)
            {
                hr = ac.InstallAssembly((int)flags, assemblyPath, null);
            }
            if (hr < 0)
            {
                GacUtils.ThrowMarshalledException(hr);
            }
        }
Esempio n. 15
0
        // If you use this, fusion will do the streaming & commit
        public static void InstallAssembly(string assemblyPath, InstallReference reference, AssemblyCommitFlags flags)
        {
            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid argument( reference guid).");
                }
            }

            IAssemblyCache asmCache = null;

            COM.CheckHR(CreateAssemblyCache(out asmCache, 0));
            COM.CheckHR(asmCache.InstallAssembly((int)flags, assemblyPath, reference));
        }
Esempio n. 16
0
        static public int RemoveAssemblyFromCache(string assemblyName)
        {
            IAssemblyCache ac = null;

            int hr = CreateAssemblyCache(out ac, 0);

            if (hr != 0)
            {
                return(hr);
            }

            uint n;

            return(ac.UninstallAssembly(0, assemblyName, (IntPtr)0, out n));
        }
Esempio n. 17
0
        static internal int RemoveAssemblyFromCache(string assembly)
        {
            IAssemblyCache ac = null;

            uint n;
            var  hr = CreateAssemblyCache(out ac, 0);

            if (hr != IntPtr.Zero)
            {
                return((int)hr);
            }
            else
            {
                return(ac.UninstallAssembly(0, assembly, (IntPtr)0, out n));
            }
        }
Esempio n. 18
0
File: GACUtil.cs Progetto: zha0/wspe
        /// <summary>
        /// Constructor. Initialise IAssemblyEnum and IAssemblyCache.
        /// </summary>
        public GACUtil()
        {
            uint hr = Functions.CreateAssemblyEnum(out IAssemblyEnum pIAssemblyEnum, IntPtr.Zero, null, ASM_CACHE_FLAGS.ASM_CACHE_GAC, IntPtr.Zero);

            if (!Macros.SUCCEEDED(hr) || pIAssemblyEnum == null)
            {
                throw new Exception("[-] Unable to create IAssemblyEnum interface.");
            }
            this.pIAssemblyEnum = pIAssemblyEnum;

            hr = Functions.CreateAssemblyCache(out IAssemblyCache pIAssemblyCache, 0);
            if (!Macros.SUCCEEDED(hr) || pIAssemblyCache == null)
            {
                throw new Exception("[-] Unable to create fusion!IAssemblyEnum interface.");
            }
            this.pIAssemblyCache = pIAssemblyCache;
        }
Esempio n. 19
0
        internal static string GetAssemblyPath(string assemblyName, out string fullName)
        {
            IAssemblyCache cache = null;

            ThrowOnError(NativeMethods.CreateAssemblyCache(out cache, 0));

            var info = new AssemblyInfo
            {
                cbAssemblyInfo = (uint)Marshal.SizeOf(typeof(AssemblyInfo))
            };

            //ProcessorArchitecture required for this call
            fullName = assemblyName;

            if (HasProcessorArchitecture(fullName))
            {
                //getting size of string, cchBuf will be the size
                cache.QueryAssemblyInfo(3, fullName, ref info);
            }
            else
            {
                //try using possible proccessors
                foreach (string p in proccessors)
                {
                    fullName = AppendProccessor(assemblyName, p);
                    cache.QueryAssemblyInfo(3, fullName, ref info);

                    //if no size, not found, try another proccessor
                    if (info.cchBuf > 0)
                    {
                        break;
                    }
                }
            }
            //if no size, not found
            if (info.cchBuf == 0)
            {
                return(null);
            }

            //get path
            info.pszCurrentAssemblyPathBuf = new string(new char[info.cchBuf]);
            ThrowOnError(cache.QueryAssemblyInfo(3, fullName, ref info));

            return(info.pszCurrentAssemblyPathBuf);
        }
Esempio n. 20
0
    public static void InstallAssembly(string path, bool forceRefresh)
    {
        IAssemblyCache iac = null;

        CreateAssemblyCache(out iac, 0);
        try {
            uint flags = forceRefresh ? 2u : 1u;
            int  hr    = iac.InstallAssembly(flags, path, IntPtr.Zero);
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
        finally {
            Marshal.FinalReleaseComObject(iac);
        }
    }
Esempio n. 21
0
        public MemoryAssemblyMembersCache(IAssemblyCache assemblyCache)
        {
            _assemblyCache = assemblyCache;
            AppDomain.CurrentDomain.AssemblyResolve += (object?sender, ResolveEventArgs args) =>
            {
                var task = assemblyCache.WaitFor(args.RequestingAssembly.FullName, 20000);
                task.Wait();

                var item = task.Result;
                if (item != null)
                {
                    //AppDomain.CurrentDomain.LO
                    var fullName = item.FullName;

                    var refs = item.GetReferencedAssemblies();
                    foreach (var @ref in refs)
                    {
                        if (AssemblyUtils.IsSystemAssembly(@ref) || AssemblyUtils.IsOskAssembly(@ref))
                        {
                            continue;
                        }
                        var asmDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                        var assembly     = Assembly.LoadFile(Path.Combine(asmDirectory, $"{@ref.Name}.dll"));
                        //var types = assembly.GetTypes();
                        //foreach (var type in types)
                        //{
                        //    try
                        //    {
                        //        var tobj = Activator.CreateInstance(type);
                        //        if (tobj != default)
                        //            break;
                        //    }
                        //    catch (Exception)
                        //    {
                        //        // ignore
                        //    }
                        //}
                    }

                    return(item);
                }

                return(null);
            };
        }
Esempio n. 22
0
        protected static void RemoveAssembly(string AssemblyName)
        {
            LogMessage("RemoveAssembly", "Uninstalling: " + AssemblyName);

            // Get an IAssemblyCache interface
            IAssemblyCache pCache = AssemblyCache.CreateAssemblyCache();

            IASSEMBLYCACHE_UNINSTALL_DISPOSITION puldisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNKNOWN; // Initialise variable

            int result = pCache.UninstallAssembly(0, AssemblyName, null, out puldisposition);

            if (result == 0)
            {
                LogMessage("RemoveAssembly", "Uninstalled without error!");
            }
            else
            {
                LogMessage("RemoveAssembly", "Uninstall returned status code: " + result);
            }

            switch (puldisposition)
            {
            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED:
                LogMessage("RemoveAssembly", "Outcome: Assembly already uninstalled"); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_DELETE_PENDING:
                LogMessage("RemoveAssembly", "Outcome: Delete currently pending"); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_HAS_INSTALL_REFERENCES:
                LogMessage("RemoveAssembly", "Outcome: Assembly has remaining install references"); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_REFERENCE_NOT_FOUND:
                LogMessage("RemoveAssembly", "Outcome: Unable to find assembly - " + AssemblyName); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_STILL_IN_USE:
                LogMessage("RemoveAssembly", "Outcome: Assembly still in use"); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED:
                LogMessage("RemoveAssembly", "Outcome: Assembly uninstalled"); break;

            default:
                LogMessage("RemoveAssembly", "Unknown uninstall outcome code: " + puldisposition); break;
            }
        }
        private IModule ResolveModule(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssembly assembly = this.ResolveAssembly(assemblyManager, assemblyCache);

            if (assembly != null)
            {
                string moduleName = this.item;

                foreach (IModule module in assembly.Modules)
                {
                    if (moduleName == module.Name)
                    {
                        return(module);
                    }
                }
            }

            return(null);
        }
Esempio n. 24
0
        public static void UninstallAssembly(string assemblyName, InstallReference reference, out AssemblyCacheUninstallDisposition disp)
        {
            AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;

            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid argument (reference guid).");
                }
            }

            IAssemblyCache asmCache = null;

            COM.CheckHR(CreateAssemblyCache(out asmCache, 0));
            COM.CheckHR(asmCache.UninstallAssembly(0, assemblyName, reference, out dispResult));

            disp = dispResult;
        }
Esempio n. 25
0
        /// <summary>
        /// Uninstalls the assembly, using the application as a reference.
        /// AssemblyName has to be fully specified name.
        /// A.k.a, for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx".
        /// For v2.0 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx".
        /// If assemblyName is not fully specified, a random matching assembly will be uninstalled.
        /// </summary>
        /// <param name="assemblyName"></param>
        private static AssemblyCacheUninstallDisposition UninstallAssemblyImplementation(String assemblyName)
        {
            AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;
            IAssemblyCache ac = null;

            int hr = GacUtils.CreateAssemblyCache(out ac, 0);

            if (hr >= 0)
            {
                hr = ac.UninstallAssembly(0, assemblyName, null, out dispResult);
            }

            if (hr < 0)
            {
                GacUtils.ThrowMarshalledException(hr);
            }

            return(dispResult);
        }
        private IResource ResolveResource(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssembly assembly = this.ResolveAssembly(assemblyManager, assemblyCache);

            if (assembly != null)
            {
                string resourceName = this.item;

                foreach (IResource resource in assembly.Resources)
                {
                    if (resourceName == resource.Name)
                    {
                        return(resource);
                    }
                }
            }

            return(null);
        }
Esempio n. 27
0
        public void GacInstall(string assemblyPath)
        {
#if !FEATURE_PAL
            IAssemblyCache ac = null;
            int            hr = NativeMethods.CreateAssemblyCache(out ac, 0);
            if (0 == hr)
            {
                hr = ac.InstallAssembly(0, assemblyPath, IntPtr.Zero);
            }
#else // !FEATURE_PAL
            int hr = -1;
            try
            {
                Process gacutilprocess = new System.Diagnostics.Process();
                if (gacutilprocess != null)
                {
                    gacutilprocess.StartInfo.CreateNoWindow = true;
#if PLATFORM_UNIX
                    gacutilprocess.StartInfo.FileName = "gacutil";
#else
                    gacutilprocess.StartInfo.FileName = "gacutil.exe";
#endif
                    gacutilprocess.StartInfo.UseShellExecute = false;
                    gacutilprocess.StartInfo.Arguments       = "/i " + assemblyPath;
                    gacutilprocess.Start();
                    while (!gacutilprocess.HasExited)
                    {
                        Thread.Sleep(250);
                    }
                    hr = gacutilprocess.ExitCode;
                }
            }
            catch (Exception)
            {
                hr = -1;
            }
#endif // FEATURE_PAL

            if (0 != hr)
            {
                throw new Exception(SR.GetString(SR.Failed_gac_install));
            }
        }
Esempio n. 28
0
        public static string QueryAssemblyInfo(string assemblyName)
        {
            if (assemblyName == null)
            {
                throw new ArgumentException("Invalid argument (assemblyName)");
            }

            AssemblyInfo aInfo = new AssemblyInfo();

            aInfo.cchBuf = 1024;
            aInfo.currentAssemblyPath = "Path".PadLeft(aInfo.cchBuf);

            IAssemblyCache ac = null;

            COM.CheckHR(CreateAssemblyCache(out ac, 0));
            COM.CheckHR(ac.QueryAssemblyInfo(0, assemblyName, ref aInfo));

            return(aInfo.currentAssemblyPath);
        }
Esempio n. 29
0
        public bool GacUnInstall(string assemblyName)
        {
            IAssemblyCache ppAsmCache     = null;
            uint           pulDisposition = 0;
            int            num2           = NativeMethods.CreateAssemblyCache(out ppAsmCache, 0);

            if (num2 == 0)
            {
                num2 = ppAsmCache.UninstallAssembly(0, assemblyName, IntPtr.Zero, out pulDisposition);
                if (pulDisposition == 3)
                {
                    return(false);
                }
            }
            if (num2 != 0)
            {
                throw new Exception(System.Web.SR.GetString("Failed_gac_uninstall"));
            }
            return(true);
        }
Esempio n. 30
0
        private static string GetLocationImpl(IAssemblyCache assemblyCache, string strongName, string targetProcessorArchitecture)
        {
            ASSEMBLY_INFO pAsmInfo = new ASSEMBLY_INFO
            {
                cbAssemblyInfo = (uint)Marshal.SizeOf(typeof(ASSEMBLY_INFO))
            };

            if (targetProcessorArchitecture != null)
            {
                strongName = strongName + ", ProcessorArchitecture=" + targetProcessorArchitecture;
            }
            int hr = assemblyCache.QueryAssemblyInfo((uint)AssemblyCacheEnum.QUERYASMINFO_FLAG_VALIDATE, strongName, ref pAsmInfo);

            if ((Win32NTMethods.Failed(hr) && (hr != Win32NTMethods.E_INSUFFICIENT_BUFFER)) || (pAsmInfo.cbAssemblyInfo == 0))
            {
                return(string.Empty);
            }
            pAsmInfo.pszCurrentAssemblyPathBuf = new string(new char[pAsmInfo.cchBuf]);
            return(!Win32NTMethods.Failed(assemblyCache.QueryAssemblyInfo(3, strongName, ref pAsmInfo)) ? pAsmInfo.pszCurrentAssemblyPathBuf : string.Empty);
        }
Esempio n. 31
0
 internal static extern int CreateAssemblyCache(
         out IAssemblyCache ppAsmCache,
         int reserved);
Esempio n. 32
0
 public static extern int CreateAssemblyCache(
     out IAssemblyCache assemblyCache,
     uint reserved);
Esempio n. 33
0
 private static extern IntPtr CreateAssemblyCache(
     out IAssemblyCache ppAsmCache,
     int reserved);
Esempio n. 34
0
 public static extern HResult CreateAssemblyCache(
     out IAssemblyCache ppAsmCache,
     int dwReserved);
Esempio n. 35
0
 static extern void CreateAssemblyCache(out IAssemblyCache ppAsmCache, uint dwReserved);
        private IResource ResolveResource(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssembly assembly = this.ResolveAssembly(assemblyManager, assemblyCache);
            if (assembly != null)
            {
                string resourceName = this.item;

                foreach (IResource resource in assembly.Resources)
                {
                    if (resourceName == resource.Name)
                    {
                        return resource;
                    }
                }
            }

            return null;
        }
        private IAssembly ResolveAssembly(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssemblyReference assemblyReference = this.ParseAssemblyReference(this.assembly, assemblyManager);

            for (int i = 0; i < assemblyManager.Assemblies.Count; i++)
            {
                IAssembly assembly = assemblyManager.Assemblies[i];
                if (assembly.Equals(assemblyReference))
                {
                    return assembly;
                }
            }

            if (assemblyCache != null)
            {
                string location = assemblyCache.QueryLocation(assemblyReference, null);
                if ((location != null) && (location.Length > 0))
                {
                    IAssembly assembly = assemblyManager.LoadFile(location);
                    return assembly;
                }
            }

            return null;
        }
        private IEventDeclaration ResolveEventDeclaration(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            ITypeDeclaration typeDeclaration = this.ResolveTypeDeclaration(assemblyManager, assemblyCache);
            if (typeDeclaration != null)
            {
                string eventName = this.member;

                foreach (IEventDeclaration eventDeclaration in typeDeclaration.Events)
                {
                    string text = this.GetEventReferenceText(eventDeclaration);
                    if (eventName == text)
                    {
                        return eventDeclaration;
                    }
                }
            }

            return null;
        }
        private IPropertyDeclaration ResolvePropertyDeclaration(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            ITypeDeclaration typeDeclaration = this.ResolveTypeDeclaration(assemblyManager, assemblyCache);
            if (typeDeclaration != null)
            {
                string propertyName = this.member;

                foreach (IPropertyDeclaration propertyDeclaration in typeDeclaration.Properties)
                {
                    string text = this.GetPropertyReferenceText(propertyDeclaration);
                    if (propertyName == text)
                    {
                        return propertyDeclaration;
                    }
                }
            }

            return null;
        }
        private IMethodDeclaration ResolveMethodDeclaration(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            ITypeDeclaration typeDeclaration = this.ResolveTypeDeclaration(assemblyManager, assemblyCache);
            if (typeDeclaration != null)
            {
                string methodName = this.member;

                foreach (IMethodDeclaration methodDeclaration in typeDeclaration.Methods)
                {
                    string text = this.GetMethodReferenceText(methodDeclaration);
                    if (methodName == text)
                    {
                        return methodDeclaration;
                    }
                }
            }

            return null;
        }
        private IFieldDeclaration ResolveFieldDeclaration(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            ITypeDeclaration typeDeclaration = this.ResolveTypeDeclaration(assemblyManager, assemblyCache);
            if (typeDeclaration != null)
            {
                string fieldName = this.member;

                foreach (IFieldDeclaration fieldDeclaration in typeDeclaration.Fields)
                {
                    string text = this.GetFieldReferenceText(fieldDeclaration);
                    if (fieldName == text)
                    {
                        return fieldDeclaration;
                    }
                }
            }

            return null;
        }
        private ITypeDeclaration ResolveTypeDeclaration(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssembly[] assemblyList = new IAssembly[assemblyManager.Assemblies.Count];
            assemblyManager.Assemblies.CopyTo(assemblyList, 0);

            if ((this.assembly != null) && (this.assembly.Length > 0))
            {
                IAssembly assembly = this.ResolveAssembly(assemblyManager, assemblyCache);
                assemblyList = (assembly != null) ? new IAssembly[] { assembly } : new IAssembly[0];
            }

            string typeName = this.item;

            foreach (IAssembly assembly in assemblyList)
            {
                foreach (IModule module in assembly.Modules)
                {
                    foreach (ITypeDeclaration typeDeclaration in module.Types)
                    {
                        foreach (ITypeDeclaration currentType in GetNestedTypeList(typeDeclaration))
                        {
                            string text = this.GetTypeReferenceText(currentType);
                            if (typeName == text)
                            {
                                return currentType;
                            }
                        }
                    }
                }
            }

            return null;
        }
        public object Resolve(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            switch (this.type)
            {
                case CodeIdentifierType.None:
                    return null;

                case CodeIdentifierType.Assembly:
                    return this.ResolveAssembly(assemblyManager, assemblyCache);

                case CodeIdentifierType.Module:
                    return this.ResolveModule(assemblyManager, assemblyCache);

                case CodeIdentifierType.Resource:
                    return this.ResolveResource(assemblyManager, assemblyCache);

                case CodeIdentifierType.Type:
                    return this.ResolveTypeDeclaration(assemblyManager, assemblyCache);

                case CodeIdentifierType.Field:
                    return this.ResolveFieldDeclaration(assemblyManager, assemblyCache);

                case CodeIdentifierType.Method:
                    return this.ResolveMethodDeclaration(assemblyManager, assemblyCache);

                case CodeIdentifierType.Property:
                    return this.ResolvePropertyDeclaration(assemblyManager, assemblyCache);

                case CodeIdentifierType.Event:
                    return this.ResolveEventDeclaration(assemblyManager, assemblyCache);
            }

            throw new NotSupportedException("Unable to resolve code identifier.");
        }
Esempio n. 44
0
 private static extern int CreateAssemblyCache(out IAssemblyCache ppAsmCache, uint dwReserved);
        private IModule ResolveModule(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssembly assembly = this.ResolveAssembly(assemblyManager, assemblyCache);
            if (assembly != null)
            {
                string moduleName = this.item;

                foreach (IModule module in assembly.Modules)
                {
                    if (moduleName == module.Name)
                    {
                        return module;
                    }
                }
            }

            return null;
        }