| ... | @@ -69,11 +69,12 @@ pub fn calcAdhocSignature(self: *CodeSignature, bin_file: *const MachO) !void { | ... | @@ -69,11 +69,12 @@ pub fn calcAdhocSignature(self: *CodeSignature, bin_file: *const MachO) !void { |
| 69 | const text_segment = bin_file.load_commands.items[bin_file.text_segment_cmd_index.?].Segment; | 69 | const text_segment = bin_file.load_commands.items[bin_file.text_segment_cmd_index.?].Segment; |
| 70 | const data_segment = bin_file.load_commands.items[bin_file.data_segment_cmd_index.?].Segment; | 70 | const data_segment = bin_file.load_commands.items[bin_file.data_segment_cmd_index.?].Segment; |
| 71 | const linkedit_segment = bin_file.load_commands.items[bin_file.linkedit_segment_cmd_index.?].Segment; | 71 | const linkedit_segment = bin_file.load_commands.items[bin_file.linkedit_segment_cmd_index.?].Segment; |
| 72 | const symtab = bin_file.load_commands.items[bin_file.symtab_cmd_index.?].Symtab; | 72 | const code_sig_cmd = bin_file.load_commands.items[bin_file.code_signature_cmd_index.?].LinkeditData; |
| 73 | | 73 | |
| 74 | const execSegBase: u64 = text_segment.fileoff; | 74 | const execSegBase: u64 = text_segment.fileoff; |
| 75 | const execSegLimit: u64 = text_segment.filesize; | 75 | const execSegLimit: u64 = text_segment.filesize; |
| 76 | const execSegFlags: u64 = if (bin_file.base.options.output_mode == .Exe) macho.CS_EXECSEG_MAIN_BINARY else 0; | 76 | const execSegFlags: u64 = if (bin_file.base.options.output_mode == .Exe) macho.CS_EXECSEG_MAIN_BINARY else 0; |
| | 77 | const file_size = code_sig_cmd.dataoff; |
| 77 | var cdir = CodeDirectory{ | 78 | var cdir = CodeDirectory{ |
| 78 | .inner = .{ | 79 | .inner = .{ |
| 79 | .magic = macho.CSMAGIC_CODEDIRECTORY, | 80 | .magic = macho.CSMAGIC_CODEDIRECTORY, |
| ... | @@ -84,7 +85,7 @@ pub fn calcAdhocSignature(self: *CodeSignature, bin_file: *const MachO) !void { | ... | @@ -84,7 +85,7 @@ pub fn calcAdhocSignature(self: *CodeSignature, bin_file: *const MachO) !void { |
| 84 | .identOffset = 0, | 85 | .identOffset = 0, |
| 85 | .nSpecialSlots = 0, | 86 | .nSpecialSlots = 0, |
| 86 | .nCodeSlots = 0, | 87 | .nCodeSlots = 0, |
| 87 | .codeLimit = 0, | 88 | .codeLimit = @intCast(u32, file_size), |
| 88 | .hashSize = hash_size, | 89 | .hashSize = hash_size, |
| 89 | .hashType = macho.CS_HASHTYPE_SHA256, | 90 | .hashType = macho.CS_HASHTYPE_SHA256, |
| 90 | .platform = 0, | 91 | .platform = 0, |
| ... | @@ -100,7 +101,6 @@ pub fn calcAdhocSignature(self: *CodeSignature, bin_file: *const MachO) !void { | ... | @@ -100,7 +101,6 @@ pub fn calcAdhocSignature(self: *CodeSignature, bin_file: *const MachO) !void { |
| 100 | }, | 101 | }, |
| 101 | }; | 102 | }; |
| 102 | | 103 | |
| 103 | const file_size = symtab.stroff + symtab.strsize; | | |
| 104 | const total_pages = mem.alignForward(file_size, page_size) / page_size; | 104 | const total_pages = mem.alignForward(file_size, page_size) / page_size; |
| 105 | log.debug("Total file size: {}; total number of pages: {}\n", .{ file_size, total_pages }); | 105 | log.debug("Total file size: {}; total number of pages: {}\n", .{ file_size, total_pages }); |
| 106 | | 106 | |