public static extern int CreateAssemblyEnum( out IAssemblyEnum ppEnum, IApplicationContext pAppCtx, IAssemblyName pName, uint dwFlags, int pvReserved );
private static string GetName(IAssemblyName name) { uint bufferSize = 255; var stringBuilder = new StringBuilder((int)bufferSize); name.GetName(ref bufferSize, stringBuilder); return stringBuilder.ToString().Trim(); }
public InstallReferenceEnumerator(IAssemblyName assemblyName) { var hr = FusionImports.CreateInstallReferenceEnum(out refEnum, assemblyName, 0, IntPtr.Zero); if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } }
private String GetFullName(IAssemblyName fusionAsmName) { StringBuilder sDisplayName = new StringBuilder(1024); int iLen = 1024; int hr = fusionAsmName.GetDisplayName(sDisplayName, ref iLen, (int)AssemblyNameDisplayFlags.ALL); if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } return sDisplayName.ToString(); }
public ExecuteScriptCommand(string script, string[] scriptArgs, IFileSystem fileSystem, IScriptExecutor scriptExecutor, IScriptPackResolver scriptPackResolver, ILog logger, IAssemblyName assemblyName) { _script = script; ScriptArgs = scriptArgs; _fileSystem = fileSystem; _scriptExecutor = scriptExecutor; _scriptPackResolver = scriptPackResolver; _logger = logger; _assemblyName = assemblyName; }
private static string GetDisplayName(IAssemblyName native) { int bufferSize = 1024; StringBuilder buffer = new StringBuilder(bufferSize); AssemblyDisplayFlags dwDisplayFlags = AssemblyDisplayFlags.ProcessorArchitecture | AssemblyDisplayFlags.PublicKeyToken | AssemblyDisplayFlags.LanguageId | AssemblyDisplayFlags.Culture | AssemblyDisplayFlags.Version; if (NativeMethods.SUCCESS == native.GetDisplayName(buffer, ref bufferSize, dwDisplayFlags)) { return buffer.ToString(); } return null; }
public ExecuteReplCommand( IFileSystem fileSystem, IScriptPackResolver scriptPackResolver, IScriptEngine scriptEngine, IFilePreProcessor filePreProcessor, ILog logger, IConsole console, IAssemblyName assemblyName ) { _fileSystem = fileSystem; _scriptPackResolver = scriptPackResolver; _scriptEngine = scriptEngine; _filePreProcessor = filePreProcessor; _logger = logger; _console = console; _assemblyName = assemblyName; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyDescription"/> class. /// </summary> /// <param name="assemblyName">Name of the assembly.</param> public AssemblyDescription(IAssemblyName assemblyName) { // Get the qualified name. var stringBuilder = new StringBuilder(10000); var iLen = 10000; var hr = assemblyName.GetDisplayName(stringBuilder, ref iLen, ASM_DISPLAY_FLAGS.ASM_DISPLAYF_VERSION | ASM_DISPLAY_FLAGS.ASM_DISPLAYF_CULTURE | ASM_DISPLAY_FLAGS.ASM_DISPLAYF_PUBLIC_KEY_TOKEN | ASM_DISPLAY_FLAGS.ASM_DISPLAYF_PROCESSORARCHITECTURE); if (hr < 0) Marshal.ThrowExceptionForHR(hr); var displayName = stringBuilder.ToString(); // Load properties from the display name. LoadPropertiesFromDisplayName(displayName); // We have the assembly name, so we can use the optimised version to load the fusion properties. lazyFusionProperties = new Lazy<AssemblyFusionProperties>(DoLoadFusionProperties); lazyReflectionProperties = new Lazy<AssemblyReflectionProperties>(DoLoadReflectionProperties); }
public static AssemblyName ToAssemblyName(IAssemblyName native) { string displayName = GetDisplayName(native); using (AssemblyCache cache = new AssemblyCache()) { // according to MSKB, this is a SUPPORTED method, therefore we can use the obtained path // in the ASSEMBLY_INFO struct to generate a fully-populated AssemblyName object. // see: http://support.microsoft.com/kb/317540 string path = cache.QueryAssemblyPath(displayName); if (path != null) { return AssemblyName.GetAssemblyName(path); } } return new AssemblyName(displayName); }
public ScriptServiceRoot( IFileSystem fileSystem, IPackageAssemblyResolver packageAssemblyResolver, IScriptExecutor executor, IScriptEngine engine, IFilePreProcessor filePreProcessor, IScriptPackResolver scriptPackResolver, IPackageInstaller packageInstaller, ILog logger, IAssemblyName assemblyName, IConsole console = null) { FileSystem = fileSystem; PackageAssemblyResolver = packageAssemblyResolver; Executor = executor; Engine = engine; FilePreProcessor = filePreProcessor; ScriptPackResolver = scriptPackResolver; PackageInstaller = packageInstaller; Logger = logger; Console = console; AssemblyName = assemblyName; }
/// <summary> /// Gets the public key. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static byte[] GetPublicKey(IAssemblyName name) { uint bufferSize = 512; IntPtr buffer = Marshal.AllocHGlobal((int) bufferSize); name.GetProperty(ASM_NAME.ASM_NAME_PUBLIC_KEY, buffer, ref bufferSize); var result = new byte[bufferSize]; for (int i = 0; i < bufferSize; i++) result[i] = Marshal.ReadByte(buffer, i); Marshal.FreeHGlobal(buffer); return result; }
/// <summary> /// Gets the display name. /// </summary> /// <param name="name">The name.</param> /// <param name="which">The which.</param> /// <returns></returns> public static String GetDisplayName(IAssemblyName name, ASM_DISPLAY_FLAGS which) { uint bufferSize = 255; var buffer = new StringBuilder((int) bufferSize); name.GetDisplayName(buffer, ref bufferSize, which); return buffer.ToString(); }
/// <summary> /// Gets the version. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static Version GetVersion(IAssemblyName name) { uint major; uint minor; name.GetVersion(out major, out minor); return new Version((int) major >> 16, (int) major & 0xFFFF, (int) minor >> 16, (int) minor & 0xFFFF); }
static extern void CreateAssemblyEnum(out IAssemblyEnum pEnum, IntPtr pUnkReserved, IAssemblyName pName, AssemblyCacheFlags dwFlags, IntPtr pvReserved);
public static extern int CreateAssemblyEnum( out IAssemblyEnum ppEnum, // Pointer to a memory location that contains the IAssemblyEnum pointer IApplicationContext pAppCtx, // Must be null. ??? IAssemblyName pName, // An assembly name that is used to filter the enumeration. Can be null to enumerate all assemblies in the GAC. ASM_CACHE_FLAGS dwFlags, // Exactly one bit from the ASM_CACHE_FLAGS enumeration. int pvReserved); // Must be NULL
private static void AssertName(IAssemblyName assemblyName, string expected) { var actual = assemblyName.Name; Assert.AreEqual(expected, actual); }
internal static extern int CreateAssemblyCacheItem(out IAssemblyCacheItem ppasm, IAssemblyName pName, [MarshalAs(UnmanagedType.LPWStr)] String pszCodebase, ref FILETIME pftLastMod, uint dwInstaller, uint dwReserved);
internal static extern int CreateAssemblyNameObject( out IAssemblyName ppAssemblyNameObj, [MarshalAs(UnmanagedType.LPWStr)] String szAssemblyName, CreateAssemblyNameObjectFlags flags, IntPtr pvReserved);
private static void AssertVersion(IAssemblyName assemblyName, string expectedVersion) { var actual = assemblyName.Version; Assert.AreEqual(new AssemblyVersion(expectedVersion), actual); }
/// <inheritdoc /> public IAssembly Load(IAssemblyName assemblyRef) { var un = ((IWrap<AssemblyName>)assemblyRef).UnderlyingObject; return new AssemblyWrap(_underlyingObject.Load(un)); }
internal static extern int CreateAssemblyEnum( out IAssemblyEnum ppEnum, IntPtr pUnkReserved, IAssemblyName pName, AssemblyCacheFlags flags, IntPtr pvReserved);
/// <inheritdoc /> public int ExecuteAssemblyByName(IAssemblyName assemblyName, Evidence assemblySecurity, params string[] args) { IWrap<AssemblyName> real = (IWrap<AssemblyName>)assemblyName; return _underlyingObject.ExecuteAssemblyByName(real.UnderlyingObject, assemblySecurity, args); }
public static extern int CreateAssemblyNameObject( [Out] out IAssemblyName ppAssemblyNameObj, [In] string szAssemblyName, [In] uint dwFlags, [In] IntPtr pvReserved);
public static extern int CreateAssemblyEnum( [Out] out IAssemblyEnum pEnum, [In] IntPtr pUnkReserved, [In] IAssemblyName pName, [In] uint dwFlags, [In] IntPtr pvReserved);
/// <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); }
internal static extern int CreateAssemblyNameObject(out IAssemblyName ppName, string szAssemblyName, uint dwFlags, int pvReserved);
private static extern int RealCreateAssemblyNameObject(out IAssemblyName ppEnum, [MarshalAs(UnmanagedType.LPWStr)] string szAssemblyName, uint dwFlags, IntPtr pvReserved);
private static extern int CreateAssemblyNameObject(out IAssemblyName ppName, string szAssemblyName, uint dwFlags, int pvReserved);
}// 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
internal static extern int CreateAssemblyEnum(out IAssemblyEnum ppEnum, IApplicationContext pAppCtx, IAssemblyName pName, uint dwFlags, int pvReserved);
static extern void CreateAssemblyNameObject(out IAssemblyName ppAssemblyNameObj, string szAssemblyName, uint dwFlags, IntPtr pvReserved);
public bool ReferenceMatchesDefinition(IAssemblyName reference, IAssemblyName definition) { return(AssemblyName.ReferenceMatchesDefinition(reference.AssemblyNameInstance, definition.AssemblyNameInstance)); }
static extern void CreateAssemblyEnum(out IAssemblyEnum pEnum, IntPtr pUnkReserved, IAssemblyName pName, ASM_CACHE_FLAGS dwFlags, IntPtr pvReserved);
internal static string GetName(IAssemblyName nameObject) { return(GetPropertyString(nameObject, PropertyId.NAME)); }
static extern void CreateInstallReferenceEnum(out IInstallReferenceEnum ppRefEnum, IAssemblyName pName, uint dwFlags, IntPtr pvReserved);
public static extern int CreateAssemblyNameObject( out IAssemblyName ppEnum, // Pointer to a memory location that receives the IAssemblyName pointer that is created. string szAssemblyName, // A string representation of the assembly name or of a full assembly reference that is determined by dwFlags. The string representation can be null. CREATE_ASM_NAME_OBJ_FLAGS dwFlags, // Zero or more of the bits that are defined in the CREATE_ASM_NAME_OBJ_FLAGS enumeration. int pvReserved); // Must be null.
/// <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)); }
private static extern void CreateAssemblyEnum(out IAssemblyEnum pEnum, IntPtr pUnkReserved, IAssemblyName pName, ASM_CACHE_FLAGS dwFlags, IntPtr pvReserved);
internal AssemblyName(IAssemblyName /*!*/ assemblyName) { this.assemblyName = assemblyName; //^ base(); }
/// <summary> /// Gets the name. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static String GetName(IAssemblyName name) { uint bufferSize = 255; var buffer = new StringBuilder((int) bufferSize); name.GetName(ref bufferSize, buffer); return buffer.ToString(); }
internal static extern int CreateInstallReferenceEnum( out IInstallReferenceEnum ppRefEnum, IAssemblyName pName, int dwFlags, IntPtr pvReserved);
/// <summary> /// Gets the public key token. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static byte[] GetPublicKeyToken(IAssemblyName name) { var result = new byte[8]; uint bufferSize = 8; IntPtr buffer = Marshal.AllocHGlobal((int) bufferSize); name.GetProperty(ASM_NAME.ASM_NAME_PUBLIC_KEY_TOKEN, buffer, ref bufferSize); for (int i = 0; i < 8; i++) result[i] = Marshal.ReadByte(buffer, i); Marshal.FreeHGlobal(buffer); return result; }
internal static extern int CreateAssemblyNameObject(out IAssemblyName ppEnum, String szAssemblyName, uint dwFlags, IntPtr pvReserved);
/// <summary> /// Gets the culture. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static CultureInfo GetCulture(IAssemblyName name) { uint bufferSize = 255; IntPtr buffer = Marshal.AllocHGlobal((int) bufferSize); name.GetProperty(ASM_NAME.ASM_NAME_CULTURE, buffer, ref bufferSize); string result = Marshal.PtrToStringAuto(buffer); Marshal.FreeHGlobal(buffer); if (result != null) { return new CultureInfo(result); } return null; }
internal byte[] GetByteArrayProperty(IAssemblyName name, ASM_NAME propertyName) { uint bufferSize = 512; IntPtr buffer = Marshal.AllocHGlobal((int)bufferSize); name.GetProperty(propertyName, buffer, ref bufferSize); byte[] result = new byte[bufferSize]; for (int i = 0; i < bufferSize; i++) result[i] = Marshal.ReadByte(buffer, i); Marshal.FreeHGlobal(buffer); return result; }
internal AssemblyName(IAssemblyName /*!*/ assemblyName) { this.assemblyName = assemblyName; }
internal UInt16 GetShortProperty(IAssemblyName name, ASM_NAME propertyName) { uint bufferSize = 512; IntPtr buffer = Marshal.AllocHGlobal((int)bufferSize); name.GetProperty(propertyName, buffer, ref bufferSize); byte low = Marshal.ReadByte(buffer); byte high = Marshal.ReadByte(buffer, 1); Marshal.FreeHGlobal(buffer); return (UInt16)(low + (high << 8)); }
public IAssembly Load(IAssemblyName assemblyRef) { return(new AssemblyWrap(Assembly.Load(assemblyRef.AssemblyNameInstance))); }
public IAssembly Load(IAssemblyName assemblyRef) { return new AssemblyWrap(Assembly.Load(assemblyRef.AssemblyNameInstance)); }
internal static string GetCulture(IAssemblyName nameObject) { return(GetPropertyString(nameObject, PropertyId.CULTURE)); }
/// <summary> /// Loads the fusion properties given the assembly name COM object. /// </summary> /// <param name="assemblyName">Name of the assembly.</param> public void Load(IAssemblyName assemblyName) { // Load the properties. MajorVersion = GetShortProperty(assemblyName, ASM_NAME.ASM_NAME_MAJOR_VERSION); MinorVersion = GetShortProperty(assemblyName, ASM_NAME.ASM_NAME_MINOR_VERSION); BuildNumber = GetShortProperty(assemblyName, ASM_NAME.ASM_NAME_BUILD_NUMBER); RevisionNumber = GetShortProperty(assemblyName, ASM_NAME.ASM_NAME_REVISION_NUMBER); PublicKey = GetByteArrayProperty(assemblyName, ASM_NAME.ASM_NAME_PUBLIC_KEY); // Create an install reference enumerator. var enumerator = new InstallReferenceEnumerator(assemblyName); var reference = enumerator.GetNextReference(); while (reference != null) { InstallReferences.Add(reference); reference = enumerator.GetNextReference(); } // Load the reserved properties. //ReservedHashValue = GetByteArrayProperty(assemblyName, ASM_NAME.ASM_NAME_HASH_VALUE); //ReservedHashAlgorithmId = GetDwordProperty(assemblyName, ASM_NAME.ASM_NAME_HASH_ALGID); }
internal static AssemblyContentType GetContentType(IAssemblyName nameObject) { return((AssemblyContentType)(GetPropertyWord(nameObject, PropertyId.CONTENT_TYPE) ?? 0)); }
internal UInt32 GetDwordProperty(IAssemblyName name, ASM_NAME propertyName) { uint bufferSize = 512; IntPtr buffer = Marshal.AllocHGlobal((int)bufferSize); name.GetProperty(propertyName, buffer, ref bufferSize); byte a = Marshal.ReadByte(buffer); byte b = Marshal.ReadByte(buffer, 1); byte c = Marshal.ReadByte(buffer); byte d = Marshal.ReadByte(buffer, 1); Marshal.FreeHGlobal(buffer); return (UInt32)(a + (b << 8) + (c << 16) + (d << 24)); }
internal static CultureInfo GetCultureInfo(IAssemblyName nameObject) { var cultureName = GetCulture(nameObject); return((cultureName != null) ? new CultureInfo(cultureName) : null); }
internal string GetStringProperty(IAssemblyName name, ASM_NAME propertyName) { uint bufferSize = BufferLength; IntPtr buffer = Marshal.AllocHGlobal((int)bufferSize); name.GetProperty(propertyName, buffer, ref bufferSize); var stringVaule = Marshal.PtrToStringUni(buffer, (int)bufferSize); Marshal.FreeHGlobal(buffer); return stringVaule; }
internal static ProcessorArchitecture GetProcessorArchitecture(IAssemblyName nameObject) { return((ProcessorArchitecture)(GetPropertyWord(nameObject, PropertyId.ARCHITECTURE) ?? 0)); }
internal AssemblyName(IAssemblyName assemblyName){ this.assemblyName = assemblyName; }
private static unsafe void SetProperty(IAssemblyName nameObject, PropertyId propertyId, uint data) { nameObject.SetProperty(propertyId, &data, sizeof(uint)); }