Jump to content
Tuts 4 You

How to get RVA from MethodBase?


CreateAndInject

Recommended Posts

CreateAndInject

Anyone know? I can only get RVA by dnlib. Is there any way to get the RVA of a method from System.Reflection.MethodBase?

Link to comment

maybe this

public static IntPtr GetAddress(MethodBase methodBase)
{
    RuntimeHelpers.PrepareMethod(methodBase.MethodHandle);
    return methodBase.MethodHandle.GetFunctionPointer();
}

 

Link to comment
CreateAndInject

@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.

 

image.png.4263cca2cba4667fe7186653c3e462e6.png

Link to comment
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.

 

image.png.4263cca2cba4667fe7186653c3e462e6.png

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

  • Thanks 1
Link to comment
CreateAndInject

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;
}

 

  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...