├── .gitignore ├── index.js ├── src ├── clean-ast.js ├── get-mapping.js ├── create-mapping.js └── cli.js ├── .travis.yml ├── package.json ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('./src/cli') 4 | -------------------------------------------------------------------------------- /src/clean-ast.js: -------------------------------------------------------------------------------- 1 | const traverse = require('babel-traverse').default 2 | const t = require('babel-types') 3 | const beautifier = require('babel-plugin-transform-beautifier') 4 | 5 | module.exports = function cleanAst (file) { 6 | traverse(file, beautifier({ types: t }).visitor) 7 | return file 8 | } 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - 8 5 | - 7 6 | before_install: 7 | - npm install -g npm@latest 8 | - npm install -g greenkeeper-lockfile@1 9 | 10 | before_script: 11 | - greenkeeper-lockfile-update 12 | script: 13 | - node ./index.js --verbose 14 | after_script: 15 | - greenkeeper-lockfile-upload 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "replug", 3 | "version": "2.0.2", 4 | "license": "MIT", 5 | "description": "Auto-reverse engineer Plug.dj javascript", 6 | "repository": "extplug/replug", 7 | "bin": "./index.js", 8 | "engines": { 9 | "node": ">= 8.9" 10 | }, 11 | "dependencies": { 12 | "babel-plugin-transform-beautifier": "^0.1.0", 13 | "babel-traverse": "^7.0.0-beta.3", 14 | "babel-types": "^7.0.0-beta.3", 15 | "babylon": "^7.0.0-beta.40", 16 | "bluebird": "^3.5.1", 17 | "browser-resolve": "^1.11.2", 18 | "chalk": "^2.3.1", 19 | "commander": "^2.14.1", 20 | "got": "^8.1.0", 21 | "jsdom": "^11.6.2", 22 | "listr": "^0.13.0", 23 | "listr-update-renderer": "^0.4.0", 24 | "listr-verbose-renderer": "^0.4.1", 25 | "mkdirp-then": "^1.1.0", 26 | "mz": "^2.7.0", 27 | "plug-login": "^1.2.0", 28 | "plug-modules": "^5.2.0", 29 | "prettier": "^1.10.2" 30 | }, 31 | "devDependencies": { 32 | "standard": "^11.0.0" 33 | }, 34 | "scripts": { 35 | "test": "standard src/*.js" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # non-lethal plug.dj reverse engineering 2 | 3 | A messy script that spews as-readable-as-computerly-possible versions of plug.dj 4 | modules into a directory. 5 | 6 | ## usage 7 | 8 | The easiest way to use replug is with [npx](https://npmjs.com/package/npx): 9 | 10 | 1. `npx replug` 11 | 12 | Alternatively, install the CLI globally (you'll have to update manually from time to time): 13 | 14 | 1. `npm install -g replug` 15 | 1. `replug` 16 | 17 | There are some command-line options: 18 | 19 | -h, --help output usage information 20 | -V, --version output the version number 21 | -m, --mapping [file] File containing the mapping JSON (optional, it's auto-generated if no file is given) 22 | -o, --out [dir] Output directory [out/] 23 | -v, --verbose Use verbose output instead of bullet list 24 | 25 | ### examples 26 | 27 | Dump output in `out/`: 28 | 29 | ``` 30 | npx replug 31 | ``` 32 | 33 | Output in `output-directory/`: 34 | 35 | ``` 36 | npx replug --out output-directory 37 | ``` 38 | 39 | ## Licence 40 | 41 | [MIT](./LICENSE) 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 René Kooi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/get-mapping.js: -------------------------------------------------------------------------------- 1 | /* global $ */ 2 | 3 | // eslint-disable-next-line no-unused-vars 4 | function getMapping (plugModules) { 5 | plugModules.run() 6 | 7 | const knownKeys = Object.keys(plugModules._nameMapping) 8 | const unknownKeys = plugModules.getUnknownModules() 9 | 10 | const knownModules = knownKeys.map((key) => ({ 11 | isUnknown: false, 12 | name: key, 13 | original: plugModules.resolveName(key), 14 | module: plugModules.require(key) 15 | })) 16 | const unknownModules = unknownKeys.map((key) => ({ 17 | isUnknown: true, 18 | name: '?', 19 | original: key, 20 | module: plugModules.require(key) 21 | })) 22 | 23 | // build mappings 24 | const partsMapping = {} 25 | knownModules.forEach((mod) => { 26 | const name = mod.name.split('/') 27 | const obsc = mod.original.split('/') 28 | 29 | obsc.forEach((part, i) => { 30 | partsMapping[part] = name[i] 31 | }) 32 | }) 33 | 34 | // guess module names based on known paths 35 | unknownModules.forEach((mod) => { 36 | mod.name = mod.original 37 | .split('/') 38 | .map((part) => partsMapping[part] || part) 39 | .join('/') 40 | }) 41 | 42 | // modules that were not remapped by plug-modules, but were partially guessed 43 | const unknownPlugModules = unknownModules.filter( 44 | (mod) => mod.name.indexOf('plug/') === 0 45 | ) 46 | 47 | void unknownPlugModules // It's not used atm 48 | 49 | // build full mapping of original names to (possibly partially guessed) proper names 50 | const fullMapping = {} 51 | knownModules.concat(unknownModules).forEach((mod) => { 52 | fullMapping[mod.original] = mod.name 53 | }) 54 | 55 | const scriptSources = $('script[src*="cdn.plug"]').toArray().map((el) => el.src) 56 | 57 | // get plug.dj version (it appears in one of the inline