Giter Site home page Giter Site logo

jsc-decompile-mozjs-34's Introduction

1.Summary

This project is a javascript bytecode decoder for mozilla spider-monkey version 34.

This version may decompile jsc file compile by cocos-2dx.

It would not work for different version of Mozilla spider-monkey (without shell of course), for its opcode defined different for each version.

Maybe no longer update, but still a good example to understand how javascript virtual machine work (though different engine has different implement).

Is this project can just decompile "34" version only and why?

Well, the truth is may decompile near 34 version before bytecode file structure change.

Js engine may change the file struct for support new language feather, performance optimization, code refactoring, ...

But think of most change is just to add section(concept come of executable binary file) and add operation instead of change struct.

So this project just try to decompile without check magic code. At least, scan.php will work at most time.

2.Usage

2.1.Install PHP and Composer

If you are familiar with php, you can skip this part.

install php7.0 (still work in php7.4)

# ubuntu
$ sudo apt install php7.0

# mac
$ brew install php7.0

# windows
# just google an binary one

install composer

see https://getcomposer.org/download/

install this project

$ cd path/to/project
# no dependences, just auto generate the autoload
$ composer install

2.2.decompile *.jsc file

$ cd /path/to/this/project
$ php run.php /path/to/your.jsc > /path/to/decompile.txt
#if this didn't work, you can also try below command to get the bitcode
$ php scan.php /path/to/your.jsc > /path/to/scan.txt

2.3. print more info with scan.php

Just remove the slashes in scan.php

3. How to guess the bytecode version

magic code version
2C C0 73 B9 33
28 C0 73 B9 34
25 C0 73 B9 35
04 C0 73 B9 36
FC BF 73 B9 37
F4 BF 73 B9 38
D1 BF 73 B9 39
C3 BF 73 B9 40
B7 BF 73 B9 41
B3 BF 73 B9 42
AB BF 73 B9 43
A0 BF 73 B9 44
95 BF 73 B9 45
88 BF 73 B9 46
81 BF 73 B9 47

Yes, change happens >= 48. bytecodeVer(int) change to buildId(string). And buildId is very like an useragent of browser.

4.Besides

This project is not complete yet.

  • A Fatal Bug was found when decompile with a deep context

Decompile result is not a runable file. Some local variables are auto generate, for the compiler discards local variables.

jsc-decompile-mozjs-34's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsc-decompile-mozjs-34's Issues

加个readme.md吧

加个readme.md吧,写一下需要环境之类, 不然看了php才知道需要7.0

Error when trying to decompile

PHP Warning:  include(vendor/autoload.php): Failed to open stream: No such file or directory in D:\Software\decompile jsc\run.php on line 8
PHP Warning:  include(): Failed opening 'vendor/autoload.php' for inclusion (include_path='.;C:\php\pear') in D:\Software\decompile jsc\run.php on line 8
PHP Fatal error:  Uncaught Error: Class "Irelance\Mozjs34\Decompile" not found in D:\Software\decompile jsc\run.php:11
Stack trace:
#0 {main}
  thrown in D:\Software\decompile jsc\run.php on line 11```

Error when trying to decompile

C:\Users\LENOVO\Downloads\jsc-decompile-mozjs-34-master\jsc-decompile-mozjs-34-master>php run.php main.jsc > D:\decompile.txt
PHP Notice: Undefined index: retirevable in C:\Users\LENOVO\Downloads\jsc-decompile-mozjs-34-master\jsc-decompile-mozjs-34-master\src\Context.php on line 103
PHP Fatal error: Uncaught Error: Call to undefined method Irelance\Mozjs34\Decompile::getSummary() in C:\Users\LENOVO\Downloads\jsc-decompile-mozjs-34-master\jsc-decompile-mozjs-34-master\src\Xdr\Script.php:55
Stack trace:
#0 C:\Users\LENOVO\Downloads\jsc-decompile-mozjs-34-master\jsc-decompile-mozjs-34-master\src\Xdr\Script.php(207): Irelance\Mozjs34\Decompile->parserHeader(Object(Irelance\Mozjs34\Context))
#1 C:\Users\LENOVO\Downloads\jsc-decompile-mozjs-34-master\jsc-decompile-mozjs-34-master\src\Decompile.php(67): Irelance\Mozjs34\Decompile->XDRScript()
#2 C:\Users\LENOVO\Downloads\jsc-decompile-mozjs-34-master\jsc-decompile-mozjs-34-master\run.php(12): Irelance\Mozjs34\Decompile->run()
#3 {main}
thrown in C:\Users\LENOVO\Downloads\jsc-decompile-mozjs-34-master\jsc-decompile-mozjs-34-master\src\Xdr\Script.php on line 55

Undefined offset, Decompilation error

When attempting to decompile this file, I only receive a bunch of errors:

Notice: Undefined offset: 3277386 in C:\Tools\jsc-decompile-mozjs-34-master\src\Xdr\Atom.php on line 25  
Notice: Undefined offset: 3277385 in C:\Tools\jsc-decompile-mozjs-34-master\src\Xdr\Atom.php on line 25  
Notice: Undefined offset: 3277388 in C:\Tools\jsc-decompile-mozjs-34-master\src\Xdr\Atom.php on line 25  
...

I receive similar errors when attempting to decompile this file:

Notice: Undefined offset: 452315 in C:\Tools\jsc-decompile-mozjs-34-master\src\Xdr\Common.php on line 46  
Notice: Undefined offset: 452316 in C:\Tools\jsc-decompile-mozjs-34-master\src\Xdr\Common.php on line 46  
Notice: Undefined offset: 452317 in C:\Tools\jsc-decompile-mozjs-34-master\src\Xdr\Common.php on line 46  
...

I've double-checked to make sure these two files are in accordance to a previously-posted issue. These files share the magic number you mentioned that this tool can decompile: 2C C0 73 B9

Any help would be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.