我使用javascript-obfuscator包,如果我对文件进行操作,它可以正常工作,例如:
javascript-obfuscator source.js
但我需要动态更改js源内容并以类似方式在控制台上输出
javascript-obfuscator "var foo = 'bar'; alert(foo);"
任何建议我如何摆脱将内容保存到文件并像上面的代码片段那样做?
答案 0 :(得分:2)
没有真正考虑为什么你需要这样做,看起来你需要使用图书馆自述文件中描述的编程API。< / p>
让我们称之为obfuscate.js
:
var JavaScriptObfuscator = require('javascript-obfuscator');
var obfuscationResult = JavaScriptObfuscator.obfuscate(
process.argv[2],
{
compact: false,
controlFlowFlattening: true
}
);
console.log(obfuscationResult.getObfuscatedCode());
$ node obfuscate.js 'console.log(1)'
将输出(例如)
var _0x2b5a = ['log'];
(function (_0x630038, _0x2944a9) {
var _0x83df37 = function (_0x2ef1a5) {
while (--_0x2ef1a5) {
_0x630038['push'](_0x630038['shift']());
}
};
_0x83df37(++_0x2944a9);
}(_0x2b5a, 0xd7));
var _0x493b = function (_0x2b48eb, _0x33884a) {
_0x2b48eb = _0x2b48eb - 0x0;
var _0x41338b = _0x2b5a[_0x2b48eb];
return _0x41338b;
};
console[_0x493b('0x0')](0x1);