Storing Payload in .rsrc Section
.rsrc
The .rsrc section is a special section in a Windows executable file that contains the resources used by the program. These resources can include icons, bitmaps, menus, dialog boxes, strings, and other data that is needed by the program at runtime.
When an executable is compiled, the resources are typically stored in a separate file called a resource file (.rc), which is then compiled into a binary format and added to the .rsrc section of the executable. This makes it possible for the program to access the resources at runtime, without having to read them from a separate file on disk.
When a program needs to access a resource, it typically uses the Win32 API functions FindResource, LoadResource, and LockResource to access the payload data from within the executable. The FindResource
function searches for the resource in the .rsrc section, the LoadResource
function loads the resource into memory, and the LockResource
function returns a pointer to the resource data that you can then use to access the payload.
Code :
Code Explanation :
HGLOBAL resHandle, HRSRC res : resHandle and res are used to store the handle to a resource and
HGLOBAL
andHRSRC
are data types defined in the Windows API for handling resource For example,HGLOBAL
can hold the handle to a loaded resource, andHRSRC
can hold the handle to a resource being searched forres = FindResource(NULL, MAKEINTRESOURCE(FAVICON_ICO), RT_RCDATA) : Uses the
FindResource
function to locate a resource within the executable. The NULL parameter indicates that the function should search for the resource in the current module.MAKEINTRESOURCE(FAVICON_ICO)
is used to create a resource identifier based on theFAVICON_ICO
value.RT_RCDATA
stands for "read-only data resource" is the resource type, indicating that the resource is a user-defined data resource.
resHandle = LoadResource(NULL, res) : Uses the
LoadResource
function to load the specified resource. It takes theNULL
parameter to indicate the current module and theres
handle obtained from the previous step. The result is stored inresHandle
, which represents the loaded resource.payload = (char*)LockResource(resHandle) : Uses the
LockResource
function to obtain the address of the resource data. TheLockResource
function takes theresHandle
obtained fromLoadResource
and returns a pointer to the resource data. It's cast to(char*)
to match the type ofpayload
.payload_len = SizeofResource(NULL, res) : Uses the
SizeofResource
function to determine the size (length) of the resource. It takes the NULL parameter to indicate the current module and theres
handle obtained fromFindResource
. The resulting size is stored inpayload_len
.
the rest of the code is the same as the .text section code so you can check here for more explanation of the code
Last updated
Was this helpful?