Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover javascript source code from uglifyjs source map

I am reverse engineering one magical script. I have an uglified source code and source map generated by uglifyjs.

Does anybody know any straightforward way how to achieve at least partly readable source code from that? I have found some obscure ways including conversions through multiple languages, but I hope something better exists.

Thank you!

like image 319
yety Avatar asked Aug 23 '15 01:08

yety


2 Answers

There is an npm library called maximize that purports to do this, but I couldn't get it to work. I rewrote it as unsourcemap but I am not a Node JS developer, so I'm sure it's awful. Anyway, it was a pretty trivial application of the source-map npm package.

Once you go through all the rigamarole of installing node-js and nvm and whatnot, you can clone that repo and say:

npm install . -g
unsourcemap path/to/packed.js path/to/packed.js.map path/to/output-dir/

I don't want to maintain this thing, so if someone wants to improve it, please just fork it and point people to that. :-)

like image 147
treat your mods well Avatar answered Sep 17 '22 14:09

treat your mods well


If the project is bundled using webpack / browserify, you can use Debundle package to do reverse engineering. Imho, the result will be either good or bad depending on some project.

And because it de-transpiles JS only (the uglifying webpack pipeline), so if you're using Vue SFC, the Debundle cannot produces your original .vue file, it's JS file instead.

Anw, in case of reading source code, if your web page doesn't hide the source map files, you can use Chrome DevTool > Source pannel to read the beautiful source easily:

Chrome DevTool - Source pannel

like image 41
Neo.Mxn0 Avatar answered Sep 18 '22 14:09

Neo.Mxn0