August 10, 20196 yr Author Anyone know? I can only get RVA by dnlib. Is there any way to get the RVA of a method from System.Reflection.MethodBase?
August 10, 20196 yr you can read MetaData table and get method File Offset then convert that to RVA (which dnlib does that). but i think you looking for a direct way to get RVA from methodbase, right?
August 10, 20196 yr maybe this public static IntPtr GetAddress(MethodBase methodBase) { RuntimeHelpers.PrepareMethod(methodBase.MethodHandle); return methodBase.MethodHandle.GetFunctionPointer(); }
August 11, 20196 yr Author @ewwink RVA isn't function pointer, please see the picture below. @wwh1004 It seems MetadataLocator can't get RVA, I can't search any results by "RVA". MethodsMap contains some infomation of MethodBase, but still doesn't contain RVA.
August 12, 20196 yr Check out NTCores information regarding the .NET header information: https://www.ntcore.com/files/dotnetformat.htm#MetaTables
August 12, 20196 yr 9 hours ago, CreateAndInject said: @ewwink RVA isn't function pointer, please see the picture below. @wwh1004 It seems MetadataLocator can't get RVA, I can't search any results by "RVA". MethodsMap contains some infomation of MethodBase, but still doesn't contain RVA. You can use MetadataLocator to get an instance of IMetaDataTables then use https://docs.microsoft.com/en-us/dotnet/framework/unmanaged-api/metadata/imetadatatables-getrow-method
August 12, 20196 yr Author It works with the following code, thanks! static int GetRVA(MethodBase mb) { var mdInfo = MetadataInfo.GetMetadataInfo(mb.Module); int table = mb.MetadataToken >> 24; int rid = mb.MetadataToken & 0xffffff; mdInfo.MetaDataTables.GetRow((uint)table, (uint)rid, out var ppRow); return *(int*)ppRow; }
Create an account or sign in to comment