How to Embed Binary Data into a Win32 Executable File in 4 Methods
This Gist covers 4 methods to embed arbitrary binary files (images, data, etc.) inside an executable. From standard approaches (byte arrays) to low-level hacks like binary appending (copy /b), each method includes ready-to-use examples in Visual C++. Use cases: Single-file deployment (no external resources). Hiding data inside .exe/.elf (no encryption). Quick prototyping or educational purposes. ⚠️ Note: Methods 1-3 are "clean" and portable. Method 4 (copy /b) is a hack and may cause problems with checksums or antivirus. All examples assume x86_64 context (adaptable for other architectures). Method 1: Using Win32 Resource Files (.rc) Best for: Native Windows executables where you want integrated resource handling Step 1: Add resource files in Visual Studio Right-click project → Add → Resource... Choose "Import..." and select your binary file (e.g., data.bin) Set resource type as RCDATA and assign an ID (e.g., IDR_MY_DATA) Visual Studio will automatically: Generate/modify resource.h with your ID Create/update the .rc file with: IDR_MY_DATA RCDATA "file.bin" Step 2: Access the resource from code This will be the code to access the resources: main.cpp #include #include "resource.h" // Auto-generated by VS void LoadEmbeddedData() { HRSRC hRes = FindResource(nullptr, MAKEINTRESOURCE(IDR_MY_DATA), RT_RCDATA); DWORD dataSize = SizeofResource(nullptr, hRes); HGLOBAL hData = LoadResource(nullptr, hRes); const BYTE* pData = static_cast(LockResource(hData)); // Use pData (read-only) and dataSize... // Note: LockResource doesn't need unlocking } Key Notes:

This Gist covers 4 methods to embed arbitrary binary files (images, data, etc.) inside an executable.
From standard approaches (byte arrays) to low-level hacks like binary appending (copy /b
), each method includes ready-to-use examples in Visual C++.
Use cases:
- Single-file deployment (no external resources).
- Hiding data inside .exe/.elf (no encryption).
- Quick prototyping or educational purposes.
⚠️ Note:
- Methods 1-3 are "clean" and portable.
- Method 4 (
copy /b
) is a hack and may cause problems with checksums or antivirus. - All examples assume x86_64 context (adaptable for other architectures).
Method 1: Using Win32 Resource Files (.rc)
Best for: Native Windows executables where you want integrated resource handling
Step 1: Add resource files in Visual Studio
- Right-click project → Add → Resource...
- Choose "Import..." and select your binary file (e.g.,
data.bin
) - Set resource type as
RCDATA
and assign an ID (e.g.,IDR_MY_DATA
)
Visual Studio will automatically:
- Generate/modify
resource.h
with your ID - Create/update the
.rc
file with:
IDR_MY_DATA RCDATA "file.bin"
Step 2: Access the resource from code
This will be the code to access the resources:
main.cpp
#include
#include "resource.h" // Auto-generated by VS
void LoadEmbeddedData()
{
HRSRC hRes = FindResource(nullptr, MAKEINTRESOURCE(IDR_MY_DATA), RT_RCDATA);
DWORD dataSize = SizeofResource(nullptr, hRes);
HGLOBAL hData = LoadResource(nullptr, hRes);
const BYTE* pData = static_cast<const BYTE*>(LockResource(hData));
// Use pData (read-only) and dataSize...
// Note: LockResource doesn't need unlocking
}