Manually Accessing Resources in C++
How do you manually access resources in C++? How would I retrieve the raw data from the file in the program's resources?
Check out the following sequence of Win32 functions: FindResource, LoadResource, LockResource, SizeofResource and FreeResource.
You want to parse the binary image of the exe/dll that the resource is contained in directly? Fun stuff it is!
the IMAGE_DATA_DIRECTORY should point to a IMAGE_RESOURCE_DIRECTORY struct... something like
see WinNT.h for more info on these. Also look at IMAGE_RESOURCE_DIRECTORY_ENTRY also in WinNT.h.
// compute start of PE imageDWORD offset = *(DWORD *)( base + 0x3c );DWORD peHeader = *(DWORD *)( base + offset );_ASSERTE( peHeader == IMAGE_NT_SIGNATURE );// compute start of COFF headerIMAGE_FILE_HEADER *ifh = (IMAGE_FILE_HEADER *)( base + offset + 4 );// verify machine type_ASSERTE( ifh->Machine == IMAGE_FILE_MACHINE_I386 );// compute start of OPTIONAL headerIMAGE_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 directoryIMAGE_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.
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? :)
Quote:Original post by doynaxQuote: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.
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.
Thanks for the help.
Quote:Original post by krumThere's pretty decent C compiler at least, and you could always use some external C++ frontend to generate code for it (Comeau for example).
I don't know if there's a C++ compiler for a C64, but you get my point.
On a small side note. 'base' would be the program/DLL's module handle, right?
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;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement