跳转到主内容

Electron Fuses

包特性切换

什么是 fuses ?

对于某些基于 Electron 的功能性应用,为整个应用程序禁用某些功能是具有意义的。 例如,99%的应用都没有使用ELECTRON_RUN_AS_NODE。它们希望能够提供无法使用该功能的二进制文件。 我们也不想要让 Electron 的使用者使用源代码重新编译构建 Electron ,因为这不但具有巨大的技术挑战,而且会花费高昂的时间、金钱成本。

Fuses 是这些问题的一个解决方案。它们在 Electron 二进制文件中有“魔法”,可以使您在打包您的 Electron 时选择启用或者禁用某些功能(限制) Because they are flipped at package time before you code sign your app the OS becomes responsible for ensuring those bits aren't flipped back via OS level code signing validation (Gatekeeper / App Locker).

How do I flip the fuses?

简易方式

We've made a handy module, @electron/fuses, to make flipping these fuses easy. Check out the README of that module for more details on usage and potential error cases.

require('@electron/fuses').flipFuses(
// Path to electron
require('electron'),
// Fuses to flip
{
runAsNode: false
}
)

复杂方式

快速术语表

  • Fuse Wire: A sequence of bytes in the Electron binary used to control the fuses
  • Sentinel: A static known sequence of bytes you can use to locate the fuse wire
  • Fuse Schema: The format / allowed values for the fuse wire

Manually flipping fuses requires editing the Electron binary and modifying the fuse wire to be the sequence of bytes that represent the state of the fuses you want.

Somewhere in the Electron binary there will be a sequence of bytes that look like this:

| ...binary | sentinel_bytes | fuse_version | fuse_wire_length | fuse_wire | ...binary |
  • sentinel_bytes is always this exact string dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX
  • fuse_version is a single byte whose unsigned integer value represents the version of the fuse schema
  • fuse_wire_length is a single byte whose unsigned integer value represents the number of fuses in the following fuse wire
  • fuse_wire is a sequence of N bytes, each byte represents a single fuse and its state.
    • "0" (0x30) indicates the fuse is disabled
    • "1" (0x31) indicates the fuse is enabled
    • "r" (0x72) indicates the fuse has been removed and changing the byte to either 1 or 0 will have no effect.

To flip a fuse you find its position in the fuse wire and change it to "0" or "1" depending on the state you'd like.

您可以在 这里查看当前schema。