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 🙏

© 2026 – Pkg Stats / Ryan Hefner

binary-file-modifier

v1.0.3

Published

二进制固件文件修改工具 - JavaScript版本

Readme

binary-file-modifier

二进制固件文件修改工具(TypeScript 版本)。支持指定地址、位宽(8/16/32/64)、大小端(be/le)进行写入,同时提供事件回调与配置锁定。

安装

# 项目内安装(库/CLI)
npm install binary-file-modifier
# 或
cnpm install binary-file-modifier

# 全局安装(使用 CLI)
npm install -g binary-file-modifier
# 或
cnpm install -g binary-file-modifier

# 开发依赖安装(测试、示例运行)
cnpm install -D vitest ts-node

构建

cnpm run build

API 使用示例

基础写入示例(src/examples/basic-usage.ts):

import { BinModifier } from '../binModifier';

const bm = new BinModifier(undefined, {
  filePath: '/path/to/firmware.bin',
  address: 0,
  bitLength: 8,
  endian: 'be',
  showBytes: true,
  logger: console,
});

const fileObj = bm.writeInt(0xff);
await bm.writeToDisk(fileObj);

高级功能示例(事件监听与配置锁定,src/examples/advanced-features.ts):

bm.on('before:write', (ctx) => console.log('before', ctx));
bm.on('after:write', (ctx) => console.log('after', ctx));
bm.lock();

CLI 使用

构建后可使用 CLI:

# 显示帮助
node dist/cli.js --help

# 或通过 bin 包装
node bin/firmware-modifier --help
# 或使用发布后的可执行别名
binary-file-modifier --help

# 写入示例:将 0x12345678 写入 0x10 位置,32 位小端
node dist/cli.js --file ./sample.bin --address 0x10 --bits 32 --endian le --value 305419896 --show

参数说明:

  • --file 固件文件路径
  • --address 写入地址(支持十六进制如 0x7C00 或十进制)
  • --bits 位宽:8/16/32/64
  • --endian 大小端:bele
  • --value 写入整数值(范围受位宽限制)
  • --show 是否打印写入前后字节

运行示例与测试

# 运行示例
cnpm run example:basic
cnpm run example:advanced

# 运行测试
cnpm run test

开发说明

  • 代码风格:ESLint v9 + Prettier(已配置)
  • 类型检查:TypeScript 5.x,严格模式
  • 测试:Vitest
  • 示例:src/examples 目录