Skip to content

Instantly share code, notes, and snippets.

@Sturtuk
Created June 24, 2020 02:44
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Sturtuk/c74b41506d0ef71630eda2f1eb1adbbd to your computer and use it in GitHub Desktop.
Save Sturtuk/c74b41506d0ef71630eda2f1eb1adbbd to your computer and use it in GitHub Desktop.
Extract source code & directories from the javascript .map files
<?php
/**
* Created by PhpStorm.
* User: edwinsturt
* Date: 2020-06-24
* Time: 00:45
*/
$file = 'main.ff0058ad.js.map';
if(file_exists($file)) {
$json = json_decode(file_get_contents($file));
$directories = [];
foreach ($json->sources as $index => $source) {
$dir = dirname($source);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$data = explode('/', $source);
$file = end($data);
file_put_contents($dir . "/" . $file, $json->sourcesContent[$index]);
$files[] = $dir . "/" . $file;
}
echo "<pre>All Source codes has been extracted from map file ";
print_r($files);
}
@mikkorantalainen
Copy link

Note that if the .map file is actually hostile, running this script may overwrite any files in your local operating system that you have write access to. The script assumes that $source is a safe local file path and it's safe to create and write directory hierarchy as whatever strings the .map file contains.

At very minimum, the variable $source should be sanity checked to not start with a slash and to not contain any sequences of ../ to avoid security vulnerability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment