authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-20 11:50:44+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-26 11:50:09+01:00
log9dcf7ee9c904b25fbffd264cabeb6638e9d9e2d6
treeb15b3c0bcc0708e44e8009b15a4c0dc72f723a6a
parent79381dc4fb1f7eb92b5e01d21f866f550ca3ff20

stage2 macho: add info about __TEXT segment


3 files changed, 17 insertions(+), 11 deletions(-)

lib/std/macho.zig+4-4
......@@ -1402,6 +1402,10 @@ pub const CS_SIGNER_TYPE_UNKNOWN: u32 = 0;
14021402pub const CS_SIGNER_TYPE_LEGACYVPN: u32 = 5;
14031403pub const CS_SIGNER_TYPE_MAC_APP_STORE: u32 = 6;
14041404
1405pub const CS_ADHOC: u32 = 0x2;
1406
1407pub const CS_EXECSEG_MAIN_BINARY: u32 = 0x1;
1408
14051409/// This CodeDirectory is tailored specfically at version 0x20400.
14061410pub const CodeDirectory = extern struct {
14071411 /// Magic number (CSMAGIC_CODEDIRECTORY)
......@@ -1488,8 +1492,6 @@ pub const SuperBlob = extern struct {
14881492
14891493 /// Number of index BlobIndex entries following this struct
14901494 count: u32,
1491
1492 // index: []const BlobIndex,
14931495};
14941496
14951497pub const GenericBlob = extern struct {
......@@ -1498,6 +1500,4 @@ pub const GenericBlob = extern struct {
14981500
14991501 /// Total length of blob
15001502 length: u32,
1501
1502 // data: []const u8,
15031503};
src/link/MachO.zig+1-1
......@@ -1758,7 +1758,7 @@ fn writecodeSignature(self: *MachO) !void {
17581758 var code_sig = CodeSignature.init(self.base.allocator);
17591759 defer code_sig.deinit();
17601760
1761 try code_sig.calcAdhocSignature();
1761 try code_sig.calcAdhocSignature(self);
17621762
17631763 var buffer = try self.base.allocator.alloc(u8, code_sig.size());
17641764 defer self.base.allocator.free(buffer);
src/link/MachO/CodeSignature.zig+12-6
......@@ -8,6 +8,8 @@ const mem = std.mem;
88const testing = std.testing;
99const Allocator = mem.Allocator;
1010
11const MachO = @import("../MachO.zig");
12
1113const Blob = struct {
1214 inner: macho.CodeDirectory,
1315 data: std.ArrayListUnmanaged(u8) = .{},
......@@ -56,13 +58,17 @@ pub fn init(alloc: *Allocator) CodeSignature {
5658 };
5759}
5860
59pub fn calcAdhocSignature(self: *CodeSignature) !void {
61pub fn calcAdhocSignature(self: *CodeSignature, bin_file: *const MachO) !void {
62 const text_segment = bin_file.load_commands.items[bin_file.text_segment_cmd_index.?].Segment;
63 const execSegBase: u64 = text_segment.fileoff;
64 const execSegLimit: u64 = text_segment.filesize;
65 const execSegFlags: u64 = text_segment.flags;
6066 var blob = Blob{
6167 .inner = .{
6268 .magic = macho.CSMAGIC_CODEDIRECTORY,
6369 .length = @sizeOf(macho.CodeDirectory),
64 .version = 0x20400,
65 .flags = 0,
70 .version = macho.CS_SUPPORTSEXECSEG,
71 .flags = macho.CS_ADHOC,
6672 .hashOffset = 0,
6773 .identOffset = 0,
6874 .nSpecialSlots = 0,
......@@ -77,9 +83,9 @@ pub fn calcAdhocSignature(self: *CodeSignature) !void {
7783 .teamOffset = 0,
7884 .spare3 = 0,
7985 .codeLimit64 = 0,
80 .execSegBase = 0,
81 .execSegLimit = 0,
82 .execSegFlags = 0,
86 .execSegBase = execSegBase,
87 .execSegLimit = execSegLimit,
88 .execSegFlags = execSegFlags,
8389 },
8490 };
8591 self.inner.length += @sizeOf(macho.BlobIndex) + blob.size();