Created
June 24, 2020 02:44
-
-
Save Sturtuk/c74b41506d0ef71630eda2f1eb1adbbd to your computer and use it in GitHub Desktop.
Extract source code & directories from the javascript .map files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.