Easily inject arbitrary read-only resources into executable formats (Mach-O, PE, ELF) and use it at runtime.
npm install postject

Easily inject arbitrary read-only resources into executable formats
(Mach-O, PE, ELF) and use it at runtime.
``sh`
npm i -g postject
`sh
$ postject -h
Usage: postject [options]
Inject arbitrary read-only resources into an executable for use at runtime
Arguments:
filename The executable to inject into
resource_name The resource name to use (section name on Mach-O and ELF, resource name for PE)
resource The resource to inject
Options:
--macho-segment-name
--output-api-header Output the API header to stdout
--overwrite Overwrite the resource if it already exists
-h, --help display help for command
`
`js
const { inject } = require('postject');
await inject('a.out', 'lol', Buffer.from('Hello, world!'));
`
* CMake
* Ninja
* Emscripten (emsdk)
`sh`
$ npm run build
The final output is placed in dist/, with main.js being the
entrypoint.
`sh`
$ npm test
To ensure maximum capatibility and head off unforeseen issues, the
implementation for each format tries to use that format's standard
practices for embedding binary data. As such, it should be possible
to embed the binary data at build-time as well. The CLI provides the
ability to inject the resources into pre-built executables, with the
goal that the end result should be as close as possible to what is
obtained by embedding them at build-time.
Note: Other runtime injection implementers should search the binary
compiled with postject-api.h for thePOSTJECT_SENTINEL_fce680ab2cc467b6e072b8b5df1996b2:0 fuse and1
flip the last character to to indicate that a resource has beenPOSTJECT_SENTINEL_FUSE
injected. A different fuse can also be used by defining the macro before including postject-api.h and--sentinel-fuse
passing the same string to postject with.
For PE executables, the resources are added into the .rsrc section,RT_RCDATA
with the (raw data) type.
The build-time equivalent is adding the binary data as a resource in
the usual manner, such as the Resource Compiler, and marking it as
RT_RCDATA.
The run-time lookup uses the FindResource and LoadResource APIs.
For Mach-O executables, the resources are added as sections inside a
new segment.
The build-time equivalent of embedding binary data with this approach
uses a linker flag: -sectcreate,__FOO,__foo,content.txt
The run-time lookup uses APIs from
For ELF executables, the resources are added as notes.
The build-time equivalent is to use a linker script.