Skip to content

Instantly share code, notes, and snippets.

@sfabijanski
Forked from davestewart/README.md
Created April 18, 2023 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfabijanski/9167c8e8ce8764ac7f941d0b33922f03 to your computer and use it in GitHub Desktop.
Save sfabijanski/9167c8e8ce8764ac7f941d0b33922f03 to your computer and use it in GitHub Desktop.
Decompile JavaScript from source maps

Decompile JavaScript from source maps

Overview

Modern JavaScript build tools compile entire folder structures of JavaScript code into single, minified files that are near-impossible to read, but can also include source maps which can be used to display the original code in tools such as the Chrome DevTools Sources panel.

These source maps can be processed to extract mainly meaningful code and file structures, by installing a package and running a simple bash command.

Generally, production builds shouldn't include source maps, but if you do manage to lose your source files, or for some (obviously, ethical!) reason need to view the original files, and you happen to have / find the source maps, you're good to go.

Instructions

This code will work on Mac/Unix.

  1. Locate your compiled files, which should include *.js.map files
  2. Create a new folder <project>
  3. Place files in <project>/input
  4. Run the script below from <project>
  5. View the files

Problems

Can't install module

The script installs a module from a PR to the main Shuji repository.

It may be that by the time you read this, that PR has been merged, so the module install will fail.

If so, update the install line with the main repository:

npm install paazmaya/shuji

The source files are not the same as the originals

Only the information in the source maps can be restored.

If these don't contain the full source code, then you're out of luck. Work with what you have!

Links

echo install decompiler
npm install mazamachi/shuji#add-preserve-option
echo find and extract files
find input -name '*.js.map' -exec shuji {} -o output -p \;
echo view files
open output/input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment