Created
December 4, 2023 21:07
-
-
Save j4k0xb/0d76d103db9696b515ce9c51c45b76b8 to your computer and use it in GitHub Desktop.
This file contains 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
const fs = require("fs"); | |
const { SourceMapConsumer, SourceMapGenerator } = require("source-map"); | |
function reverseSourceMap(sourceMap) { | |
return SourceMapConsumer.with(sourceMap, null, (consumer) => { | |
const reversedMap = new SourceMapGenerator(); | |
consumer.eachMapping((mapping) => { | |
reversedMap.addMapping({ | |
generated: { | |
line: mapping.originalLine, | |
column: mapping.originalColumn, | |
}, | |
original: { | |
line: mapping.generatedLine, | |
column: mapping.generatedColumn, | |
}, | |
source: "deobfuscated.js", | |
}); | |
}); | |
return reversedMap.toJSON(); | |
}); | |
} | |
const sourceMap = JSON.parse(fs.readFileSync(process.argv[2], "utf-8")); | |
reverseSourceMap(sourceMap).then((reverseMap) => | |
console.log(JSON.stringify(reverseMap, null, 2)) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment