public IList <string> GetAllAssemblies() { List <string> assemblies = new List <string>(); // Enumerate. IAssemblyEnum assemblyEnum = AssemblyCache.CreateGACEnum(); IAssemblyName assemblyName; assemblyEnum.GetNextAssembly(IntPtr.Zero, out assemblyName, 0); while (assemblyName != null) { // Grab the name and the version. uint size = 10000; StringBuilder sb = new StringBuilder((int)size); int ret = assemblyName.GetDisplayName(sb, ref size, ASM_DISPLAY_FLAGS.VERSION); if (ret == 0) { assemblies.Add(sb.ToString()); } assemblyEnum.GetNextAssembly(IntPtr.Zero, out assemblyName, 0); } return(assemblies); }
/// <summary> /// Gets the names of all assemblies in the GAC. /// </summary> public static IEnumerable <AssemblyNameInfo> GetGacAssemblyFullNames() { IApplicationContext applicationContext = null; IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName = null; Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0); while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { uint nChars = 0; assemblyName.GetDisplayName(null, ref nChars, 0); StringBuilder name = new StringBuilder((int)nChars); assemblyName.GetDisplayName(name, ref nChars, 0); AssemblyNameInfo r = null; try { r = new AssemblyNameInfo(name.ToString()); } catch (ArgumentException) { } catch (FormatException) { } catch (OverflowException) { } if (r != null) { yield return(r); } } }
public static void ReadCache(ArrayList alAssems, String name, uint nFlag) { IAssemblyEnum aEnum = null; IApplicationContext AppCtx = null; IAssemblyName aName = null; IAssemblyName pNameEnum = null; int hr; if (name != null) { hr = CreateAssemblyNameObject(out pNameEnum, name, CANOF.PARSE_DISPLAY_NAME, 0); if (hr != 0) { return; } } hr = CreateAssemblyEnum(out aEnum, null, pNameEnum, nFlag, 0); while (hr == 0) { hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0); if (hr == 0) { uint iLen = 0; IntPtr pDisplayName = (IntPtr)0; // Get the length of the string we need aName.GetDisplayName((IntPtr)0, ref iLen, 0); if (iLen > 0) { // Do some yucky memory allocating here // We need to assume that a wide character is 2 bytes. pDisplayName = Marshal.AllocHGlobal(((int)iLen + 1) * 2); aName.GetDisplayName(pDisplayName, ref iLen, 0); String sDisplayName = Marshal.PtrToStringUni(pDisplayName); Marshal.FreeHGlobal(pDisplayName); // Our info is in a comma seperated list. Let's pull it out String[] sFields = sDisplayName.Split(new char[] { ',' }); AssemblyInformation newguy = new AssemblyInformation(); newguy.FullName = sDisplayName; newguy.Name = sFields[0]; // The version string is represented as Version=###### // Let's take out the 'Version=' newguy.Version = sFields[1].Substring(sFields[1].IndexOf('=') + 1); // Same goes for the locale newguy.Locale = sFields[2].Substring(sFields[2].IndexOf('=') + 1); // And the key token sFields[3] = sFields[3].Substring(sFields[3].IndexOf('=') + 1); if (sFields[3].Equals("null")) { sFields[3] = "null"; } newguy.PublicKeyToken = sFields[3]; alAssems.Add(newguy); } } } }
static GAC() { assemblies = new ArrayList(); IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName = null; Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, (uint)Fusion.AssemblyCacheFlags.GAC, IntPtr.Zero); assemblyEnum.GetNextAssembly(IntPtr.Zero, out assemblyName, 0); while (assemblyName != null) { uint ccbuf = 1024; StringBuilder sb = new StringBuilder((int)ccbuf); assemblyName.GetDisplayName(sb, ref ccbuf, (uint)Fusion.AssemblyNameDisplayFlags.ALL); assemblies.Add(new AssemblyName(sb.ToString())); assemblyEnum.GetNextAssembly(IntPtr.Zero, out assemblyName, 0); } }
public bool MoveNext() { IAssemblyName ae; IApplicationContext context; var hResult = _enum.GetNextAssembly(out context, out ae, 0); _current = ae != null && hResult == 0 ? ae.ToAssemblyName() : null; return(_current != null); }
public static IEnumerable <AssemblyName> GetAssemblies() { IAssemblyEnum assemblyEnum = null; ComCheck(FusionApi.CreateAssemblyEnum(out assemblyEnum, IntPtr.Zero, null, AssemblyCacheFlags.Gac, IntPtr.Zero)); IAssemblyName fusionAssemblyName = null; do { ComCheck(assemblyEnum.GetNextAssembly(IntPtr.Zero, out fusionAssemblyName, 0)); if (fusionAssemblyName != null) { yield return(new AssemblyName(GlobalAssemblyCache.GetDisplayName(fusionAssemblyName))); } } while (fusionAssemblyName != null); }
public static void ReadCache(ArrayList alAssems, string name, uint nFlag) { IAssemblyEnum ppEnum1 = (IAssemblyEnum)null; IAssemblyName ppName = (IAssemblyName)null; IAssemblyName ppEnum2 = (IAssemblyName)null; IApplicationContext ppAppCtx = (IApplicationContext)null; if (name != null) { int assemblyNameObject = Win32Native.CreateAssemblyNameObject(out ppEnum2, name, 1U, IntPtr.Zero); if (assemblyNameObject != 0) { Marshal.ThrowExceptionForHR(assemblyNameObject); } } int assemblyEnum = Win32Native.CreateAssemblyEnum(out ppEnum1, ppAppCtx, ppEnum2, nFlag, IntPtr.Zero); if (assemblyEnum != 0) { Marshal.ThrowExceptionForHR(assemblyEnum); } while (true) { string displayName; do { int nextAssembly = ppEnum1.GetNextAssembly(out ppAppCtx, out ppName, 0U); if (nextAssembly != 0) { if (nextAssembly < 0) { Marshal.ThrowExceptionForHR(nextAssembly); return; } goto label_10; } else { displayName = Fusion.GetDisplayName(ppName, 0U); } }while (displayName == null); alAssems.Add((object)displayName); } label_10 :; }
IEnumerable <DomAssemblyName> GetGacAssemblyFullNames() { IApplicationContext applicationContext = null; IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName = null; Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0); while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { uint nChars = 0; assemblyName.GetDisplayName(null, ref nChars, 0); StringBuilder name = new StringBuilder((int)nChars); assemblyName.GetDisplayName(name, ref nChars, 0); yield return(new DomAssemblyName(name.ToString())); } }
[System.Security.SecurityCritical] // auto-generated public static void ReadCache(ArrayList alAssems, String name, uint nFlag) { IAssemblyEnum aEnum = null; IAssemblyName aName = null; IAssemblyName aNameEnum = null; IApplicationContext AppCtx = null; int hr; if (name != null) { hr = Win32Native.CreateAssemblyNameObject(out aNameEnum, name, CANOF.PARSE_DISPLAY_NAME, IntPtr.Zero); if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } } hr = Win32Native.CreateAssemblyEnum(out aEnum, AppCtx, aNameEnum, nFlag, IntPtr.Zero); if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } for (; ;) { hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0); if (hr != 0) { if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } break; } String sDisplayName = GetDisplayName(aName, 0); if (sDisplayName == null) { continue; } alAssems.Add(sDisplayName); } // for (;;) }
public static List <DomAssemblyName> GetAssemblyList() { IApplicationContext applicationContext = null; IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName = null; List <DomAssemblyName> l = new List <DomAssemblyName>(); Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0); while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { uint nChars = 0; assemblyName.GetDisplayName(null, ref nChars, 0); StringBuilder sb = new StringBuilder((int)nChars); assemblyName.GetDisplayName(sb, ref nChars, 0); l.Add(new DomAssemblyName(sb.ToString())); } return(l); }
public static void ReadCache(ArrayList alAssems, string name, uint nFlag) { IAssemblyEnum assemblyEnum = null; IAssemblyName aName = null; IAssemblyName pName = null; IApplicationContext pAppCtx = null; int num; if (name != null) { num = Win32Native.CreateAssemblyNameObject(out pName, name, 1U, IntPtr.Zero); if (num != 0) { Marshal.ThrowExceptionForHR(num); } } num = Win32Native.CreateAssemblyEnum(out assemblyEnum, pAppCtx, pName, nFlag, IntPtr.Zero); if (num != 0) { Marshal.ThrowExceptionForHR(num); } for (;;) { num = assemblyEnum.GetNextAssembly(out pAppCtx, out aName, 0U); if (num != 0) { break; } string displayName = Fusion.GetDisplayName(aName, 0U); if (displayName != null) { alAssems.Add(displayName); } } if (num < 0) { Marshal.ThrowExceptionForHR(num); return; } }
/// <summary> /// Gets the names of all assemblies in the GAC. /// </summary> public static IEnumerable <AssemblyNameInfo> GetGacAssemblyFullNames() { IApplicationContext applicationContext = null; IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName = null; Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0); while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { uint nChars = 0; assemblyName.GetDisplayName(null, ref nChars, 0); StringBuilder name = new StringBuilder((int)nChars); assemblyName.GetDisplayName(name, ref nChars, 0); var r = new AssemblyNameInfo(name.ToString()); if (r.Version != null) { yield return(r); } } }
/// <summary> /// Gets the names of all assemblies in the GAC. /// </summary> public static IEnumerable <AssemblyNameReference> GetGacAssemblyFullNames() { IApplicationContext applicationContext = null; IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName = null; uint result = unchecked ((uint)Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0)); if (result == 0x80070005) { MessageBox.Show($"Cannot access GAC, please restart with elevated privileges! (HRESULT 0x{result:X})", "ILSpy", MessageBoxButton.OK, MessageBoxImage.Error); yield break; } while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { if (assemblyName == null) { continue; } uint nChars = 0; assemblyName.GetDisplayName(null, ref nChars, 0); StringBuilder name = new StringBuilder((int)nChars); assemblyName.GetDisplayName(name, ref nChars, 0); AssemblyNameReference r = null; try { r = AssemblyNameReference.Parse(name.ToString()); } catch (ArgumentException) { } catch (FormatException) { } catch (OverflowException) { } if (r != null) { yield return(r); } } }
public static void ReadCache(ArrayList alAssems, string name, uint nFlag) { IAssemblyEnum ppEnum = null; IAssemblyName ppName = null; IAssemblyName name3 = null; IApplicationContext pAppCtx = null; int num; if (name != null) { num = Win32Native.CreateAssemblyNameObject(out name3, name, 1, IntPtr.Zero); if (num != 0) { Marshal.ThrowExceptionForHR(num); } } num = Win32Native.CreateAssemblyEnum(out ppEnum, pAppCtx, name3, nFlag, IntPtr.Zero); if (num != 0) { Marshal.ThrowExceptionForHR(num); } Label_0042: num = ppEnum.GetNextAssembly(out pAppCtx, out ppName, 0); if (num == 0) { string displayName = GetDisplayName(ppName, 0); if (displayName != null) { alAssems.Add(displayName); } goto Label_0042; } if (num < 0) { Marshal.ThrowExceptionForHR(num); } }
static IEnumerable <Mono.Cecil.AssemblyNameReference> _loadGAC(uint dwFlags) { IApplicationContext applicationContext = null; IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName = null; Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, dwFlags, 0); while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { uint nChars = 0; assemblyName.GetDisplayName(null, ref nChars, 0); StringBuilder name = new StringBuilder((int)nChars); assemblyName.GetDisplayName(name, ref nChars, 0); Mono.Cecil.AssemblyNameReference r = null; try { r = Mono.Cecil.AssemblyNameReference.Parse(name.ToString()); } catch (ArgumentException) { } catch (FormatException) { } catch (OverflowException) { } if (r != null) { yield return(r); } } }
public bool MoveNext() { EnforceNotDisposed(); IAssemblyName native; if (_enumerator.GetNextAssembly(IntPtr.Zero, out native, 0) == 0) { try { _current = AssemblyNameConvertor.ToAssemblyName(native); } finally { Marshal.ReleaseComObject(native); } } else { _current = null; } return(_current != null); }
}// ReadFusionCache private static void ReadCache(ArrayList alAssems, uint nFlag) { IAssemblyEnum aEnum = null; IApplicationContext AppCtx = null; IAssemblyName aName = null; int hr = CreateAssemblyEnum(out aEnum, null, null, nFlag, 0); while (hr == HRESULT.S_OK) { hr = aEnum.GetNextAssembly(out AppCtx, out aName, 0); if (hr == HRESULT.S_OK) { uint iLen = 0; IntPtr pDisplayName = (IntPtr)0; // Get the length of the string we need aName.GetDisplayName((IntPtr)0, ref iLen, 0); if (iLen > 0) { // Do some yucky memory allocating here // We need to assume that a wide character is 2 bytes. pDisplayName = Marshal.AllocHGlobal(((int)iLen + 1) * 2); aName.GetDisplayName(pDisplayName, ref iLen, 0); String sDisplayName = Marshal.PtrToStringUni(pDisplayName); Marshal.FreeHGlobal(pDisplayName); AssemInfo newguy = new AssemInfo(); newguy.sFusionName = sDisplayName; // Our info is in a comma seperated list. Let's pull it out String[] sFields = sDisplayName.Split(new char[] { ',' }); newguy.Name = sFields[0]; // The version string is represented as Version=###### // Let's take out the 'Version=' newguy.Version = sFields[1].Substring(sFields[1].IndexOf('=') + 1); // Same goes for the locale newguy.Locale = sFields[2].Substring(sFields[2].IndexOf('=') + 1); // And the internal key token sFields[3] = sFields[3].Substring(sFields[3].IndexOf('=') + 1); if (sFields[3].Equals("null")) { sFields[3] = CResourceStore.GetString("None"); } newguy.PublicKeyToken = sFields[3]; // Now get some more stuff we can't get from a 'GetDisplayName' call newguy.PublicKey = GetFusionString(aName, ASM_NAME.PUBLIC_KEY); newguy.Codebase = GetFusionString(aName, ASM_NAME.CODEBASE_URL); // newguy.Modified = GetFusionString(aName, ASM_NAME.CODEBASE_LASTMOD); // Currently, there's a fusion bug which prevents us from getting this information // We'll go out to the file system and get the data right now. newguy.Modified = ""; try { if (newguy.Codebase != null && newguy.Codebase.Length > 0) { Uri uCodebase = new Uri(newguy.Codebase); String sAbsolutePath = uCodebase.AbsolutePath; if (File.Exists(sAbsolutePath)) { newguy.Modified = File.GetLastWriteTime(sAbsolutePath).ToString(); } } } catch (Exception) { } newguy.ProcType = GetFusionString(aName, ASM_NAME.PROCESSOR_ID_ARRAY); newguy.OSType = GetFusionString(aName, ASM_NAME.OSINFO_ARRAY); newguy.OSVersion = ""; // We'll need to munge the OSINFO_ARRAY a bit // This will grab the ZAP signature newguy.sCustom = GetFusionString(aName, ASM_NAME.CUSTOM); newguy.nCacheType = nFlag; alAssems.Add(newguy); } } } }// ReadFusionCache
/// <summary> /// Get the next assembly name in the current enumerator or fail /// </summary> /// <param name="enumerator"></param> /// <param name="name"></param> /// <returns>0 if the enumeration is not at its end</returns> public static int GetNextAssembly(IAssemblyEnum enumerator, out IAssemblyName name) { return enumerator.GetNextAssembly((IntPtr) 0, out name, 0); }
public static DomAssemblyName FindBestMatchingAssemblyName(DomAssemblyName name) { string[] info; string version = name.Version; string publicKey = name.PublicKeyToken; IApplicationContext applicationContext = null; IAssemblyEnum assemblyEnum = null; IAssemblyName assemblyName; Fusion.CreateAssemblyNameObject(out assemblyName, name.ShortName, 0, 0); Fusion.CreateAssemblyEnum(out assemblyEnum, null, assemblyName, 2, 0); List <string> names = new List <string>(); while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0) { uint nChars = 0; assemblyName.GetDisplayName(null, ref nChars, 0); StringBuilder sb = new StringBuilder((int)nChars); assemblyName.GetDisplayName(sb, ref nChars, 0); string fullName = sb.ToString(); if (publicKey != null) { info = fullName.Split(','); if (publicKey != info[3].Substring(info[3].LastIndexOf('=') + 1)) { // Assembly has wrong public key continue; } } names.Add(fullName); } if (names.Count == 0) { return(null); } string best = null; Version bestVersion = null; Version currentVersion; if (version != null) { // use assembly with lowest version higher or equal to required version Version requiredVersion = new Version(version); for (int i = 0; i < names.Count; i++) { info = names[i].Split(','); currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1)); if (currentVersion.CompareTo(requiredVersion) < 0) { continue; // version not good enough } if (best == null || currentVersion.CompareTo(bestVersion) < 0) { bestVersion = currentVersion; best = names[i]; } } if (best != null) { return(new DomAssemblyName(best)); } } // use assembly with highest version best = names[0]; info = names[0].Split(','); bestVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1)); for (int i = 1; i < names.Count; i++) { info = names[i].Split(','); currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1)); if (currentVersion.CompareTo(bestVersion) > 0) { bestVersion = currentVersion; best = names[i]; } } return(new DomAssemblyName(best)); }
/// <summary> /// Get the next assembly name in the current enumerator or fail /// </summary> /// <param name="enumerator"></param> /// <param name="name"></param> /// <returns>0 if the enumeration is not at its end</returns> static int GetNextAssembly(IAssemblyEnum enumerator, out IAssemblyName name) { return(enumerator.GetNextAssembly((IntPtr)0, out name, 0)); }