authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-16 18:39:31+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-16 13:37:07-08:00
logcd4b54fd38ff3ea3e494e330e9487069ef6762da
treeea0d672430089ba871af7e81d1e7edf2c487b7d6
parent36c869dc142d3e5466ad0d975419224ff9579f49

libstd: add more MachO consts and structs


1 files changed, 191 insertions(+), 1 deletions(-)

lib/std/macho.zig+191-1
...@@ -29,6 +29,8 @@ pub const load_command = extern struct {...@@ -29,6 +29,8 @@ pub const load_command = extern struct {
29 cmdsize: u32,29 cmdsize: u32,
30};30};
3131
32/// The uuid load command contains a single 128-bit unique random number that
33/// identifies an object produced by the static link editor.
32pub const uuid_command = extern struct {34pub const uuid_command = extern struct {
33 /// LC_UUID35 /// LC_UUID
34 cmd: u32,36 cmd: u32,
...@@ -40,11 +42,41 @@ pub const uuid_command = extern struct {...@@ -40,11 +42,41 @@ pub const uuid_command = extern struct {
40 uuid: [16]u8,42 uuid: [16]u8,
41};43};
4244
45
46/// The version_min_command contains the min OS version on which this
47/// binary was built to run.
48pub 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.
64pub 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/// The entry_point_command is a replacement for thread_command.75/// The entry_point_command is a replacement for thread_command.
44/// It is used for main executables to specify the location (file offset)76/// It is used for main executables to specify the location (file offset)
45/// of main(). If -stack_size was used at link time, the stacksize77/// of main(). If -stack_size was used at link time, the stacksize
46/// field will contain the stack size needed for the main thread.78/// field will contain the stack size needed for the main thread.
47pub const entry_point_command = struct {79pub const entry_point_command = extern struct {
48 /// LC_MAIN only used in MH_EXECUTE filetypes80 /// LC_MAIN only used in MH_EXECUTE filetypes
49 cmd: u32,81 cmd: u32,
5082
...@@ -1301,3 +1333,161 @@ pub const N_WEAK_DEF: u16 = 0x80;...@@ -1301,3 +1333,161 @@ pub const N_WEAK_DEF: u16 = 0x80;
1301/// be called to get the address of the real function to use.1333/// be called to get the address of the real function to use.
1302/// This bit is only available in .o files (MH_OBJECT filetype)1334/// This bit is only available in .o files (MH_OBJECT filetype)
1303pub const N_SYMBOL_RESOLVER: u16 = 0x100;1335pub 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
1341pub const CSMAGIC_REQUIREMENT: u32 = 0xfade0c00;
1342/// Requirements vector (internal requirements)
1343pub const CSMAGIC_REQUIREMENTS: u32 = 0xfade0c01;
1344/// CodeDirectory blob
1345pub const CSMAGIC_CODEDIRECTORY: u32 = 0xfade0c02;
1346/// embedded form of signature data
1347pub const CSMAGIC_EMBEDDED_SIGNATURE: u32 = 0xfade0cc0;
1348/// XXX
1349pub const CSMAGIC_EMBEDDED_SIGNATURE_OLD: u32 = 0xfade0b02;
1350/// Embedded entitlements
1351pub const CSMAGIC_EMBEDDED_ENTITLEMENTS: u32 = 0xfade7171;
1352/// Multi-arch collection of embedded signatures
1353pub const CSMAGIC_DETACHED_SIGNATURE: u32 = 0xfade0cc1;
1354/// CMS Signature, among other things
1355pub const CSMAGIC_BLOBWRAPPER: u32 = 0xfade0b01;
1356
1357pub const CS_SUPPORTSSCATTER: u32 = 0x20100;
1358pub const CS_SUPPORTSTEAMID: u32 = 0x20200;
1359pub const CS_SUPPORTSCODELIMIT64: u32 = 0x20300;
1360pub const CS_SUPPORTSEXECSEG: u32 = 0x20400;
1361
1362/// Slot index for CodeDirectory
1363pub const CSSLOT_CODEDIRECTORY: u32 = 0;
1364pub const CSSLOT_INFOSLOT: u32 = 1;
1365pub const CSSLOT_REQUIREMENTS: u32 = 2;
1366pub const CSSLOT_RESOURCEDIR: u32 = 3;
1367pub const CSSLOT_APPLICATION: u32 = 4;
1368pub const CSSLOT_ENTITLEMENTS: u32 = 5;
1369
1370/// first alternate CodeDirectory, if any
1371pub const CSSLOT_ALTERNATE_CODEDIRECTORIES: u32 = 0x1000;
1372/// Max number of alternate CD slots
1373pub const CSSLOT_ALTERNATE_CODEDIRECTORY_MAX: u32 = 5;
1374/// One past the last
1375pub const CSSLOT_ALTERNATE_CODEDIRECTORY_LIMIT: u32 = CSSLOT_ALTERNATE_CODEDIRECTORIES + CSSLOT_ALTERNATE_CODEDIRECTORY_MAX;
1376
1377/// CMS Signature
1378pub const CSSLOT_SIGNATURESLOT: u32 = 0x10000;
1379pub const CSSLOT_IDENTIFICATIONSLOT: u32 = 0x10001;
1380pub const CSSLOT_TICKETSLOT: u32 = 0x10002;
1381
1382/// Compat with amfi
1383pub const CSTYPE_INDEX_REQUIREMENTS: u32 = 0x00000002;
1384/// Compat with amfi
1385pub const CSTYPE_INDEX_ENTITLEMENTS: u32 = 0x00000005;
1386
1387pub const CS_HASHTYPE_SHA1: u32 = 1;
1388pub const CS_HASHTYPE_SHA256: u32 = 2;
1389pub const CS_HASHTYPE_SHA256_TRUNCATED: u32 = 3;
1390pub const CS_HASHTYPE_SHA384: u32 = 4;
1391
1392pub const CS_SHA1_LEN: u32 = 20;
1393pub const CS_SHA256_LEN: u32 = 32;
1394pub const CS_SHA256_TRUNCATED_LEN: u32 = 20;
1395
1396/// Always - larger hashes are truncated
1397pub const CS_CDHASH_LEN: u32 = 20;
1398/// Max size of the hash we'll support
1399pub const CS_HASH_MAX_SIZE: u32 = 48;
1400
1401pub const CS_SIGNER_TYPE_UNKNOWN: u32 = 0;
1402pub const CS_SIGNER_TYPE_LEGACYVPN: u32 = 5;
1403pub const CS_SIGNER_TYPE_MAC_APP_STORE: u32 = 6;
1404
1405/// This CodeDirectory is tailored specfically at version 0x20400.
1406pub 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
1462pub 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
1472pub 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
1485pub 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};