protected string FormatRuntimeMember(RuntimeMember member) { if (!showTokenValues.Checked) return member.Name; return "[" + TokenToString(member.Token) + "] " + member.Name; }
/// <summary> /// Initializes a new instance of the <see cref="MemberOperand"/> class. /// </summary> /// <param name="member">The member to reference.</param> /// <param name="type">The type of data held in the operand.</param> /// <param name="offset">The offset from the base register or absolute address to retrieve.</param> public MemberOperand(RuntimeMember member, SigType type, IntPtr offset) : base(type, null, offset) { if (member == null) throw new ArgumentNullException(@"member"); this.member = member; }
/// <summary> /// Initializes a new instance of the <see cref="MemberOperand"/> class. /// </summary> /// <param name="method">The method to reference.</param> /// <exception cref="System.ArgumentNullException"><paramref name="method"/> is null.</exception> public MemberOperand(RuntimeMethod method) : base(new SigType(CilElementType.I), null, IntPtr.Zero) { if (method == null) throw new ArgumentNullException(@"method"); this.member = method; }
/// <summary> /// Initializes a new instance of <see cref="MemberOperand"/>. /// </summary> /// <param name="field">The runtime field to reference.</param> /// <exception cref="System.ArgumentNullException"><paramref name="field"/> is null.</exception> public MemberOperand(RuntimeField field) : base(field.SignatureType, null, IntPtr.Zero) { if (field == null) throw new ArgumentNullException(@"field"); this.member = field; }
/// <summary> /// Checks that <paramref name="member"/> is a member, which can be linked. /// </summary> /// <param name="member">The member to check.</param> /// <returns> /// True, if the member is valid for linking. /// </returns> protected bool IsValid(RuntimeMember member) { return (member is RuntimeMethod || (member is RuntimeField && FieldAttributes.Static == (FieldAttributes.Static & ((RuntimeField)member).Attributes))); }
/// <summary> /// Allocates the specified member. /// </summary> /// <param name="member">The member.</param> /// <param name="section">The section.</param> /// <param name="size">The size.</param> /// <param name="alignment">The alignment.</param> /// <returns></returns> public virtual Stream Allocate(RuntimeMember member, SectionKind section, int size, int alignment) { return null; }
/// <summary> /// Issues a linker request for the given runtime method. /// </summary> /// <param name="method">The method the patched code belongs to.</param> /// <param name="methodOffset">The offset inside the method where the patch is placed.</param> /// <param name="linkType">The type of link required.</param> /// <param name="methodRelativeBase">The base address, if a relative link is required.</param> /// <param name="target">The method or static field to link against.</param> /// <returns> /// The return value is the preliminary address to place in the generated machine /// code. On 32-bit systems, only the lower 32 bits are valid. The above are not used. An implementation of /// IAssemblyLinker may not rely on 64-bits being stored in the memory defined by position. /// </returns> public virtual long Link(LinkType linkType, RuntimeMethod method, int methodOffset, int methodRelativeBase, RuntimeMember target) { return 0; }
/// <summary> /// Loads the interfaces. /// </summary> protected void LoadMemberReferences() { Token maxToken = GetMaxTokenValue(TableType.MemberRef); foreach (Token token in new Token(TableType.MemberRef, 1).Upto(maxToken)) { MemberRefRow row = metadataProvider.ReadMemberRefRow(token); string name = GetString(row.NameStringIdx); RuntimeType ownerType = null; switch (row.Class.Table) { case TableType.TypeDef: ownerType = types[row.Class.RID - 1]; break; case TableType.TypeRef: ownerType = typeRef[row.Class.RID - 1]; break; case TableType.TypeSpec: ownerType = typeSpecs[row.Class.RID - 1]; break; default: throw new NotSupportedException(String.Format(@"LoadMemberReferences() does not support token table {0}", row.Class.Table)); } if (ownerType == null) { throw new InvalidOperationException(String.Format(@"Failed to retrieve owner type for Token {0:x} (Table {1})", row.Class, row.Class.Table)); } Signature signature = GetMemberRefSignature(row.SignatureBlobIdx); CilGenericType genericOwnerType = ownerType as CilGenericType; RuntimeMember runtimeMember = null; if (signature is FieldSignature) { foreach (RuntimeField field in ownerType.Fields) { if (field.Name == name) { runtimeMember = field; break; } } } else { MethodSignature methodSignature = signature as MethodSignature; Debug.Assert(signature is MethodSignature); if ((genericOwnerType != null) && (genericOwnerType.GenericArguments.Length != 0)) { methodSignature = new MethodSignature(methodSignature, genericOwnerType.GenericArguments); } foreach (RuntimeMethod method in ownerType.Methods) { if (method.Name == name) { if (method.Signature.Matches(methodSignature)) { runtimeMember = method; break; } } } // Special case: string.get_Chars is same as string.get_Item if (runtimeMember == null && name == "get_Chars" && ownerType.FullName == "System.String") { name = "get_Item"; foreach (RuntimeMethod method in ownerType.Methods) { if (method.Name == name) { if (method.Signature.Matches(methodSignature)) { runtimeMember = method; break; } } } } } if (runtimeMember == null) { throw new InvalidOperationException(String.Format(@"Failed to locate field {0}.{1}", ownerType.FullName, name)); } memberRef[token.RID - 1] = runtimeMember; } }