npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postject

v1.0.0-alpha.6

Published

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

Downloads

241,785

Readme

postject

CircleCI npm version

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

Install

npm i -g postject

Usage

Command line utility

$ postject -h
Usage: postject [options] <filename> <resource_name> <resource>

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 <segment_name>  Name for the Mach-O segment (default: "__POSTJECT")
  --output-api-header                  Output the API header to stdout
  --overwrite                          Overwrite the resource if it already exists
  -h, --help                           display help for command

Using Programatically

const { inject } = require('postject');

await inject('a.out', 'lol', Buffer.from('Hello, world!'));

Building

Prerequisites

Build Command

$ npm run build

The final output is placed in dist/, with main.js being the entrypoint.

Testing

$ npm test

Design

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 the POSTJECT_SENTINEL_fce680ab2cc467b6e072b8b5df1996b2:0 fuse and flip the last character to 1 to indicate that a resource has been injected. A different fuse can also be used by defining the POSTJECT_SENTINEL_FUSE macro before including postject-api.h and passing the same string to postject with --sentinel-fuse <sentinel_fuse>.

Windows

For PE executables, the resources are added into the .rsrc section, with the RT_RCDATA (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.

macOS

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 <mach-o/getsect.h>.

Linux

For ELF executables, the resources are added as notes.

The build-time equivalent is to use a linker script.