Jump to content
  • Advertisement

Algorithm Reading RVA memory address of a given exported function demangled name

Recommended Posts

Suppose i don't have any linker at hand but i am calling an exported function from a C++ DLL Windows, i.e. sqrt from mvcrt14.dll, how would i get just and only just the Relative Virtual Address of sqrt from that dll to simulate what linker does and convert this call to a call to such RVA on the hexcoded generated .exe file? 

Either, how would i read the RVA of Mac, Android, iOS and Linux library formats?

Share this post

Link to post
Share on other sites

The calling code has a fixed call to a placeholder to its PE's import address table.  DLLs contain an export address table.  The loader rewrites the placeholder in the caller's IAT with the real address after loading the DLL and figuring out what the absolute address of the actual function is.  The lookup can be done either using function name OR ordinal (i.e. index).

See the Import Address Table and Export Address Table sections of https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format

If you want to do it the easy way at runtime, use LoadLibrary and GetProcAddress instead to avoid headaches.

Other platforms use different formats (Mach-O, ELF, etc) and I'm not as familiar with low level details of those.

Edited by Nypyren

Share this post

Link to post
Share on other sites

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!