Problem with JavaScript Obfuscator package
See original GitHub issue_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
Issue Analytics
- State:
- Created 3 years ago
- Comments:16
Top Results From Across the Web
Issues · javascript-obfuscator/javascript-obfuscator - GitHub
A powerful obfuscator for JavaScript and Node.js. Contribute to javascript-obfuscator/javascript-obfuscator development by creating an account on GitHub.
Read more >javascript-obfuscator - npm Package Health Analysis - Snyk
We found that javascript-obfuscator demonstrates a positive version release cadence with at least one new version released in the past 12 months. As...
Read more >node.js - failing to package a script using pkg after obfuscating ...
i wanted to obfuscate my files with https://www.npmjs.com/package/javascript-obfuscator before compiling them to an executable to make it ...
Read more >javascript-obfuscator - npm
Start using javascript-obfuscator in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type ...
Read more >JavaScript Obfuscation: The Definitive Guide (2022)
As with all things related to security, obfuscation is a high-stakes process. Just like using a weak JS obfuscator can provide a wrong...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!