AlexAltea / capstone.js

Capstone disassembler framework for JavaScript
https://alexaltea.github.io/capstone.js/
BSD 3-Clause "New" or "Revised" License
172 stars 28 forks source link

Expose APIs to get instruction details. #5

Closed mbebenita closed 7 years ago

mbebenita commented 7 years ago

The APIs used in sections 3 and 4 from http://www.capstone-engine.org/lang_c.html would be nice to have exposed. A somewhat slow, but convenient way to extract data from C code is to write a JSON string on the C/C++ side then parse it on the JS side.

AlexAltea commented 7 years ago

Just added the necessary changes in 82bf11af8b60ef5900640dbefe41d2ad39132869 but I won't be able to test it until next week. I'll update the issue status then. Anyway, this should work as long as I didn't mess up calculating the offsets in memory (very likely though).

A somewhat slow, but convenient way to extract data from C code is to write a JSON string on the C/C++ side then parse it on the JS side.

Usually, I only patch the original libraries to fix issues with Emscripten. To read data from JavaScript, it's generally easier to rely on the Emscripten API [1] to directly access the memory.

[1] https://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html

mbebenita commented 7 years ago

Wow, thanks for the quick turnaround.

BTW, I'm using your library in http://wasmfiddle.com and http://mbebenita.github.io/WasmExplorer I like that you're porting these large libraries to asm.js / wasm, it enables lots of interesting use cases.