Ejemplo n.º 1
0
        unsafe public IntPtr GetIntPtrFromIndex(uint index)
        {
#if PROJECTN
            uint rva = GetRvaFromIndex(index);
            if ((rva & IndirectionConstants.RVAPointsToIndirection) != 0)
            {
                // indirect through IAT
                return(*(IntPtr *)(_moduleHandle.ConvertRVAToPointer(rva & ~IndirectionConstants.RVAPointsToIndirection)));
            }
            else
            {
                return((IntPtr)(_moduleHandle.ConvertRVAToPointer(rva)));
            }
#else
            return(GetAddressFromIndex(index));
#endif
        }
Ejemplo n.º 2
0
        unsafe public IntPtr GetIntPtrFromIndex(uint index)
        {
#if CORERT
            if (index >= _elementsCount)
            {
                throw new BadImageFormatException();
            }

            // TODO: indirection through IAT

            return(((TableElement *)_elements)[index]);
#else
            uint rva = GetRvaFromIndex(index);
            if ((rva & 0x80000000) != 0)
            {
                // indirect through IAT
                return(*(IntPtr *)(_moduleHandle.ConvertRVAToPointer(rva & ~0x80000000)));
            }
            else
            {
                return((IntPtr)(_moduleHandle.ConvertRVAToPointer(rva)));
            }
#endif
        }
Ejemplo n.º 3
0
        unsafe public IntPtr GetIntPtrFromIndex(uint index)
        {
#if CORERT
            if (index >= _elementsCount)
            {
                throw new BadImageFormatException();
            }

            // TODO: indirection through IAT
            int *pRelPtr32 = &((int *)_elements)[index];
            return((IntPtr)((byte *)pRelPtr32 + *pRelPtr32));
#else
            uint rva = GetRvaFromIndex(index);
            if ((rva & IndirectionConstants.RVAPointsToIndirection) != 0)
            {
                // indirect through IAT
                return(*(IntPtr *)(_moduleHandle.ConvertRVAToPointer(rva & ~IndirectionConstants.RVAPointsToIndirection)));
            }
            else
            {
                return((IntPtr)(_moduleHandle.ConvertRVAToPointer(rva)));
            }
#endif
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Resolve a given 32-bit integer (staticFieldRVA) representing a static field address.
        /// For "local" static fields residing in the module given by moduleHandle, staticFieldRVA
        /// directly contains the RVA of the static field. For remote static fields residing in other
        /// modules, staticFieldRVA has the highest bit set (FieldAccessFlags.RemoteStaticFieldRVA)
        /// and it contains the RVA of a RemoteStaticFieldDescriptor structure residing in the module
        /// given by moduleHandle that holds a pointer to the indirection cell
        /// of the remote static field and its offset within the cell.
        /// </summary>
        /// <param name="moduleHandle">Reference module handle used for static field lookup</param>
        /// <param name="staticFieldRVA">
        /// RVA of static field for local fields; for remote fields, RVA of a RemoteStaticFieldDescriptor
        /// structure for the field or-ed with the FieldAccessFlags.RemoteStaticFieldRVA bit
        /// </param>
        public static unsafe IntPtr RvaToNonGenericStaticFieldAddress(TypeManagerHandle moduleHandle, int staticFieldRVA)
        {
            IntPtr staticFieldAddress;

            if ((staticFieldRVA & FieldAccessFlags.RemoteStaticFieldRVA) != 0)
            {
                RemoteStaticFieldDescriptor *descriptor = (RemoteStaticFieldDescriptor *)(moduleHandle.ConvertRVAToPointer
                                                                                              (staticFieldRVA & ~FieldAccessFlags.RemoteStaticFieldRVA));
                staticFieldAddress = *descriptor->IndirectionCell + descriptor->Offset;
            }
            else
            {
                staticFieldAddress = (IntPtr)(moduleHandle.ConvertRVAToPointer(staticFieldRVA));
            }

            return(staticFieldAddress);
        }