From 70be75a8bebd7d004a6788b0764489da24e4eb3a Mon Sep 17 00:00:00 2001 From: mrmacete Date: Tue, 7 Nov 2023 16:47:30 +0100 Subject: [PATCH] Fix codesign identifier parsing on fat bins --- lib/bin.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/bin.js b/lib/bin.js index 82f4e9d..db6a097 100644 --- a/lib/bin.js +++ b/lib/bin.js @@ -154,6 +154,16 @@ function parseMacho (data) { } } +function parseMachoAndGetData (data) { + try { + return [macho.parse(data), data]; + } catch (e) { + const fat = fatmacho.parse(data); // throws + const slice = fat[0].data; + return [parseMacho(slice), slice]; + } +} + function enumerateLibraries (data) { if (typeof data === 'string') { data = fs.readFileSync(data); @@ -171,13 +181,14 @@ function entitlements (file) { } function getIdentifier (path) { - const data = fs.readFileSync(path); - const bin = parseMacho(data); + const rawData = fs.readFileSync(path); + const [bin, data] = parseMachoAndGetData(rawData); for (const cmd of bin.cmds) { if (cmd.type === 'code_signature') { return parseIdentifier(data.slice(cmd.dataoff)); } } + return null; function parseIdentifier (data) { const count = data.readUInt32BE(8);