| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- const beautify = require('js-beautify').js_beautify
- const fs = require('fs')
- let code = fs.readFileSync('./game.min.js', 'utf8')
- // Get dictionary name, stores base64 encoded strings.
- let dictName = /^var (\S+)=\[/.exec(code)[1]
- // Get the dictionary itself
- let dict = JSON.parse(/(\[[^\]]*\])/.exec(code)[1].split("'").join('"')).map(x => Buffer.from(x, 'base64').toString()).map(x => JSON.stringify(x))
- // Find the offset for the dictionary
- let offset = parseInt(new RegExp(`\\(${dictName},0x([^\\)]*)\\)`).exec(code)[1], 16)
- // Find the dictionary function name
- let func = new RegExp(`\\(${dictName},0x${offset.toString(16)}\\)\\);var (_0x[^=]*)=`).exec(code)[1]
- // Apply the offset
- while (--offset >= 0) dict.push(dict.shift())
- // Replace strings
- code = code.replace(new RegExp(`${func}\\('0x([^']*)'\\)`, 'g'), (_, id) => dict[parseInt(id, 16)])
- // Replace x["simpleName"] with x.simpleName
- code = code.replace(/\["([a-zA-Z0-9_-]*)"\]/g, (_, x) => `.${x} `)
- // Find reverse string function (keep in mine, properties have trailing spaces at this point)
- reverseFunc = /(_0x[^\.]+\.\S+) =function\(_0x[^\)]+\){return _0x[^\)]+\.split \(''\)\.reverse \(\)\.join \(''\);}/.exec(code)[1]
- // Replace blah.reverse ("gnirtSemos") with "someString"
- code = code.replace(new RegExp(`${reverseFunc} \\(("[^"]*")\\)`, 'g'), (_, x) => JSON.stringify(JSON.parse(x).split('').reverse().join('')))
- // Replace x["simpleName"] with x.simpleName
- code = code.replace(/\["([a-zA-Z0-9_-]*)"\]/g, (_, x) => `.${x} `)
- // Replace hex with int
- code = code.replace(/([^_])0x([a-f0-9]+)([^"])/g, (_, a, b, c) => `${a}${parseInt(b, 16)}${c}`)
- // label Menu class
- code = code.split(/this.menu =new (_0x[0-9a-f]*)/.exec(code)[1]).join('Menu')
- // label Net class
- code = code.split(/this.net =new (_0x[0-9a-f]*)/.exec(code)[1]).join('Net')
- // label Game class
- code = code.split(/case "game":this.game =new (_0x[0-9a-f]*)/.exec(code)[1]).join('Game')
- // label Lobby class
- code = code.split(/case "lobby":this.game =new (_0x[0-9a-f]*)/.exec(code)[1]).join('Lobby')
- // label Jail class
- code = code.split(/case "jail":this.game =new (_0x[0-9a-f]*)/.exec(code)[1]).join('Jail')
- // Beautify code
- code = beautify(code, {
- indent_size: 2
- })
- fs.writeFileSync('game.decoded.js', code)
|