CreateAndInject Posted August 6, 2019 Posted August 6, 2019 How to get the RVA of a method from MethodBase/MethodInfo?
CreateAndInject Posted August 10, 2019 Author Posted August 10, 2019 Anyone know? I can only get RVA by dnlib. Is there any way to get the RVA of a method from System.Reflection.MethodBase?
Reza-HNA Posted August 10, 2019 Posted August 10, 2019 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?
CreateAndInject Posted August 10, 2019 Author Posted August 10, 2019 Yes, I want to get RVA from memory rather than file.
ewwink Posted August 10, 2019 Posted August 10, 2019 maybe this public static IntPtr GetAddress(MethodBase methodBase) { RuntimeHelpers.PrepareMethod(methodBase.MethodHandle); return methodBase.MethodHandle.GetFunctionPointer(); }
wwh1004 Posted August 11, 2019 Posted August 11, 2019 https://github.com/wwh1004/MetadataLocator You can use IMetaDataTables interface
CreateAndInject Posted August 11, 2019 Author Posted August 11, 2019 @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.
atom0s Posted August 12, 2019 Posted August 12, 2019 Check out NTCores information regarding the .NET header information: https://www.ntcore.com/files/dotnetformat.htm#MetaTables
wwh1004 Posted August 12, 2019 Posted August 12, 2019 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 1
CreateAndInject Posted August 12, 2019 Author Posted August 12, 2019 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; } 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now