Is there a decompiler or disassembler in bytecode in javascript? Here is an example from python.

In [6]: def f(): ...: a=1 ...: In [7]: dis.dis(f) 2 0 LOAD_CONST 1 (1) 3 STORE_FAST 0 (a) 6 LOAD_CONST 0 (None) 9 RETURN_VALUE 
  • one
    Are you sure that the JS interpreter you are using has some intermediate code? - Vladimir Martyanov
  • one
    And what do you want to apply to the input of such a decompiler? - Grundy
  • In order for this question to have an unequivocal answer, it would be nice to confine ourselves to a specific implementation of JS. And if the choice will stop on V8, those who wish to respond can do the translation . - D-side
  • @ D-side, to be honest, not sure what exactly this author needs - Grundy
  • @Grundy it depends on which interpreter. In the context of V8, the answer to this question is exactly this, but for all implementations the answer (a) does not always exist, and (b) each case must be looked at separately. - D-side

1 answer 1

For the V8 ( chromium / chrome js engine ), you can use the built-in disassembler:

First build the source engine, including support for the disassembler:

 make ia32.release objectprint=on disassembler=on 

Then run d8 shell, with options

 out/ia32.release/d8 --print-opt-code --code-comments --trace-hydrogen your_app.js 

The first two options will print the assembler code with comments. The third option will generate a trace that can be viewed using the C1Visualizer.

honestly took the solution from Quora , did not check v8 on the latest sources

Corresponding options for spidermonkey (FF engine):

 IONFLAGS=codegen js --ion-offthread-compile=off app.js 

taken from enSO: Print ion monkey generated code

  • I just corrected the question - what is the code disassembled into? I need bytecode, native code is too complicated. Those. it doesn't need stackoverflow.com/a/1197559/2112218 - Smit Johnth
  • 2
    @SmitJohnth, javascript has no bytecode - Grundy
  • four
    In most cases, @SmitJohnth is used to compile directly into machine code bypassing the stage of creating bytecode. However, you can find old versions that used bytecode, for example, the old SpiderMonkey in which there is a compiler in bytecode. - Alex Krass
  • @Grundy not at all or what? And there are no instruction decompilers in js either? - Smit Johnth
  • @AlexKrass how old is he? How irrelevant? - Smit Johnth pm