UNPKG

ts-capstone

Version:

This module provides bindings for the Capstone disassembly framework.

28 lines (24 loc) 920 B
import { expect, test } from 'bun:test'; import CS, { type cs_opt_fmt } from '../capstone'; test('fmt', () => { const buffer = new Uint8Array([ 0x8d, 0x4c, 0x32, 0x08, 0x01, 0xd8, 0x81, 0xc6, 0x34, 0x12, 0x00, 0x00, 0x05, 0x23, 0x01, 0x00, 0x00, 0x36, 0x8b, 0x84, 0x91, 0x23, 0x01, 0x00, 0x00, 0x41, 0x8d, 0x84, 0x39, 0x89, 0x67, 0x00, 0x00, 0x8d, 0x87, 0x89, 0x67, 0x00, 0x00, 0xb4, 0xc6, 0x66, 0xe9, 0xb8, 0x00, 0x00, 0x00, 0x67, 0xff, 0xa0, 0x23, 0x01, 0x00, 0x00, 0x66, 0xe8, 0xcb, 0x00, 0x00, 0x00, 0x74, 0xfc, ]); const disassembler = new CS.CAPSTONE(CS.ARCH_X86, CS.MODE_16); disassembler.option(CS.OPT_DETAIL, true); const insns = disassembler.disasm(buffer, 0x1000); const options: cs_opt_fmt = { ASCII: true, colors: true, hex_comment: null, bytes: null, address: null }; console.log(disassembler.fmt(insns, options)); disassembler.close(); });