electron asar防止解压 asarmor安装教程 node-gyp总是安装失败?

本示例适用于以下插件创建的vue-electron项目

"vue-cli-plugin-electron-builder": "3.0.0-alpha.4"

环境信息

node > 16.17.1
node-gyp = 8.4.0
asarmor = 2.0.0

安装插件

npm i node-gyp@8.4.0 -g
npm i asarmor@2.0.0 --save-dev
备注:asarmor似乎会和uglifyjs-webpack-plugin,要加密源码的可以试试webpack-obfuscator

如需要代码加密:在vue.config.js中
const webpackObfuscator = require('webpack-obfuscator')
configureWebpack中
plugins: process.env.NODE_ENV === 'production' ? [new webpackObfuscator({
      rotateUnicodeArray: true
    })] : []
即可

在项目根目录(与package.json同级)创建asarmor.js

// 防止asar包被解压
const asarmor = require('asarmor')
const path = require('path')
exports.default = async ({ appOutDir, packager }) => {
  try {
    const asarPath = path.join(packager.getResourcesDir(appOutDir), 'app.asar')
    const archive = await asarmor.open(asarPath)
    archive.patch()
    archive.patch(asarmor.createBloatPatch(1314))
    await archive.write(asarPath)
  } catch (error) {
    console.log(error)
  }
}

在vue.config.js中引入并使用

在module.exports = defineConfig({ 里面的 pluginOptions中的electronBuilder中的builderOptions增加:
afterSign: './asarmor.js',

大功告成!打包之后对方通过asar解压app.asar时即可无限得到1G的随机文件并无限循环~~~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容