Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to get RVA from MethodBase?

Featured Replies

Posted

How to get the RVA of a method from MethodBase/MethodInfo?

  • 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?

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?

  • Author

Yes, I want to get RVA from memory rather than file.

maybe this

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

 

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

 

image.png.4263cca2cba4667fe7186653c3e462e6.png

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

  • 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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.