Ejemplo n.º 1
0
        /// <summary>
        /// Gets the field index of a field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns>The field index.</returns>
        public uint GetFieldIndex(FieldReference field)
        {
            List <IStructEntry> fields = GetStructLayout(field.DeclaringType.Resolve());

            uint i = 0;

            foreach (IStructEntry child in fields)
            {
                if (child.EntryType != StructEntryType.Field)
                {
                    i++;
                    continue;
                }

                StructFieldEntry fieldEntry = (StructFieldEntry)child;
                if (fieldEntry.Field.IsStatic)
                {
                    continue;
                }

                // Found.
                if (fieldEntry.Field == field)
                {
                    return(i);
                }

                i++;
            }

            throw new Exception("Could not find field index for: " + field);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the index in a type struct of a class vtable.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The index.</returns>
        public uint GetClassVTableIndex(TypeDefinition type)
        {
            List <IStructEntry> fields = GetStructLayout(type);

            uint i = 0;

            foreach (IStructEntry child in fields)
            {
                // Class VTable entry? It might be the one we're looking for!
                if (child.EntryType == StructEntryType.ClassVTable)
                {
                    VTableEntry barrier = (VTableEntry)child;
                    if (barrier.Type == type)
                    {
                        return(i);
                    }

                    i++;
                }
                // Indirection pointer to VTables for interfaces.
                else if (child.EntryType == StructEntryType.InterfaceVTablesTable)
                {
                    i++;
                }
                // Field.
                else if (child.EntryType == StructEntryType.Field)
                {
                    StructFieldEntry fieldEntry = (StructFieldEntry)child;
                    if (!fieldEntry.Field.IsStatic)
                    {
                        i++;
                    }
                }
            }

            throw new Exception("Could not find VTable index for: " + type);
        }