Jump to content
  • Advertisement
Sign in to follow this  
thenoobie

LoadLibrary from byte array?

This topic is 2533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I go about using an array of bytes containing binary data to find the address of a function located in that data. For example, I compile a DLL with the function "Squared( int a, int b )" but all I have is the array of bytes that make up the DLL. How would I go about finding the address of "Squared"?

Share this post


Link to post
Share on other sites
Advertisement
This is a non-trivial exercise. You could try the instructions here, but honestly it's just easier to have it as a separate file.

Share this post


Link to post
Share on other sites
Why not just store the byte array to a temporary dll file and load that file?
Some single exe tools (such as RegMon from sysinternal, if I remember correct) does same to load drivers.

Share this post


Link to post
Share on other sites
I worded my question pretty badly, I want to get the address of a function stored in a DLL through a byte array. This is absolutely 100% for learning purposes which is why I don't want to use a blatantly simpler method. There are 100 ways I know how to do this differently but I want to learn how to do it this specific way.


DWORD GetAddressFromBinary( unsigned char *pData )
{
// Sort through data here
HMODULE MemDll = reinterpret_cast<HMODULE>pData;
DWORD Address = GetProcAddress( MemDll, "TestFunction" );

return Address;
}

int main( unsigned char *pData )
{
// Read file for array of bytes
unsigned char *pData = ReadFile(/*Parameters here*/);
GetAddressFromBinary( pData );
}

Share this post


Link to post
Share on other sites
Thanks, keep the information coming guys. wink.gif

I am incredibly interested in learning Windows programming bottom to top and this is one of the things at the moment that I'm most interested in learning.

Share this post


Link to post
Share on other sites

HMODULE MemDll = reinterpret_cast<HMODULE>pData;
[/quote]
No. Just... no.

A HMODULE is a handle. A handle is an opaque type given to you by an API. You're not supposed to assume anything about it. You are assuming that it is a pointer to the first byte in memory of a loaded DLL.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!