bytenode: Problem with JavaScript Obfuscator package
_Originally posted by @cyphercodes96 in https://github.com/OsamaAbbas/bytenode/issues/5#issuecomment-727723366_
Awesome and amazing work on this package - Looking forward to put it into good use
JSYK whenever I try to bytenode an obfuscated file using JavaScriptObfuscator I get the same rangeError invalid string length exception
Would be awesome if we can somehow resolve this - would add more security whenever the .js file will exist prior to .jsc on production environment ( prior to compilation / deletion of file )
const obfJs = (src, options = {}) => {
fs.readFile(src, 'utf8', function (err, data) {
if (err) return console.log('err obfuscation3 to file', err);
var obfuscationResult = JavaScriptObfuscator.obfuscate(data, Object.assign({}, obfOptions, options));
fs.writeFile(src, obfuscationResult.getObfuscatedCode(), 'utf8', function (err) {
if (err) return console.log('err obfuscation4 to file', err);
});
});
};
obfJs('./libraries/secured.js');
Then on my electron main.js
const appPath = require('electron-root-path').rootPath;
const obfJs2Byte = (src, options = {}) => {
console.log('obfuscating js 2 bye');
try {
let compiledFilename = bytenode.compileFile({
filename: appPath + src,
compileAsModule: true
});
console.log(compiledFilename)
} catch (err) {
console.log('ERR CAUGHT', err)
}
try {
fs.unlink(appPath + src, (err) => {
if (err) {
console.error(err);
return
}
})
} catch (err) {
console.error(err)
}
};
console.log('LOGGING FILE RN');
const bytenode = require('bytenode');
if (!fs.existsSync(appPath + '/secured.jsc')) {
obfJs2Byte('/secured.js');
}
const Security = require(appPath + '/secured.jsc');
Remove javascript obfuscation and it works like a charm
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16
I think you are right!!! I obfuscated the code below in https://obfuscator.io/
No matter whether debugProtection or self-defending is checked. It outputs: Function.prototype.toString is called Hello World! (Note: Check Evaluate options in the output tab in https://obfuscator.io) Thanks very much!
Iām sorry I canāt provide a demo project, because I created a demo with vue-cli+electron-builder+javaScript-obfuscator on another computer and there is no problem. The program I had a problem with is on the intranet and could not be taken out. But I found the problem is because of the arrow function! I donāt know why there are many arrow functions in the vue code packaged in electron, even if babel is added by default. As far as I know, I usually use vue to build projects and add babel by default to transpile arrow functions into ordinary functions.
My process of creating the project: 1.vue create demo 2.vue add electron-builder
I finally solved the problem by adding the plugin ā@babel/plugin-transform-arrow-functionsā to the babel.config.js file in the project root directory.
However, the debugProtection option of JavaScript-obfuscator still prevents the program from starting (the application window is blank after opening).I only open the āDebug Protectionā option at https://obfuscator.io/, you can see that it has inserted a piece of code.Other options of JavaScript-obfuscator are still undetermined.
Thanks again!
I had the same problem. I will give a complete reproducible example later. If this problem is solved, it will help me a lot. Thank you very much.Bytenode is a great work!
If anyone also has this problem, either use a buffer to decode or just remove the stringArrayEncoding. Itās kind of useless anyway, since it only takes secs to reverse.