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

ksdumpjs

v1.0.2

Published

Dump binary to json using format.

Downloads

27

Readme

npm version

About

This is a tool to dump binary files into JSON using Kaitai Struct formats.

It instantiates instance values, populates enum name values and loads format imports.

It most likely does not cover many constructs that can be created using Kaitai Struct but it should work for most formats. It serves as a lightweight alternative to installing the Kaitai Struct Visualizer's ksdump.

Kaitai Struct
Kaitai Struct Visualizer

Install

npm install -g ksdumpjs

Usage

Concept

Without any args ksdumpjs will use ksy format files in ./formats to compile parsers that are output to ./parsers and then parse binary files in ./binaries based on the format's meta section using ${id}.{file-extension} to identify a matching binary for the format placing the JSON output in ./jsons.

Arguments

--format, -f: Path to a .ksy format file or directory of format files. Default is ./formats.
--binary, -b: Path to a binary file, directory, or glob pattern. Default is ./binaries.
--out, -o: Output path for JSON files. Default is ./jsons.
--parser, -p: Directory for compiled parsers. Default is ./parsers.
--spaces, -s: Number of spaces for formatted JSON output (use compact output if omitted).

Details

| Format | Binary | Result | Comment | |------------|------------|--------|--------------------------------------------------------------------------------------------------| | directory | directory | allow | Use .ksy meta {id}.{file-extension} to find matches in binary | | file | directory | allow | Use .ksy meta {id}.{file-extension} to find match in binary | | file | file | allow | | | file | glob | allow | Use format on each binary result of glob | | directory | file | deny | Ambiguous: cannot determine which .ksy file in the directory should match the binary file | | directory | glob | deny | Ambiguous: cannot determine which .ksy file in the directory should match the binary files | | glob | <any> | deny | Ambiguous: multiple .ksy files could match the binary files |

Note: use forwardslash for paths, backslash will escape any glob tokens.

Example

> node ksdump .\test\formats\zip.ksy .\test\samples\sample1.zip .\jsons -s
►  ksdump           Initialized timer...

Processing:      .\test\formats\zip.ksy
⚙️  Generating:      Zip
  -> Importing common/dos_datetime
     Parsing common/dos_datetime
🔍  Parsing binary:  .\test\samples\sample1.zip
📤  Transforming:    .\test\samples\sample1.zip
📤  Exporting:       jsons\sample1.json
✅  Success          jsons\sample1.json

[█] ksdump           Timer run for: 128ms

Verify correctness against Kaitai Struct Web-IDE exported json:

jq will sort the field order since the instantiated instance field orders differs between ksdumpjs and the Kaitai Struct Web-IDE.

> ./jq -b -S . .\jsons\sample1.json > sorted_sample1.json
> ./jq -b -S . check_sample1.json > sorted_check_sample1.json
> git diff --no-index sorted_sample1.json sorted_check_sample1.json
> $?
True

Why

ksdumpjs allows you to parse structured binary data into JSON for easier integration with analysis tools, such as spreadsheets. Compared to the Kaitai Struct Web IDE, which struggles with large files due to browser memory limits, ksdumpjs uses json-stream-stringify to avoid memory constraints.

On a Ryzen 5700G, ksdumpjs can parse a 165MB binary file containing 200+ fields with nested types in ~3 seconds, and output 614MB of JSON in ~25 seconds (or 1GB formatted output in ~30 seconds).