Skip to content

Commit d2859ca

Browse files
radaretrufae
authored andcommitted
Only resign macho files that can be processed by ldid2
1 parent 76570bf commit d2859ca

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/bin.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,31 @@ const macho = require('macho');
66
const fs = require('fs');
77

88
const MACH0_MIN_SIZE = 1024 * 4;
9+
const MH_EXECUTE = 2;
10+
const MH_DYLIB = 6;
11+
const MH_BUNDLE = 8;
912

1013
function isMacho (data) {
1114
if (typeof data === 'string') {
1215
if (!fs.lstatSync(data).isFile()) {
1316
return false;
1417
}
1518
const fd = fs.openSync(data, 'r');
16-
data = Buffer.alloc(4);
17-
if (fs.readSync(fd, data, 0, 4) !== 4) {
19+
data = Buffer.alloc(32);
20+
if (fs.readSync(fd, data, 0, 32) !== 32) {
1821
return false;
1922
}
2023
fs.close(fd);
2124
}
25+
const fileType = data[15];
26+
switch (fileType) {
27+
case MH_EXECUTE:
28+
case MH_DYLIB:
29+
case MH_BUNDLE:
30+
break;
31+
default:
32+
return false;
33+
}
2234
const magics = [
2335
[0xca, 0xfe, 0xba, 0xbe], // fat
2436
[0xce, 0xfa, 0xed, 0xfe], // 32bit

0 commit comments

Comments
 (0)