/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="type">Type</param> /// <param name="flags">Flags</param> public EventDefUser(UTF8String name, ITypeDefOrRef type, EventAttributes flags) { this.name = name; this.eventType = type; this.attributes = (int)flags; }
/// <summary> /// Returns an assembly name string /// </summary> /// <param name="name">Simple assembly name</param> /// <param name="version">Version or <c>null</c></param> /// <param name="culture">Culture or <c>null</c></param> /// <param name="publicKey">Public key / public key token or <c>null</c></param> /// <param name="attributes">Assembly attributes</param> /// <returns>An assembly name string</returns> internal static string GetAssemblyNameString(UTF8String name, Version version, UTF8String culture, PublicKeyBase publicKey, AssemblyAttributes attributes) { var sb = new StringBuilder(); foreach (var c in UTF8String.ToSystemStringOrEmpty(name)) { if (c == ',' || c == '=') { sb.Append('\\'); } sb.Append(c); } if (version != null) { sb.Append(", Version="); sb.Append(CreateVersionWithNoUndefinedValues(version).ToString()); } if ((object)culture != null) { sb.Append(", Culture="); sb.Append(UTF8String.IsNullOrEmpty(culture) ? "neutral" : culture.String); } sb.Append(", "); sb.Append(publicKey == null || publicKey is PublicKeyToken ? "PublicKeyToken=" : "PublicKey="); sb.Append(publicKey == null ? "null" : publicKey.ToString()); if ((attributes & AssemblyAttributes.Retargetable) != 0) { sb.Append(", Retargetable=Yes"); } if ((attributes & AssemblyAttributes.ContentType_Mask) == AssemblyAttributes.ContentType_WindowsRuntime) { sb.Append(", ContentType=WindowsRuntime"); } return(sb.ToString()); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="signature">Signature</param> public FieldDefUser(UTF8String name, FieldSig signature) : this(name, signature, 0) { }
/// <summary> /// Compares two locales (cultures) /// </summary> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns>< 0 if a < b, 0 if a == b, > 0 if a > b</returns> internal static int LocaleCompareTo(UTF8String a, string b) { return(GetCanonicalLocale(a).CompareTo(GetCanonicalLocale(b))); }
/// <summary> /// Gets the hash code of a locale /// </summary> /// <param name="a">Value</param> /// <returns>The hash code</returns> internal static int GetHashCodeLocale(UTF8String a) { return(GetCanonicalLocale(a).GetHashCode()); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Simple name</param> /// <param name="version">Version</param> /// <param name="publicKey">Public key or public key token</param> /// <param name="locale">Locale</param> /// <exception cref="ArgumentNullException">If any of the args is invalid</exception> public AssemblyRefUser(UTF8String name, Version version, PublicKeyBase publicKey, UTF8String locale) { if ((object)name == null) { throw new ArgumentNullException("name"); } if (version == null) { throw new ArgumentNullException("version"); } if ((object)locale == null) { throw new ArgumentNullException("locale"); } this.name = name; this.version = version; this.publicKeyOrToken = publicKey; this.culture = locale; this.attributes = (int)(publicKey is PublicKey ? AssemblyAttributes.PublicKey : AssemblyAttributes.None); }
private MarshalType Read() { MarshalType returnValue; try { var nativeType = (NativeType)reader.ReadByte(); NativeType nt; int size; switch (nativeType) { case NativeType.FixedSysString: size = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; returnValue = new FixedSysStringMarshalType(size); break; case NativeType.SafeArray: var vt = CanRead() ? (VariantType)reader.ReadCompressedUInt32() : VariantType.NotInitialized; var udtName = CanRead() ? ReadUTF8String() : null; var udtRef = (object)udtName == null ? null : TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(udtName), null, gpContext); returnValue = new SafeArrayMarshalType(vt, udtRef); break; case NativeType.FixedArray: size = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; nt = CanRead() ? (NativeType)reader.ReadCompressedUInt32() : NativeType.NotInitialized; returnValue = new FixedArrayMarshalType(size, nt); break; case NativeType.Array: nt = CanRead() ? (NativeType)reader.ReadCompressedUInt32() : NativeType.NotInitialized; int paramNum = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; size = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; int flags = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; returnValue = new ArrayMarshalType(nt, paramNum, size, flags); break; case NativeType.CustomMarshaler: var guid = ReadUTF8String(); var nativeTypeName = ReadUTF8String(); var custMarshalerName = ReadUTF8String(); var cmRef = TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(custMarshalerName), new CAAssemblyRefFinder(module), gpContext); var cookie = ReadUTF8String(); returnValue = new CustomMarshalType(guid, nativeTypeName, cmRef, cookie); break; case NativeType.IUnknown: case NativeType.IDispatch: case NativeType.IntF: int iidParamIndex = CanRead() ? (int)reader.ReadCompressedUInt32() : -1; return(new InterfaceMarshalType(nativeType, iidParamIndex)); default: returnValue = new MarshalType(nativeType); break; } } catch { returnValue = new RawMarshalType(reader.ReadAllBytes()); } return(returnValue); }
public ClassName(string ns, string name, bool isValueType = false) { this.Namespace = ns; this.Name = name; this.IsValueType = isValueType; }
public bool Equals(ClassName other) { // Don't check IsValueType return(UTF8String.Equals(Namespace, other.Namespace) && UTF8String.Equals(Name, other.Name)); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="sequence">Sequence</param> /// <param name="flags">Flags</param> public ParamDefUser(UTF8String name, ushort sequence, ParamAttributes flags) { this.name = name; this.sequence = sequence; this.attributes = (int)flags; }
/// <summary> /// Constructor /// </summary> /// <param name="scope">Scope</param> /// <param name="name">Name</param> /// <param name="flags">Flags</param> public ImplMapUser(ModuleRef scope, UTF8String name, PInvokeAttributes flags) { this.module = scope; this.name = name; this.attributes = (int)flags; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="sequence">Sequence</param> public ParamDefUser(UTF8String name, ushort sequence) : this(name, sequence, 0) { }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> public ParamDefUser(UTF8String name) : this(name, 0) { }
/// <summary> /// Figures out which of two assembly names is closer to another assembly name /// </summary> /// <param name="requested">Requested assembly name</param> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns>-1 if both are equally close, 0 if <paramref name="a"/> is closest, 1 if /// <paramref name="b"/> is closest</returns> public int CompareClosest(IAssembly requested, IAssembly a, IAssembly b) { if (a == b) { return(0); } if (a == null) { return(!CompareName ? 1 : UTF8String.CaseInsensitiveEquals(requested.Name, b.Name) ? 1 : 0); } if (b == null) { return(!CompareName ? 0 : UTF8String.CaseInsensitiveEquals(requested.Name, a.Name) ? 0 : 1); } // Compare the most important parts first: // 1. Assembly simple name // 2. Public key token // 3. Version // 4. Locale // 5. Content type if (CompareName) { // If the name only matches one of a or b, return that one. bool na = UTF8String.CaseInsensitiveEquals(requested.Name, a.Name); bool nb = UTF8String.CaseInsensitiveEquals(requested.Name, b.Name); if (na && !nb) { return(0); } if (!na && nb) { return(1); } if (!na && !nb) { return(-1); } } if (ComparePublicKeyToken) { bool pa, pb; if (PublicKeyBase.IsNullOrEmpty2(requested.PublicKeyOrToken)) { // If one of them has a pkt but the other one hasn't, return the one with // no pkt. pa = PublicKeyBase.IsNullOrEmpty2(a.PublicKeyOrToken); pb = PublicKeyBase.IsNullOrEmpty2(b.PublicKeyOrToken); } else { // If one of them has the correct pkt, but the other one has an incorrect // pkt, return the one with the correct pkt. pa = PublicKeyBase.TokenEquals(requested.PublicKeyOrToken, a.PublicKeyOrToken); pb = PublicKeyBase.TokenEquals(requested.PublicKeyOrToken, b.PublicKeyOrToken); } if (pa && !pb) { return(0); } if (!pa && pb) { return(1); } } if (CompareVersion && !Utils.Equals(a.Version, b.Version)) { var rv = Utils.CreateVersionWithNoUndefinedValues(requested.Version); if (rv == new Version(0, 0, 0, 0)) { rv = new Version(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue); } int va = Utils.CompareTo(a.Version, rv); int vb = Utils.CompareTo(b.Version, rv); if (va == 0) { return(0); // vb != 0 so return 0 } if (vb == 0) { return(1); // va != 0 so return 1 } if (va > 0 && vb < 0) { return(0); } if (va < 0 && vb > 0) { return(1); } // Now either both a and b's version > req version or both are < req version if (va > 0) { // a.Version and b.Version > req.Version. Pick the one that is closest. return(Utils.CompareTo(a.Version, b.Version) < 0 ? 0 : 1); } else { // a.Version and b.Version < req.Version. Pick the one that is closest. return(Utils.CompareTo(a.Version, b.Version) > 0 ? 0 : 1); } } if (CompareCulture) { bool la = Utils.LocaleEquals(requested.Culture, a.Culture); bool lb = Utils.LocaleEquals(requested.Culture, b.Culture); if (la && !lb) { return(0); } if (!la && lb) { return(1); } } if (CompareContentType) { bool ca = requested.ContentType == a.ContentType; bool cb = requested.ContentType == b.ContentType; if (ca && !cb) { return(0); } if (!ca && cb) { return(1); } } return(-1); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Simple name</param> /// <param name="version">Version</param> /// <exception cref="ArgumentNullException">If any of the args is invalid</exception> public AssemblyRefUser(UTF8String name, Version version) : this(name, version, new PublicKey()) { }
public override int GetHashCode() { // Don't use IsValueType return(UTF8String.GetHashCode(Namespace) ^ UTF8String.GetHashCode(Name)); }
/// <summary> /// Constructor /// </summary> /// <param name="name">Simple name</param> /// <param name="version">Version</param> /// <param name="publicKey">Public key or public key token</param> /// <exception cref="ArgumentNullException">If any of the args is invalid</exception> public AssemblyRefUser(UTF8String name, Version version, PublicKeyBase publicKey) : this(name, version, publicKey, UTF8String.Empty) { }
/// <summary> /// Constructor /// </summary> /// <param name="module">Owner module</param> /// <param name="name">Name of ref</param> public MemberRefUser(ModuleDef module, UTF8String name) { this.module = module; this.name = name; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name of file</param> /// <param name="flags">Flags</param> /// <param name="hashValue">File hash</param> public FileDefUser(UTF8String name, FileAttributes flags, byte[] hashValue) { this.name = name; this.attributes = (int)flags; this.hashValue = hashValue; }
/// <summary> /// Constructor /// </summary> /// <param name="module">Owner module</param> /// <param name="name">Name of method ref</param> /// <param name="sig">Method sig</param> public MemberRefUser(ModuleDef module, UTF8String name, MethodSig sig) : this(module, name, sig, null) { }
/// <summary> /// Constructor /// </summary> /// <param name="module">Owner module</param> /// <param name="typeDefId">TypeDef ID</param> /// <param name="typeName">Type name</param> /// <param name="typeNamespace">Type namespace</param> /// <param name="flags">Flags</param> /// <param name="implementation">Implementation</param> public ExportedTypeUser(ModuleDef module, uint typeDefId, UTF8String typeNamespace, UTF8String typeName, TypeAttributes flags, IImplementation implementation) { this.module = module; this.typeDefId = typeDefId; this.typeName = typeName; this.typeNamespace = typeNamespace; this.attributes = (int)flags; this.implementation = implementation; this.implementation_isInitialized = true; }
/// <summary> /// Constructor /// </summary> /// <param name="module">Owner module</param> /// <param name="name">Type name</param> public TypeRefUser(ModuleDef module, UTF8String name) : this(module, UTF8String.Empty, name) { }
/// <summary> /// Compares two locales (cultures) /// </summary> /// <param name="a">First</param> /// <param name="b">Second</param> /// <returns><c>true</c> if same, <c>false</c> otherwise</returns> internal static bool LocaleEquals(UTF8String a, string b) { return(LocaleCompareTo(a, b) == 0); }
/// <summary> /// Constructor /// </summary> /// <param name="module">Owner module</param> /// <param name="namespace">Type namespace</param> /// <param name="name">Type name</param> public TypeRefUser(ModuleDef module, UTF8String @namespace, UTF8String name) : this(module, @namespace, name, null) { }
private static string GetCanonicalLocale(UTF8String locale) { return(GetCanonicalLocale(UTF8String.ToSystemStringOrEmpty(locale))); }
/// <inheritdoc/> public AssemblyDef Resolve(IAssembly assembly, ModuleDef sourceModule) { if (assembly == null) { return(null); } if (EnableFrameworkRedirect && !FindExactMatch) { FrameworkRedirect.ApplyFrameworkRedirect(ref assembly, sourceModule); } #if THREAD_SAFE theLock.EnterWriteLock(); try { #endif AssemblyDef resolvedAssembly = Resolve2(assembly, sourceModule); if (resolvedAssembly == null) { string asmName = UTF8String.ToSystemStringOrEmpty(assembly.Name); string asmNameTrimmed = asmName.Trim(); if (asmName != asmNameTrimmed) { assembly = new AssemblyNameInfo { Name = asmNameTrimmed, Version = assembly.Version, PublicKeyOrToken = assembly.PublicKeyOrToken, Culture = assembly.Culture, }; resolvedAssembly = Resolve2(assembly, sourceModule); } } if (resolvedAssembly == null) { // Make sure we don't search for this assembly again. This speeds up callers who // keep asking for this assembly when trying to resolve many different TypeRefs cachedAssemblies[GetAssemblyNameKey(assembly)] = null; return(null); } var key1 = GetAssemblyNameKey(resolvedAssembly); var key2 = GetAssemblyNameKey(assembly); AssemblyDef asm1, asm2; cachedAssemblies.TryGetValue(key1, out asm1); cachedAssemblies.TryGetValue(key2, out asm2); if (asm1 != resolvedAssembly && asm2 != resolvedAssembly) { // This assembly was just resolved if (enableTypeDefCache) { foreach (var module in resolvedAssembly.Modules.GetSafeEnumerable()) { if (module != null) { module.EnableTypeDefFindCache = true; } } } } bool inserted = false; if (!cachedAssemblies.ContainsKey(key1)) { cachedAssemblies.Add(key1, resolvedAssembly); inserted = true; } if (!cachedAssemblies.ContainsKey(key2)) { cachedAssemblies.Add(key2, resolvedAssembly); inserted = true; } if (inserted || asm1 == resolvedAssembly || asm2 == resolvedAssembly) { return(resolvedAssembly); } // Dupe assembly. Don't insert it. var dupeModule = resolvedAssembly.ManifestModule; if (dupeModule != null) { dupeModule.Dispose(); } return(asm1 ?? asm2); #if THREAD_SAFE } finally { theLock.ExitWriteLock(); } #endif }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> public FieldDefUser(UTF8String name) : this(name, null) { }
/// <summary> /// Constructor /// </summary> /// <param name="name">Simple name</param> /// <exception cref="ArgumentNullException">If any of the args is invalid</exception> public AssemblyRefUser(UTF8String name) : this(name, new Version(0, 0, 0, 0)) { }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="signature">Signature</param> /// <param name="attributes">Flags</param> public FieldDefUser(UTF8String name, FieldSig signature, FieldAttributes attributes) { this.name = name; this.signature = signature; this.attributes = (int)attributes; }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name</param> /// <param name="type">Type</param> public EventDefUser(UTF8String name, ITypeDefOrRef type) : this(name, type, 0) { }