From 1550352ec3b05e811da06a532aad0a3f1b091ccb Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 30 Jan 2023 23:45:07 -0800 Subject: [PATCH 1/3] Mach-O types are in big endian format One of my dependencies for some reason has two universal binaries per platform, and they are not exactly the same bytewise. I'm unsure why. But I am certain they are functional. In any case, this error is erroneously being thrown since it fails the previous byte comparison match. ```ts throw new Error(`Can't reconcile two non-macho files ${file}`); ``` CAFEBABE and FEEDFACE magics for universal binaries. This will allow packaging to continue if both the arm and x64 packages have universal binaries. --- src/asar-utils.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/asar-utils.ts b/src/asar-utils.ts index 882a8c9..928cfe5 100644 --- a/src/asar-utils.ts +++ b/src/asar-utils.ts @@ -33,6 +33,12 @@ const MACHO_MAGIC = new Set([ 0xcffaedfe, ]); +const MACHO_UNIVERSAL_MAGIC = new Set([ + // universal + 0xcafebabe, + 0xbebafeca, +]); + export const detectAsarMode = async (appPath: string) => { d('checking asar mode of', appPath); const asarPath = path.resolve(appPath, 'Contents', 'Resources', 'app.asar'); @@ -147,7 +153,11 @@ export const mergeASARs = async ({ continue; } - if (!MACHO_MAGIC.has(x64Content.readUInt32LE(0))) { + if (MACHO_UNIVERSAL_MAGIC.has(x64Content.readUInt32LE(0)) && MACHO_UNIVERSAL_MAGIC.has(arm64Content.readUInt32LE(0))) { + continue; + } + + if (!MACHO_MAGIC.has(x64Content.readUInt32BE(0))) { throw new Error(`Can't reconcile two non-macho files ${file}`); } @@ -192,7 +202,6 @@ export const mergeASARs = async ({ } d(`creating archive at ${outputAsarPath}`); - const resolvedUnpack = Array.from(unpackedFiles).map((file) => path.join(x64Dir, file)); let unpack: string | undefined; From 20a89f648dd6c0991ff306ab64f0f7df7044ff11 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 30 Jan 2023 23:50:03 -0800 Subject: [PATCH 2/3] Update asar-utils.ts --- src/asar-utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asar-utils.ts b/src/asar-utils.ts index 928cfe5..91ba3fc 100644 --- a/src/asar-utils.ts +++ b/src/asar-utils.ts @@ -157,7 +157,7 @@ export const mergeASARs = async ({ continue; } - if (!MACHO_MAGIC.has(x64Content.readUInt32BE(0))) { + if (!MACHO_MAGIC.has(x64Content.readUInt32LE(0))) { throw new Error(`Can't reconcile two non-macho files ${file}`); } From 487424b42022b32a2bdb54345deb9bf8fd7313f7 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 30 Jan 2023 23:50:28 -0800 Subject: [PATCH 3/3] Update asar-utils.ts --- src/asar-utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/asar-utils.ts b/src/asar-utils.ts index 91ba3fc..792f04b 100644 --- a/src/asar-utils.ts +++ b/src/asar-utils.ts @@ -202,6 +202,7 @@ export const mergeASARs = async ({ } d(`creating archive at ${outputAsarPath}`); + const resolvedUnpack = Array.from(unpackedFiles).map((file) => path.join(x64Dir, file)); let unpack: string | undefined;