Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are win32 executable resources handled?

Tags:

c

winapi

I don't know why it's so difficult to find the answer to this question on Google, but I want to set something straight.

Are win32 resources handled in the same way static data is where that data is kept in the RAM for the entire runtime of a process, or are they kept on disk like a regular file until loaded into memory? Functions like LoadResource / LoadString imply the latter, but I want to be absolutely sure I'm not being fooled by abstraction.

like image 284
NmdMystery Avatar asked Dec 19 '13 23:12

NmdMystery


People also ask

Is a win32 executable file?

What is win32.exe. The file win32.exe is associated with Windows System 32, where the drivers and . dll files are stored. This file is responsible for running all the executable files found on your computer.

What is a Windows resource file?

In Microsoft Windows, resources are read-only data embedded in portable executable files like .exe, DLL, CPL, SCR, SYS or (beginning with Windows Vista) MUI files. The Windows API provides for easy access to all applications resources.

What is RC data type?

Defines a raw data resource for an application. Raw data resources permit the inclusion of binary data directly in the executable file. syntax Copy. nameID RCDATA [optional-statements] {raw-data ... }

What is Findresourcea?

An application can use FindResource to find any type of resource, but this function should be used only if the application must access the binary resource data by making subsequent calls to LoadResource and then to LockResource.


1 Answers

In olden days (like Windows 3.1 and earlier), resources were copied into memory during load, and you just got a handle to them. The memory manager could do things like move the copy around in memory to defragment space or even secretly unload the resource until you needed it again. When you needed the resource, there was a second step to "lock" it into memory. This gave you a pointer to the copy and made sure the resource manager didn't move it around until you unlocked it again.

In 32-bit versions of Windows, resources aren't copied. The executable (or DLL) is mapped into memory, and if you touch the resource, the virtual memory manager will make sure it's there for you.

The APIs (FindResource, LoadResource, LockResource) reflect the old days, with handles to resources, and locking of handles, etc. But the implementations are much simpler now because the handle is just a pointer to the beginning of the resource and locking is effectively a no-op, casting the handle to a pointer type and returning it.

like image 117
Adrian McCarthy Avatar answered Nov 16 '22 03:11

Adrian McCarthy