我的目标:我试图将 .js 文件加密为 .jse,并仅在运行时解密(混淆 Nodejs 代码)。
var ffi = require('ffi'); //libpcrypt.so is a library to encrypt and decrypt files var crypt = ffi.Library('./libpcrypt', { 'decrypt' : [ 'string', ['string', 'string']] }); require.extensions[".jse"] = function (module) { module.exports = (crypt.decrypt(module.filename, 'out')); }; console.log(require('./routes.jse'));
我知道,用cosole.log()可以打印出源代码。
问题:解密的代码是一个纯字符串,我无法将其转换为用于导出的有效 JavaScript 对象。有没有办法导出我解密的代码串?
最佳答案
这是您的解决方案(未经测试):
require.extensions['.jse'] = function(module, filename) {
var content = crypt.decrypt(fs.readFileSync(filename), 'out')
return module._compile(content, filename);
};
快乐调试加密模块;)
关于javascript - 字符串中的有效nodejs代码到javascript对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13234991/