public MemberRefOptions(MemberRef mr) { this.Class = mr.Class; this.Name = mr.Name; this.Signature = mr.Signature; this.CustomAttributes.AddRange(mr.CustomAttributes); }
public MemberRef CopyTo(MemberRef mr) { mr.Class = Class; mr.Name = Name ?? UTF8String.Empty; mr.Signature = Signature; mr.CustomAttributes.Clear(); mr.CustomAttributes.AddRange(CustomAttributes); return mr; }
MemberRef CreateInitializeArrayMethod() { if (initializeArrayMethod == null) { var runtimeHelpersType = DotNetUtils.FindOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System.Runtime.CompilerServices", "RuntimeHelpers", false); var systemArrayType = DotNetUtils.FindOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System", "Array", false); var runtimeFieldHandleType = DotNetUtils.FindOrCreateTypeRef(module, module.CorLibTypes.AssemblyRef, "System", "RuntimeFieldHandle", true); var methodSig = MethodSig.CreateStatic(module.CorLibTypes.Void, systemArrayType, runtimeFieldHandleType); initializeArrayMethod = module.UpdateRowId(new MemberRefUser(module, "InitializeArray", methodSig, runtimeHelpersType.TypeDefOrRef)); } return initializeArrayMethod; }
/// <inheritdoc/> public IMemberForwarded Resolve(MemberRef memberRef) { if (memberRef == null) return null; var parent = memberRef.Class; var method = parent as MethodDef; if (method != null) return method; var declaringType = GetDeclaringType(memberRef, parent); return declaringType == null ? null : declaringType.Resolve(memberRef); }
internal static bool ContainsGenericParameter(MemberRef mr) { if (mr == null) return false; if (ContainsGenericParameter(mr.Signature)) return true; var cl = mr.Class; var tdr = cl as ITypeDefOrRef; if (tdr != null) return tdr.ContainsGenericParameter; var md = cl as MethodDef; if (md != null) return TypeHelper.ContainsGenericParameter(md.Signature); return false; }
public MemberRefInfo(MemberRef mr) { this.MemberRef = mr; this.OrigName = mr.Name; }
void AnalyzeMemberRef(ConfuserContext context, INameService service, MemberRef memberRef) { ITypeDefOrRef declType = memberRef.DeclaringType; var typeSpec = declType as TypeSpec; if (typeSpec == null) return; TypeSig sig = typeSpec.TypeSig; while (sig.Next != null) sig = sig.Next; Debug.Assert(sig is TypeDefOrRefSig || sig is GenericInstSig || sig is GenericSig); if (sig is GenericInstSig) { var inst = (GenericInstSig)sig; Debug.Assert(!(inst.GenericType.TypeDefOrRef is TypeSpec)); TypeDef openType = inst.GenericType.TypeDefOrRef.ResolveTypeDefThrow(); if (!context.Modules.Contains((ModuleDefMD)openType.Module) || memberRef.IsArrayAccessors()) return; IDnlibDef member; if (memberRef.IsFieldRef) member = memberRef.ResolveFieldThrow(); else if (memberRef.IsMethodRef) member = memberRef.ResolveMethodThrow(); else throw new UnreachableException(); service.AddReference(member, new MemberRefReference(memberRef, member)); } }
public MMethodDef findMethod(MemberRef mr) { return methods.find(mr); }
bool? CanAccess(MethodDef md, MemberRef mr) { if (mr == null || md == null) return null; return CanAccess(md); }
bool? CanAccess(TypeDef td, MemberRef mr) { return CanAccess(td, null, mr); }
void Hash(MemberRef mr) { if (mr == null) return; Hash(mr.Class); if (IsFromNonObfuscatedAssembly(mr.Class)) Hash(mr.Name); Hash(mr.Signature); }
/// <inheritdoc/> public IMemberForwarded Resolve(MemberRef memberRef) { if (memberRef == null) return null; if (ProjectWinMDRefs) memberRef = WinMDHelpers.ToCLR(memberRef.Module, memberRef) ?? memberRef; var parent = memberRef.Class; var method = parent as MethodDef; if (method != null) return method; var declaringType = GetDeclaringType(memberRef, parent); return declaringType == null ? null : declaringType.Resolve(memberRef); }
public MemberRefInfo(MemberRef mr) { MemberRef = mr; OrigName = mr.Name; }
void Add(MemberRef mr) { if (mr == null || memberRefs.ContainsKey(mr)) return; if (mr.Module != validModule) return; memberRefs[mr] = true; Push(mr.Class); Add(mr.Signature); Add(mr.CustomAttributes); }
TypeDef GetDeclaringType(MemberRef memberRef, IMemberRefParent parent) { if (memberRef == null || parent == null) return null; var declaringTypeDef = parent as TypeDef; if (declaringTypeDef != null) return declaringTypeDef; var declaringTypeRef = parent as TypeRef; if (declaringTypeRef != null) return Resolve(declaringTypeRef); // A module ref is used to reference the global type of a module in the same // assembly as the current module. var moduleRef = parent as ModuleRef; if (moduleRef != null) { var module = memberRef.Module; if (module == null) return null; TypeDef globalType = null; if (new SigComparer(0).Equals(module, moduleRef)) globalType = module.GlobalType; var modAsm = module.Assembly; if (globalType == null && modAsm != null) { var moduleDef = modAsm.FindModule(moduleRef.Name); if (moduleDef != null) globalType = moduleDef.GlobalType; } return globalType; } var method = parent as MethodDef; if (method != null) return method.DeclaringType; var ts = parent as TypeSpec; if (ts != null) { var git = ts.TypeSig as GenericInstSig; if (git != null) { var td = git.GenericType.TypeDef; if (td != null) return td; var tr = git.GenericType.TypeRef; if (tr != null) return Resolve(tr); } return null; } return null; }
/// <summary> /// Checks whether it can access a <see cref="MemberRef"/> /// </summary> /// <param name="mr">The member reference</param> /// <returns><c>true</c> if it has access to it, <c>false</c> if not, and <c>null</c> /// if we can't determine it (eg. we couldn't resolve a type or input was <c>null</c>)</returns> public bool? CanAccess(MemberRef mr) { if (mr == null) return null; var parent = mr.Class; var td = parent as TypeDef; if (td != null) return CanAccess(td, mr); var tr = parent as TypeRef; if (tr != null) return CanAccess(tr.Resolve(), mr); var ts = parent as TypeSpec; if (ts != null) return CanAccess(ts.ResolveTypeDef(), ts.TryGetGenericInstSig(), mr); var md = parent as MethodDef; if (md != null) return CanAccess(md, mr); var mod = parent as ModuleRef; if (mod != null) return CanAccess(mod, mr); return null; }
public MMethodDef FindAnyMethod(MemberRef mr) { return methods.FindAny(mr); }
bool? CanAccess(TypeDef td, GenericInstSig git, MemberRef mr) { if (mr == null || td == null) return null; if (mr.MethodSig != null) { var md = td.FindMethodCheckBaseType(mr.Name, mr.MethodSig); if (md == null) { // Assume that it's an array type if it's one of these methods if (mr.Name == "Get" || mr.Name == "Set" || mr.Name == "Address" || mr.Name == ".ctor") return true; return null; } return CanAccess(md, git); } if (mr.FieldSig != null) return CanAccess(td.FindFieldCheckBaseType(mr.Name, mr.FieldSig), git); return null; }
public MFieldDef FindAnyField(MemberRef fr) { return fields.FindAny(fr); }
bool? CanAccess(ModuleRef mod, MemberRef mr) { if (mr == null || mod == null || mod.Module == null) return null; var userModule = userType.Module; if (userModule == null) return null; if (!IsSameAssembly(userModule.Assembly, mod.Module.Assembly)) return false; if (userModule.Assembly == null) return false; var otherMod = userModule.Assembly.FindModule(mod.Name); if (otherMod == null) return false; return CanAccess(otherMod.GlobalType, mr); }
public MFieldDef findField(MemberRef fr) { return fields.find(fr); }