| ... | ... | @@ -29,6 +29,8 @@ pub const load_command = extern struct { |
| 29 | 29 | cmdsize: u32, |
| 30 | 30 | }; |
| 31 | 31 | |
| 32 | /// The uuid load command contains a single 128-bit unique random number that |
| 33 | /// identifies an object produced by the static link editor. |
| 32 | 34 | pub const uuid_command = extern struct { |
| 33 | 35 | /// LC_UUID |
| 34 | 36 | cmd: u32, |
| ... | ... | @@ -40,11 +42,41 @@ pub const uuid_command = extern struct { |
| 40 | 42 | uuid: [16]u8, |
| 41 | 43 | }; |
| 42 | 44 | |
| 45 | |
| 46 | /// The version_min_command contains the min OS version on which this |
| 47 | /// binary was built to run. |
| 48 | pub const version_min_command = extern struct { |
| 49 | /// LC_VERSION_MIN_MACOSX or LC_VERSION_MIN_IPHONEOS or LC_VERSION_MIN_WATCHOS or LC_VERSION_MIN_TVOS |
| 50 | cmd: u32, |
| 51 | |
| 52 | /// sizeof(struct version_min_command) |
| 53 | cmdsize: u32, |
| 54 | |
| 55 | /// X.Y.Z is encoded in nibbles xxxx.yy.zz |
| 56 | version: u32, |
| 57 | |
| 58 | /// X.Y.Z is encoded in nibbles xxxx.yy.zz |
| 59 | sdk: u32, |
| 60 | }; |
| 61 | |
| 62 | /// The source_version_command is an optional load command containing |
| 63 | /// the version of the sources used to build the binary. |
| 64 | pub const source_version_command = extern struct { |
| 65 | /// LC_SOURCE_VERSION |
| 66 | cmd: u32, |
| 67 | |
| 68 | /// sizeof(source_version_command) |
| 69 | cmdsize: u32, |
| 70 | |
| 71 | /// A.B.C.D.E packed as a24.b10.c10.d10.e10 |
| 72 | version: u64, |
| 73 | }; |
| 74 | |
| 43 | 75 | /// The entry_point_command is a replacement for thread_command. |
| 44 | 76 | /// It is used for main executables to specify the location (file offset) |
| 45 | 77 | /// of main(). If -stack_size was used at link time, the stacksize |
| 46 | 78 | /// field will contain the stack size needed for the main thread. |
| 47 | | pub const entry_point_command = struct { |
| 79 | pub const entry_point_command = extern struct { |
| 48 | 80 | /// LC_MAIN only used in MH_EXECUTE filetypes |
| 49 | 81 | cmd: u32, |
| 50 | 82 | |
| ... | ... | @@ -1301,3 +1333,161 @@ pub const N_WEAK_DEF: u16 = 0x80; |
| 1301 | 1333 | /// be called to get the address of the real function to use. |
| 1302 | 1334 | /// This bit is only available in .o files (MH_OBJECT filetype) |
| 1303 | 1335 | pub const N_SYMBOL_RESOLVER: u16 = 0x100; |
| 1336 | |
| 1337 | // Codesign consts and structs taken from: |
| 1338 | // https://opensource.apple.com/source/xnu/xnu-6153.81.5/osfmk/kern/cs_blobs.h.auto.html |
| 1339 | |
| 1340 | /// Single Requirement blob |
| 1341 | pub const CSMAGIC_REQUIREMENT: u32 = 0xfade0c00; |
| 1342 | /// Requirements vector (internal requirements) |
| 1343 | pub const CSMAGIC_REQUIREMENTS: u32 = 0xfade0c01; |
| 1344 | /// CodeDirectory blob |
| 1345 | pub const CSMAGIC_CODEDIRECTORY: u32 = 0xfade0c02; |
| 1346 | /// embedded form of signature data |
| 1347 | pub const CSMAGIC_EMBEDDED_SIGNATURE: u32 = 0xfade0cc0; |
| 1348 | /// XXX |
| 1349 | pub const CSMAGIC_EMBEDDED_SIGNATURE_OLD: u32 = 0xfade0b02; |
| 1350 | /// Embedded entitlements |
| 1351 | pub const CSMAGIC_EMBEDDED_ENTITLEMENTS: u32 = 0xfade7171; |
| 1352 | /// Multi-arch collection of embedded signatures |
| 1353 | pub const CSMAGIC_DETACHED_SIGNATURE: u32 = 0xfade0cc1; |
| 1354 | /// CMS Signature, among other things |
| 1355 | pub const CSMAGIC_BLOBWRAPPER: u32 = 0xfade0b01; |
| 1356 | |
| 1357 | pub const CS_SUPPORTSSCATTER: u32 = 0x20100; |
| 1358 | pub const CS_SUPPORTSTEAMID: u32 = 0x20200; |
| 1359 | pub const CS_SUPPORTSCODELIMIT64: u32 = 0x20300; |
| 1360 | pub const CS_SUPPORTSEXECSEG: u32 = 0x20400; |
| 1361 | |
| 1362 | /// Slot index for CodeDirectory |
| 1363 | pub const CSSLOT_CODEDIRECTORY: u32 = 0; |
| 1364 | pub const CSSLOT_INFOSLOT: u32 = 1; |
| 1365 | pub const CSSLOT_REQUIREMENTS: u32 = 2; |
| 1366 | pub const CSSLOT_RESOURCEDIR: u32 = 3; |
| 1367 | pub const CSSLOT_APPLICATION: u32 = 4; |
| 1368 | pub const CSSLOT_ENTITLEMENTS: u32 = 5; |
| 1369 | |
| 1370 | /// first alternate CodeDirectory, if any |
| 1371 | pub const CSSLOT_ALTERNATE_CODEDIRECTORIES: u32 = 0x1000; |
| 1372 | /// Max number of alternate CD slots |
| 1373 | pub const CSSLOT_ALTERNATE_CODEDIRECTORY_MAX: u32 = 5; |
| 1374 | /// One past the last |
| 1375 | pub const CSSLOT_ALTERNATE_CODEDIRECTORY_LIMIT: u32 = CSSLOT_ALTERNATE_CODEDIRECTORIES + CSSLOT_ALTERNATE_CODEDIRECTORY_MAX; |
| 1376 | |
| 1377 | /// CMS Signature |
| 1378 | pub const CSSLOT_SIGNATURESLOT: u32 = 0x10000; |
| 1379 | pub const CSSLOT_IDENTIFICATIONSLOT: u32 = 0x10001; |
| 1380 | pub const CSSLOT_TICKETSLOT: u32 = 0x10002; |
| 1381 | |
| 1382 | /// Compat with amfi |
| 1383 | pub const CSTYPE_INDEX_REQUIREMENTS: u32 = 0x00000002; |
| 1384 | /// Compat with amfi |
| 1385 | pub const CSTYPE_INDEX_ENTITLEMENTS: u32 = 0x00000005; |
| 1386 | |
| 1387 | pub const CS_HASHTYPE_SHA1: u32 = 1; |
| 1388 | pub const CS_HASHTYPE_SHA256: u32 = 2; |
| 1389 | pub const CS_HASHTYPE_SHA256_TRUNCATED: u32 = 3; |
| 1390 | pub const CS_HASHTYPE_SHA384: u32 = 4; |
| 1391 | |
| 1392 | pub const CS_SHA1_LEN: u32 = 20; |
| 1393 | pub const CS_SHA256_LEN: u32 = 32; |
| 1394 | pub const CS_SHA256_TRUNCATED_LEN: u32 = 20; |
| 1395 | |
| 1396 | /// Always - larger hashes are truncated |
| 1397 | pub const CS_CDHASH_LEN: u32 = 20; |
| 1398 | /// Max size of the hash we'll support |
| 1399 | pub const CS_HASH_MAX_SIZE: u32 = 48; |
| 1400 | |
| 1401 | pub const CS_SIGNER_TYPE_UNKNOWN: u32 = 0; |
| 1402 | pub const CS_SIGNER_TYPE_LEGACYVPN: u32 = 5; |
| 1403 | pub const CS_SIGNER_TYPE_MAC_APP_STORE: u32 = 6; |
| 1404 | |
| 1405 | /// This CodeDirectory is tailored specfically at version 0x20400. |
| 1406 | pub const CodeDirectory = extern struct { |
| 1407 | /// Magic number (CSMAGIC_CODEDIRECTORY) |
| 1408 | magic: u32, |
| 1409 | |
| 1410 | /// Total length of CodeDirectory blob |
| 1411 | length: u32, |
| 1412 | |
| 1413 | /// Compatibility version |
| 1414 | version: u32, |
| 1415 | |
| 1416 | /// Setup and mode flags |
| 1417 | flags: u32, |
| 1418 | |
| 1419 | /// Offset of hash slot element at index zero |
| 1420 | hashOffset: u32, |
| 1421 | |
| 1422 | /// Offset of identifier string |
| 1423 | identOffset: u32, |
| 1424 | |
| 1425 | /// Number of special hash slots |
| 1426 | nSpecialSlots: u32, |
| 1427 | |
| 1428 | /// Number of ordinary (code) hash slots |
| 1429 | nCodeSlots: u32, |
| 1430 | |
| 1431 | /// Limit to main image signature range |
| 1432 | codeLimit: u32, |
| 1433 | |
| 1434 | /// Size of each hash in bytes |
| 1435 | hashSize: u8, |
| 1436 | |
| 1437 | /// Type of hash (cdHashType* constants) |
| 1438 | hashType: u8, |
| 1439 | |
| 1440 | /// Platform identifier; zero if not platform binary |
| 1441 | platform: u8, |
| 1442 | |
| 1443 | /// log2(page size in bytes); 0 => infinite |
| 1444 | pageSize: u8, |
| 1445 | |
| 1446 | /// Unused (must be zero) |
| 1447 | spare2: u32, |
| 1448 | |
| 1449 | /// Offset of executable segment |
| 1450 | execSegBase: u64, |
| 1451 | |
| 1452 | /// Limit of executable segment |
| 1453 | execSegLimit: u64, |
| 1454 | |
| 1455 | /// Executable segment flags |
| 1456 | execSegFlags, |
| 1457 | |
| 1458 | // end_withExecSeg: [*]u8, |
| 1459 | }; |
| 1460 | |
| 1461 | /// Structure of an embedded-signature SuperBlob |
| 1462 | pub const BlobIndex = extern struct { |
| 1463 | /// Type of entry |
| 1464 | @"type": u32, |
| 1465 | |
| 1466 | /// Offset of entry |
| 1467 | offset: u32, |
| 1468 | }; |
| 1469 | |
| 1470 | /// This structure is followed by GenericBlobs in no particular |
| 1471 | /// order as indicated by offsets in index |
| 1472 | pub const SuperBlob = extern struct { |
| 1473 | /// Magic number |
| 1474 | magic: u32, |
| 1475 | |
| 1476 | /// Total length of SuperBlob |
| 1477 | length: u32, |
| 1478 | |
| 1479 | /// Number of index BlobIndex entries following this struct |
| 1480 | count: u32, |
| 1481 | |
| 1482 | // index: []const BlobIndex, |
| 1483 | }; |
| 1484 | |
| 1485 | pub const GenericBlob = extern struct { |
| 1486 | /// Magic number |
| 1487 | magic: u32, |
| 1488 | |
| 1489 | /// Total length of blob |
| 1490 | length: u32, |
| 1491 | |
| 1492 | // data: []const u8, |
| 1493 | }; |