> For the complete documentation index, see [llms.txt](https://everythingblackkk.gitbook.io/everythingblackkk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://everythingblackkk.gitbook.io/everythingblackkk/malware-development/publish-your-docs-1.md).

# Load Resource Data From .Rsrc

## 1 - Load Resource Data From .Rsrc

<figure><img src="/files/dgiXTQPlCxn6xsIaVrq8" alt=""><figcaption></figcaption></figure>

```csharp
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
#include "resource.h"
#include <string.h>

PBYTE GetResourceData(SIZE_T* resourceSize) {
    HRSRC hRsrc = NULL;         
    HGLOBAL hGlobal = NULL;     
    PVOID pPayloadAddr = NULL;  

    printf("[*] Searching for resource...\n");
    hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_RCDATA1), RT_RCDATA);
    if (hRsrc == NULL) {
        printf("[-] Failed to find resource. Error: %lu\n", GetLastError());
        return NULL;
    }
    printf("[+] Resource found successfully.\n");

    printf("[*] Loading resource...\n");
    hGlobal = LoadResource(NULL, hRsrc);
    if (hGlobal == NULL) {
        printf("[-] Failed to load resource. Error: %lu\n", GetLastError());
        return NULL;
    }
    printf("[+] Resource loaded successfully.\n");

    printf("[*] Locking resource...\n");
    pPayloadAddr = LockResource(hGlobal);
    if (pPayloadAddr == NULL) {
        printf("[-] Failed to lock resource. Error: %lu\n", GetLastError());
        return NULL;
    }
    printf("[+] Resource locked successfully. Payload address: %p\n", pPayloadAddr);

    printf("[*] Getting resource size...\n");
    *resourceSize = SizeofResource(NULL, hRsrc);
    if (*resourceSize == 0) {
        printf("[-] Failed to get resource size. Error: %lu\n", GetLastError());
        return NULL;
    }
    printf("[+] Resource size: %zu bytes.\n", *resourceSize);

    printf("[*] Allocating memory for writable payload...\n");
    PBYTE pWritablePayload = (PBYTE)malloc(*resourceSize);
    if (pWritablePayload == NULL) {
        printf("[-] Failed to allocate memory for writable payload.\n");
        return NULL;
    }
    printf("[+] Memory allocated successfully at address: %p\n", pWritablePayload);

    printf("[*] Copying resource data to allocated memory...\n");
    memcpy(pWritablePayload, pPayloadAddr, *resourceSize);
    printf("[+] Resource data copied successfully.\n");

    return pWritablePayload;
}

int main() {
    SIZE_T sPayloadSize = 0;

    printf("[#] Calling GetResourceData...\n");
    PBYTE pWritablePayload = GetResourceData(&sPayloadSize);

    if (pWritablePayload == NULL) {
        printf("[-] Failed to get resource data.\n");
        return 1;
    }

    printf("[+] Successfully retrieved resource data.\n");
    printf("[+] Payload Size: %zu bytes\n", sPayloadSize);

    free(pWritablePayload);
    printf("[#] Memory freed successfully.\n");

    return 0;
}



```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://everythingblackkk.gitbook.io/everythingblackkk/malware-development/publish-your-docs-1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
