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

disassembler

v0.3.0-beta

Published

A library for disassembling various types of machine code.

Downloads

19

Readme

Disassembler

A library for disassembling various types of machine code. It is a thin wrapper over the Capstone disassembly framework, which has been compiled to WebAssembly and is automatically loaded when initialize is called.

Usage

import { initialize, Architecture, Mode } from 'disassembler';

async function disassembleStuff() {

    // initialize the library (loads the capstone WebAssembly binary).
    // This takes about half a second the first time. Thereafter, it
    // just returns the capstone object. You can call it once and then
    // keep the capstone object around.
    const capstone = await initialize();

    // create an instance that can disassemble Arm Thumb code.
    const instance = capstone.createInstance(Architecture.ARM, Mode.Thumb);

    // disassemble the code
    const someCode = Buffer.from("4ff00001bde80088d1e800f018bfadbff3ff0b0c86f3008980f3008c4ffa99f6d0ffa201", "hex");
    const instructions = instance.disassemble(someCode);

    // print out the results
    for (let insn of instructions) {
        console.log(`${insn.mnemonic} ${insn.operands}`);
    }
}

disassembleStuff().catch(console.error);

The code above spits out:

mov.w r1, #0
pop.w {fp, pc}
tbb [r1, r0]
it ne
iteet ge
vdupne.8 d16, d11[1]
msr cpsr_fc, r6
msr apsr_nzcvqg, r0
sxtb.w r6, sb, ror #8
vaddw.u16 q8, q8, d18

Note about web

The Capstone wasm file is quite large (5Mb). In order to save space, it is not included when packed with webpack or other tools but rather will be downloaded by calling fetch. The wasm file is stored on a CDN, is compressed to about 500kb, and may be cached indefinitely.

If this library is included from a regular node project, the wasm data is stored as hex in a javascript file generated when this library is published.

This works by specifying a different main file for browser in the package.json file. I'm not sure how one can go about overriding this behaviour. The reason it's completely separate is to prevent webpack from including 1Mb of hex stuff unnecessarily.

Work in Progress

This module does basic disassembly right now. It does not yet support all the various architectures. These things are on the to do list:

  • [x] Basic functionality.
  • [ ] Nice error strings.
  • [ ] Non-architecture specific details.
  • [ ] Architecture specific details and enums.
  • [ ] Some documentation, at least JSDoc.
  • [ ] The various helper functions (e.g. getting instruction names).
  • [x] Figure out some kind of way to garbage collect instances.

License

Files in this repo are copyright (c) 2021 Cillié Malan. See LICENSE for info.

This library relies on the Capstone disassembly framework. The sources for the capstone project, including modifications for this module, and any binary files produced therefrom, distributed with this library, are Copyright (c) 2013, COSEINC.