/// <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> private static unsafe IntPtr RvaToNonGenericStaticFieldAddress(IntPtr moduleHandle, int staticFieldRVA) { IntPtr staticFieldAddress; if ((staticFieldRVA & FieldAccessFlags.RemoteStaticFieldRVA) != 0) { RemoteStaticFieldDescriptor *descriptor = (RemoteStaticFieldDescriptor *)(moduleHandle + (staticFieldRVA & ~FieldAccessFlags.RemoteStaticFieldRVA)); staticFieldAddress = *descriptor->IndirectionCell + descriptor->Offset; } else { staticFieldAddress = (IntPtr)(moduleHandle + staticFieldRVA); } return(staticFieldAddress); }
/// <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); }