Skip to content

Commit

Permalink
Fix codesign identifier parsing on fat bins
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmacete authored and trufae committed Nov 7, 2023
1 parent 022548f commit 70be75a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 70be75a

Please sign in to comment.