text: #!/usr/bin/env python
  import os
  import sys
  import hashlib
  try:
  	import pathlib
  except:
  	print("Please install pathlib: 'pip install pathlib'")
  	exit(1)
  
  PRIVATE_FRAMEWORKS_PATH = "/System/Library/PrivateFrameworks/"
  TARGET_FRAMEWORK = "MobileDevice.framework/MobileDevice"
  TARGET = PRIVATE_FRAMEWORKS_PATH + TARGET_FRAMEWORK
  
  FIND_START = "-----BEGIN RSA PUBLIC KEY-----"
  FIND_END = "-----END RSA PUBLIC KEY-----"
  
  def getSize(filename):
      st = os.stat(filename)
      return st.st_size
  
  def FindPublicKeyStart(HAYSTACK, HAYBORDER):
  	magic = str("")
  	while magic != FIND_START:
  		current = HAYSTACK.tell()
  		if current == HAYBORDER:
  			return -1
  	        magic = HAYSTACK.read(len(FIND_START))
  		HAYSTACK.seek(current+1)
  	return HAYSTACK.tell()
  
  def FindPublicKeyEnd(HAYSTACK, HAYBORDER):
          magic = str("")
          while magic != FIND_END:
                  current = HAYSTACK.tell()
                  if current == HAYBORDER:
                          return -1
                  magic = HAYSTACK.read(len(FIND_END))
                  HAYSTACK.seek(current+1)
  	return HAYSTACK.tell()
  
  if __name__ == "__main__":
      
      argc = len(sys.argv)
      if argc > 1:
          TARGET = sys.argv[1]
      
      with open(TARGET, "rb") as HAYSTACK:
          HAYBORDER = int(getSize(TARGET))
          print("Got file with size %d" % HAYBORDER)
          found = False
          keyStart = 0
          keyData = None
          while keyStart != -1:
              keyStart = FindPublicKeyStart(HAYSTACK, HAYBORDER)
              if keyStart != -1:
                  print("Found RSA Public Key at %#x" % keyStart)
              else:
                  print("No public key found anymore.")
                  break
              keyEnd = FindPublicKeyEnd(HAYSTACK, HAYBORDER)
              if keyEnd != -1:
                  keyLen = int(keyEnd) - int(keyStart) + len(FIND_END)
                  print("Got end of the key. Length: %d bytes" % int(keyLen))
                  HAYSTACK.seek(keyStart)
                  keyData = HAYSTACK.read(keyLen)
                  HAYSTACK.seek(keyEnd)
              else:
                  print("Could not find the end of the RSA public key, skipping...")
                  HAYSTACK.seek(keyStart+1)
  
              if keyData != None and keyLen != -1 and keyStart != -1:
                  keyHash = hex(keyStart)+"-"+str(keyLen)+"-"+hashlib.sha256(keyData.encode()).hexdigest()
                  keyFile = os.getcwd()+"/"+str(keyHash)+".pub"
                  if pathlib.Path(keyFile).exists():
                      print("This key has already been dumped to %s, skipping...\n" % keyFile)
                      continue
                  with open(keyFile, "wb+") as keyOut:
                      keyOut.write(keyData)
                      keyHash = None
                      keyOut.close()
                      print("Wrote the RSA Public key to %s." % keyFile)
                      keyFile = None
                  keyData = None
  