An obfuscation extension to electron-vite's V8 Bytecode plugin using javascript-obfuscator.
npm i electron-vite-obfuscator -D
Similarly to how the official Bytecode plugin works, use the plugin bytecodePlugin to enable bytecode protection:
import { defineConfig } from 'electron-vite'
import { bytecodePlugin } from 'electron-vite-obfuscator'
export default defineConfig({
main: {
plugins: [bytecodePlugin()]
},
preload: {
plugins: [bytecodePlugin()]
},
renderer: {
// ...
}
})
To enable the javascript obfuscation, pass the wanted obfuscator settings in the obfuscationOptions object. Refer to the javascript-obfuscator official documentation to see all possible options.
import { defineConfig } from 'electron-vite'
import { bytecodePlugin } from 'electron-vite-obfuscator'
export default defineConfig({
main: {
plugins: [
bytecodePlugin({
obfuscationOptions: {
//options go here
}
})
]
},
preload: {
// ...
})
Important
Both selfDefending
and debugProtection
depend on Function.prototype.toString()
. According to the electron-vite docs, the function does not work due to bytecode's nature. Thus, selfDefending
and debugProtection
are enforced to false
.
On top of obfuscationOptions
, all official electron-vite bytecodePlugin options (protectedStrings
, transformArrowFunctions
, etc) are supported. They can be found here.
Based on my own understanding, having extra obfuscation supported is not in the roadmap of electron-vite. By making a separate package, I can improve and work on this without cluttering and making electron-vite deviate from its original purpose. Of course, if alex.wei does want to include my changes, he's free to do so.
First of all, the obfuscation process is embedded in the bytecode transformation process. Therefore you are sure that everything works as it should, and when it should. Second of all, stringArray
works perfectly compared to other modern alternatives that enforce it to false
.
The larger the project, the more problems you stumble upon. Before submitting an issue, try playing around with the different javascript-obfuscator settings.
- Create an issue