capstone.js
capstone.js copied to clipboard
"MCapstone is not a function" error after manual build
After manually building the library with Grunt and Emscripten, using both capstone.min.js
and capstone-x86.min.js
, without adding any extra JS code:
capstone-x86_new.min.js:7 Uncaught TypeError: MCapstone is not a function
at capstone-x86_new.min.js:7:13
(anonymous) @ capstone-x86_new.min.js:7
capstone_new.min.js:535 Uncaught TypeError: MCapstone._malloc is not a function
at new Capstone (capstone_new.min.js:535:37)
at main.js:7:18
Likely you are using an incompatible (newer?) Emscripten version.
Emscripten has changed a lot over the years which means quite some maintenance burden for me, so I'm not going to update the build scripts unless we have a significant reason to do so (PRs are welcome though!).
Try to use whichever Emcripten version was latest as of the date of the latest release: 2027-02-01
Using Python 3.8.10 and latest Emscripten (3.1.9).
Looks like there are no changes needed. the output JS is good, only usage is a bit different.
There were probably some changes to Emscripten usage for MODULARIZE=1
option - module usage is documented here.
cs.MCapstone.then(instance => {
MCapstone = instance;
// Continue normally from here
const capstone = new cs.Capstone(cs.ARCH_X86, cs.MODE_64);
const code = new Uint8Array([0x55, 0x31, 0xD2, 0x89, 0xE5, 0x8B, 0x45, 0x08]);
const instructions = capstone.disasm(code, 0);
console.log(instructions);
})
This works 🙂 I suggest updating the example in the Readme accordingly.