1.0.1 • Published 4 years ago

@erhhung/node-resource-hacker v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

node-resource-hacker

Simple Node.js wrapper around the Resource Hacker application for Windows. Unlike other wrappers that don't seem to be actively maintained, this one has an async interface, and, most importantly, conforms to the new command-line format of Resource Hacker v5.1.6 from July 2018.

Install

$ npm install @erhhung/node-resource-hacker --save-dev

This wrapper is written using async/await support in ES8, and will require Node.js 8.0 at a minimum.

Upon first usage, this module will download "resource_hacker.zip" from www.angusj.com, the official and only website were Resource Hacker is distributed. It will then extract a single file, "ResourceHacker.exe", and place it into "node_modules\.bin".

Make sure your network proxy environment variable http_proxy is already set, if necessary.

Usage

import hacker from '@erhhung/node-resource-hacker';

async function setIcon() {
  try {
    await hacker({
      action:   'addoverwrite', // required
      open:     'bin\app.exe',  // required
      save:     'bin\app.exe',  // optional (default: .open)
      resource: 'res\app.ico',  // optional
      mask: {                   // optional
        type: 'ICONGROUP',
        name: '1',              // optional
        lang: '',               // optional
      },
    });
  } catch (err) {
    console.error(err);
  }
}

See the Command-Line Syntax section of Resource Hacker for details on available actions and mask values. This wrapper automatically adds the -log NUL option to suppress application output.

Pkg

This module was originally written to patch Windows executables generated by the pkg tool so one doesn't have to be stuck with the default node.exe icon. If you have the same use case, simply adapt the example above in your build script, and follow these tips:

  • Run Resource Hacker only on the output of pkg.
  • Make sure your resource .ico file has the exact same set of icon sizes (16x16, 32x32, 48x48, 64x64, 128x128) as the node.exe template or else the patched .exe will be corrupt! You can use an online tool like ICO Convert to convert from a PNG.
  • Make sure the mask type is ICONGROUP, and the mask name is 1.

License

MIT

1.0.1

4 years ago

1.0.0

6 years ago