-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: write asar integrity resource on windows (#8245)
Electron 30-x-y added support for ASAR integrity fuse on Windows. When enabled the app would fetch the ELECTRONASAR resource out of the executable file and use it to verify the integrity of the ASAR when reading the data from it.
- Loading branch information
1 parent
29f6504
commit 13e0e0d
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"app-builder-lib": patch | ||
--- | ||
|
||
write asar integrity resource on windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { readFile, writeFile } from "fs/promises" | ||
import { log } from "builder-util" | ||
import { NtExecutable, NtExecutableResource, Resource } from "resedit" | ||
import { AsarIntegrity } from "../asar/integrity" | ||
|
||
/** @internal */ | ||
export async function addWinAsarIntegrity(executablePath: string, asarIntegrity: AsarIntegrity) { | ||
const buffer = await readFile(executablePath) | ||
const executable = NtExecutable.from(buffer) | ||
const resource = NtExecutableResource.from(executable) | ||
|
||
const versionInfo = Resource.VersionInfo.fromEntries(resource.entries) | ||
if (versionInfo.length !== 1) { | ||
throw new Error(`Failed to parse version info in ${executablePath}`) | ||
} | ||
|
||
const languages = versionInfo[0].getAllLanguagesForStringValues() | ||
if (languages.length !== 1) { | ||
throw new Error(`Failed to locate languages in ${executablePath}`) | ||
} | ||
|
||
// See: https://github.com/electron/packager/blob/00d20b99cf4aa4621103dbbd09ff7de7d2f7f539/src/resedit.ts#L124 | ||
const integrityList = Array.from(Object.entries(asarIntegrity)).map(([file, { algorithm: alg, hash: value }]) => ({ | ||
file, | ||
alg, | ||
value, | ||
})) | ||
|
||
resource.entries.push({ | ||
type: "INTEGRITY", | ||
id: "ELECTRONASAR", | ||
bin: Buffer.from(JSON.stringify(integrityList)), | ||
lang: languages[0].lang, | ||
codepage: languages[0].codepage, | ||
}) | ||
|
||
resource.outputResource(executable) | ||
|
||
await writeFile(executablePath, Buffer.from(executable.generate())) | ||
log.info({ executablePath }, "updating asar integrity executable resource") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.