Jump to content
  • Advertisement
Sign in to follow this  
deadimp

Manually Accessing Resources in C++

This topic is 4850 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 do you manually access resources in C++? How would I retrieve the raw data from the file in the program's resources?

Share this post


Link to post
Share on other sites
Advertisement
You want to parse the binary image of the exe/dll that the resource is contained in directly? Fun stuff it is!


// compute start of PE image
DWORD offset = *(DWORD *)( base + 0x3c );
DWORD peHeader = *(DWORD *)( base + offset );
_ASSERTE( peHeader == IMAGE_NT_SIGNATURE );

// compute start of COFF header
IMAGE_FILE_HEADER *ifh = (IMAGE_FILE_HEADER *)( base + offset + 4 );

// verify machine type
_ASSERTE( ifh->Machine == IMAGE_FILE_MACHINE_I386 );

// compute start of OPTIONAL header
IMAGE_OPTIONAL_HEADER *ioh = (IMAGE_OPTIONAL_HEADER *)( (BYTE *)ifh + sizeof( IMAGE_FILE_HEADER ) );

// verify optional header magic number
_ASSERTE( ioh->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC );

// grab the pointer to the resource directory
IMAGE_DATA_DIRECTORY *directory = &ioh->DataDirectory[ IMAGE_DIRECTORY_ENTRY_RESOURCE ];


the IMAGE_DATA_DIRECTORY should point to a IMAGE_RESOURCE_DIRECTORY struct... something like


IMAGE_RESOURCE_DIRECTORY *iid = (IMAGE_RESOURCE_DIRECTORY *)( base + importDirectory->VirtualAddress );


see WinNT.h for more info on these. Also look at IMAGE_RESOURCE_DIRECTORY_ENTRY also in WinNT.h.

Share this post


Link to post
Share on other sites
Quote:
Original post by krum
You want to parse the binary image of the exe/dll that the resource is contained in directly? Fun stuff it is!

But.. why? :)

Share this post


Link to post
Share on other sites
Quote:
Original post by doynax
Quote:
Original post by krum
You want to parse the binary image of the exe/dll that the resource is contained in directly? Fun stuff it is!

But.. why? :)


HAH People do crazy stuff. Maybe he's trying to read a resource from a win32 exe on a Commodore 64. I don't know if there's a C++ compiler for a C64, but you get my point.

Share this post


Link to post
Share on other sites
Actually, thta was a little too advanced for me. I think the functions doynax supplied will help me, using FindResource(), LoadResrouce(), and LockResource() with the type RT_RCDATA.
Thanks for the help.

Share this post


Link to post
Share on other sites
Quote:
Original post by krum
I don't know if there's a C++ compiler for a C64, but you get my point.
There's pretty decent C compiler at least, and you could always use some external C++ frontend to generate code for it (Comeau for example).

On a small side note. 'base' would be the program/DLL's module handle, right?

Share this post


Link to post
Share on other sites
Quote:

On a small side note. 'base' would be the program/DLL's module handle, right?


Indeed. I think you get the same thing if you just used an open() call of some sort on the file.


void domagicstuff( HMODULE module )
{
// compute base image address for module
BYTE *base = (BYTE *)module;

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!