INNER CODE UNIT · Python
strip
stablyai/agent-slack · scripts/strip-macho-signature.py:15
def strip(path: str) -> bool:
with open(path, "rb") as f:
data = bytearray(f.read())
if struct.unpack_from("<I", data, 0)[0] != MH_MAGIC_64:
return False
ncmds, sizeofcmds = struct.unpack_from("<II", data, 16)
hdr_size = 32 # sizeof(mach_header_64)
# First pass: find LC_CODE_SIGNATURE and __LINKEDIT offsets.
offset = hdr_size
sig_dataoff = None
sig_datasize = 0
sig_cmdsize = 0
linkedit_offset = None # offset of __LINKEDIT load command in file
for _ in range(ncmds):