def fix_exe_for_code_signing(filename):
 exe_data = MachO(filename)
 cmds = exe_data.headers[0].commands
 file_size = exe_data.headers[0].size
 for c in cmds:
  if (c[0].get_cmd_name() == 'LC_SYMTAB'):
   data = c[1]
   new_strsize = (file_size - data.stroff)
   data.strsize = new_strsize
 linkedit = cmds[3][1]
 new_segsize = (file_size - linkedit.fileoff)
 linkedit.filesize = new_segsize
 linkedit.vmsize = new_segsize
 fp = open(exe_data.filename, 'rb+')
 exe_data.write(fp)
 fp.close()

def fix_exe_for_code_signing ( filename ) : exe_data = MachO ( filename ) cmds = exe_data . headers [ 0 ] . commands file_size = exe_data . headers [ 0 ] . size for c in cmds : if ( c [ 0 ] . get_cmd_name ( ) == 'LC_SYMTAB' ) : data = c [ 1 ] new_strsize = ( file_size - data . stroff ) data . strsize = new_strsize linkedit = cmds [ 3 ] [ 1 ] new_segsize = ( file_size - linkedit . fileoff ) linkedit . filesize = new_segsize linkedit . vmsize = new_segsize fp = open ( exe_data . filename , 'rb+' ) exe_data . write ( fp ) fp . close ( )
fixes the mach-o headers to make code signing possible .