js混淆 javascript-obfuscator(nodejs DEMO)

个人代码记录,不适用于大多数人

const fs = require('fs');
const JavaScriptObfuscator = require('javascript-obfuscator');

/*必须是当前目录!
还有是正常的  a.b.c 这样的格式文件

a.b.c ->  a.b.m.c
jq.js -> jq.m.js
haha.cc -> haha.m.cc


*/
//要写全路径  C:\Users\Administrator\Desktop\benjazhu\fire\public\js  or ./
let filename='C:/Users/Administrator/Desktop/benjazhu-06-02-19/fire/public/js/???.js'  
let newArr =  filename.split('.')
newArr[newArr.length-2] = newArr[newArr.length-2]+'.m'
let newName =   newArr.join('.')

fs.readFile(`${filename}`, 'utf-8', (err, file) => {
  if (!err) {
    var obfuscationResult = JavaScriptObfuscator.obfuscate(file, {


      debugProtection: true,
      //debugProtection debuger 会干扰 F12 
      disableConsoleOutput: true,
      //禁用控制台 就是console.xx 禁止了
      identifierNamesGenerator:'mangled',
      //hexadecimal: identifier names like _0xabc123 
      // mangled: short identifier names like a, b, c
      stringArrayThreshold:1,
      //是1的话 几乎全部是字符串数组 a= ['a','b'] 这样来调用,如果是0 就相当于为改变



    })
    fs.writeFile(`${newName}`, obfuscationResult.getObfuscatedCode(), 'utf-8', (err1) => {
      if (!err1) {
        console.log('文件写入OK')
      }
    })
  } else {
    console.log('no file')
  }
})



参考

github javascript-obfuscator



回到顶部