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);