GithubHelp home page GithubHelp logo

cohesible / postject Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nodejs/postject

0.0 0.0 0.0 15.06 MB

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

License: Other

JavaScript 41.24% C++ 38.73% C 15.56% Assembly 1.33% CMake 3.13%

postject's Introduction

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.

postject's People

Contributors

dsanders11 avatar raisinten avatar jadensimon avatar robertgzr avatar tony-go avatar cjihrig avatar dfellis avatar jviotti avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.