diff --git a/lib/mach-o.ts b/lib/mach-o.ts index d4d832a8..9993457b 100644 --- a/lib/mach-o.ts +++ b/lib/mach-o.ts @@ -32,6 +32,11 @@ function patchCommand(type: number, buf: Buffer, file: Buffer) { } } +/** + * It would be nice to explain the purpose of this patching function + * @param file + * @returns + */ function patchMachOExecutable(file: Buffer) { const align = 8; const hsize = 32; @@ -67,4 +72,14 @@ function signMachOExecutable(executable: string) { } } -export { patchMachOExecutable, signMachOExecutable }; +function removeMachOExecutableSignature(executable: string) { + execFileSync('codesign', ['--remove-signature', executable], { + stdio: 'inherit', + }); +} + +export { + patchMachOExecutable, + removeMachOExecutableSignature, + signMachOExecutable, +}; diff --git a/lib/sea.ts b/lib/sea.ts index 3eb36e6b..d028c54d 100644 --- a/lib/sea.ts +++ b/lib/sea.ts @@ -11,7 +11,11 @@ import unzipper from 'unzipper'; import { extract as tarExtract } from 'tar'; import { log } from './log'; import { NodeTarget, Target } from './types'; -import { patchMachOExecutable, signMachOExecutable } from './mach-o'; +import { + patchMachOExecutable, + removeMachOExecutableSignature, + signMachOExecutable, +} from './mach-o'; const exec = util.promisify(cExec); @@ -277,9 +281,16 @@ async function bake( await copyFile(nodePath, outPath); log.info(`Injecting the blob into ${outPath}...`); - await exec( - `npx postject "${outPath}" NODE_SEA_BLOB "${blobPath}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2`, - ); + if (target.platform === 'macos') { + removeMachOExecutableSignature(outPath); + await exec( + `npx postject "${outPath}" NODE_SEA_BLOB "${blobPath}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --macho-segment-name NODE_SEA`, + ); + } else { + await exec( + `npx postject "${outPath}" NODE_SEA_BLOB "${blobPath}" --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2`, + ); + } } /** Create NodeJS executable using sea */ diff --git a/test/test-00-sea/main.js b/test/test-00-sea/main.js index beb587a6..7daf2a2e 100644 --- a/test/test-00-sea/main.js +++ b/test/test-00-sea/main.js @@ -28,12 +28,11 @@ if (process.platform === 'linux') { 'Output matches', ); } else if (process.platform === 'darwin') { - // FIXME: not working, needs investigation - // assert.equal( - // utils.spawn.sync('./test-sea-macos', []), - // 'Hello world\n', - // 'Output matches', - // ); + assert.equal( + utils.spawn.sync('./test-sea-macos', []), + 'Hello world\n', + 'Output matches', + ); } else if (process.platform === 'win32') { // FIXME: output doesn't match on windows // assert.equal(