def __init__(self, lockdown = None,backupPath = None):
        if lockdown:
            self.lockdown = lockdown
        else:
            self.lockdown = LockdownClient()
        try:
            self.udid = lockdown.getValue("", "UniqueDeviceID")#lockdown.udid
        except:
            self.lockdown = LockdownClient()
            self.udid = self.lockdown.getValue("", "UniqueDeviceID")
        self.service = self.lockdown.startService("com.apple.mobilebackup2")
        if not self.service:
            raise Exception("MobileBackup2Client init error : Could not start com.apple.mobilebackup2")
        if backupPath:
            self.backupPath = backupPath
        else:
            self.backupPath = "backups" #self.udid
        if not os.path.isdir(self.backupPath):
            os.makedirs(self.backupPath,0o0755)

        print "Starting new com.apple.mobilebackup2 service with working dir: %s" %  self.backupPath
        self.password = ""
        DLMessageVersionExchange = self.service.recvPlist()
        #print DLMessageVersionExchange
        version_major = DLMessageVersionExchange[1]
        self.service.sendPlist(["DLMessageVersionExchange", "DLVersionsOk", version_major])
        DLMessageDeviceReady = self.service.recvPlist()
        #print DLMessageDeviceReady
        if DLMessageDeviceReady and DLMessageDeviceReady[0] == "DLMessageDeviceReady":
            #print "Got DLMessageDeviceReady"
            self.version_exchange()
        else:
            raise Exception("MobileBackup2Client init error %s" % DLMessageDeviceReady)
 def file_write(self, handle, data):
     MAXIMUM_WRITE_SIZE = 1 << 15
     hh = struct.pack("<Q", handle)
     segments = len(data) / MAXIMUM_WRITE_SIZE
     try:
         for i in xrange(segments):
             self.dispatch_packet(
                 AFC_OP_WRITE,
                 hh +
                 data[i * MAXIMUM_WRITE_SIZE:(i + 1) * MAXIMUM_WRITE_SIZE],
                 this_length=48)
             s, d = self.receive_data()
             if s != AFC_E_SUCCESS:
                 print "file_write error %d" % s
                 break
         if len(data) % MAXIMUM_WRITE_SIZE:
             self.dispatch_packet(AFC_OP_WRITE,
                                  hh + data[segments * MAXIMUM_WRITE_SIZE:],
                                  this_length=48)
             s, d = self.receive_data()
             #print s,d
     except:
         self.lockdown = LockdownClient()
         self.service = lockdown.startService(serviceName)
         self.file_write(handle, data)
     return s
def main():
    parser = OptionParser(usage="%prog")
    parser.add_option("-l",
                      "--list",
                      dest="list",
                      action="store_true",
                      default=False,
                      help="List installed profiles")
    parser.add_option("-i",
                      "--install",
                      dest="install",
                      action="store",
                      metavar="FILE",
                      help="Install profile")
    parser.add_option("-r",
                      "--remove",
                      dest="remove",
                      action="store",
                      metavar="IDENTIFIER",
                      help="Remove profile")
    (options, args) = parser.parse_args()

    if not options.list and not options.install and not options.remove:
        parser.print_help()
        return
    lockdown = LockdownClient()
    mc = MobileConfigService(lockdown)

    if options.list:
        pprint(mc.GetProfileList())
    elif options.install:
        mc.InstallProfile(read_file(options.install))
    elif options.remove:
        pprint(mc.RemoveProfile(options.remove))
 def __init__(self, lockdown=None):
     if lockdown:
         self.lockdown = lockdown
     else:
         self.lockdown = LockdownClient()
     self.service = self.lockdown.startService(
         "com.apple.springboardservices")
Example #5
0
 def __init__(self, lockdown=None):
     if lockdown:
         self.lockdown = lockdown
     else:
         self.lockdown = LockdownClient()
     self.c = self.lockdown.startService("com.apple.syslog_relay")
     self.c.send("watch")
Example #6
0
    def __init__(self, lockdown=None, serviceName='com.apple.afc', service=None):
        """
        Constructor method of `AFCClient`.

        Note:
            `serviceName` is obsolete when `service` parameter is used.
            Although it will be saved as attribute.

        Args:
            `lockdown` (optional): The `LockdownClient` class that should be used for almost everything.
            `serviceName` (optional): Service ID of the protocol, defaults to 'com.apple.afc'.
                Used for abstract class purposes although you can modify if you have good reasons.
            `service` (optional): Useful when you already have a service running.
        """
        if lockdown:
            self.lockdown = lockdown
        else:
            self.lockdown = LockdownClient()

        if service:
            self.service = service
        else:
            self.service = self.lockdown.startService(serviceName)
        self.serviceName = serviceName
        self.packet_num = 0
Example #7
0
 def __init__(self,
              lockdown=None,
              serviceName="com.apple.mobile.house_arrest",
              service=None):
     self.serviceName = serviceName
     self.lockdown = lockdown if lockdown else LockdownClient()
     self.service = service if service else self.lockdown.startService(
         self.serviceName)
Example #8
0
 def __init__(self,
              lockdown=None,
              serviceName="com.apple.mobile.notification_proxy"):
     if lockdown:
         self.lockdown = lockdown
     else:
         self.lockdown = LockdownClient()
     self.service = self.lockdown.startService(serviceName)
 def do_operation(self, opcode, data=""):
     try:
         self.dispatch_packet(opcode, data)
         return self.receive_data()
     except:
         self.lockdown = LockdownClient()
         self.service = lockdown.startService(serviceName)
         return self.do_operation(opcode, data)
Example #10
0
    def __init__(self, lockdown=None, serviceName="com.apple.mobile.file_relay"):
        if lockdown:
            self.lockdown = lockdown
        else:
            self.lockdown = LockdownClient()

        self.service = self.lockdown.startService(serviceName)
        self.packet_num = 0
Example #11
0
    def __init__(self, lockdown=None):
        if lockdown:
            self.lockdown = lockdown
        else:
            self.lockdown = LockdownClient()

        self.service = self.lockdown.startService(
            'com.apple.mobile.installation_proxy')
Example #12
0
 def __init__(self,
              lockdown=None,
              serviceName="com.apple.afc",
              service=None):
     self.serviceName = serviceName
     self.lockdown = lockdown if lockdown else LockdownClient()
     self.service = service if service else self.lockdown.startService(
         self.serviceName)
     self.packet_num = 0
Example #13
0
    def __init__(self, afcname='com.apple.afc', completekey='tab', stdin=None, stdout=None, client=None):

        Cmd.__init__(self, completekey=completekey, stdin=stdin, stdout=stdout)
        self.lockdown = LockdownClient()
        self.afc = client if client else AFCClient(self.lockdown, serviceName=afcname)

        self.curdir = '/'
        self.prompt = 'AFC$ ' + self.curdir + ' '
        self.complete_cat = self._complete
        self.complete_ls = self._complete
 def __init__(self, completekey='tab', stdin=None, stdout=None, afc=None):
     Cmd.__init__(self, completekey=completekey, stdin=stdin, stdout=stdout)
     self.lockdown = LockdownClient()
     if afc:
         self.afc = afc
     else:
         self.afc = AFCClient(self.lockdown, "com.apple.afc")
     self.prompt = "(AFC) / "
     self.curdir = "/"
     self.complete_cat = self._complete
     self.complete_ls = self._complete
Example #15
0
    def __init__(self, completekey='tab', stdin=None, stdout=None, afc=None):
        super(AFCShell, self).__init__(self, completekey=completekey, stdin=stdin, stdout=stdout)
        if afc:
            self.afc = afc
        else:
            self.lockdown = LockdownClient()
            self.afc = AFCClient(self.lockdown)

        self.prompt = "(AFC) / "
        self.curdir = "/"
        self.complete_cat = self._complete
        self.complete_ls = self._complete
Example #16
0
    def __init__(self, lockdown=None, serviceName="com.apple.mobile.file_relay"):
        if lockdown:
            self.lockdown = lockdown
        else:
            self.lockdown = LockdownClient()

        ProductVersion = self.lockdown.getValue("", "ProductVersion")

        if ProductVersion[0] >= "8":
            raise DeviceVersionNotSupported

        self.service = self.lockdown.startService(serviceName)
        self.packet_num = 0
    def __init__(self, lockdown=None, serviceName='com.apple.mobile.screenshotr'):
        if lockdown:
            self.lockdown = lockdown
        else:
            self.lockdown = LockdownClient()
        #Starting Screenshot service
        self.service = self.lockdown.startService(serviceName)

        #hand check
        DLMessageVersionExchange = self.service.recvPlist()
        #assert len(DLMessageVersionExchange) == 2
        version_major = DLMessageVersionExchange[1]
        self.service.sendPlist(["DLMessageVersionExchange", "DLVersionsOk", version_major ])
        DLMessageDeviceReady = self.service.recvPlist()
Example #18
0
def house_arrest(lockdown, applicationId):
    try:
        mis = lockdown.startService("com.apple.mobile.house_arrest")
    except:
        lockdown = LockdownClient()
        mis = lockdown.startService("com.apple.mobile.house_arrest")

    if mis == None:
        return
    mis.sendPlist({"Command": "VendDocuments", "Identifier": applicationId})
    res = mis.recvPlist()
    if res.get("Error"):
        print "Unable to Lookup the selected application: You probably trying to access to a system app..."
        return None
    return AFCClient(lockdown, service=mis)
Example #19
0
def house_arrest(lockdown, applicationId):
    try:
        mis = lockdown.startService("com.apple.mobile.house_arrest")
    except:
        lockdown = LockdownClient()
        mis = lockdown.startService("com.apple.mobile.house_arrest")

    if mis == None:
        return
    mis.sendPlist({"Command": "VendDocuments", "Identifier": applicationId})
    res = mis.recvPlist()
    error = res.get("Error")
    if error:
        print res["Error"]
        return None
    return AFCClient(lockdown, service=mis)
Example #20
0
    def __init__(self,
                 completekey='tab',
                 stdin=None,
                 stdout=None,
                 client=None):

        Cmd.__init__(self, completekey=completekey, stdin=stdin, stdout=stdout)
        self.lockdown = LockdownClient()
        if client:
            self.afc = client
        else:
            self.afc = AFCClient(self.lockdown, "com.apple.afc")
        self.curdir = "/"
        self.prompt = "AFC$ " + self.curdir + " "
        self.complete_cat = self._complete
        self.complete_ls = self._complete
Example #21
0
    def __init__(self, lockdown=None):
	if lockdown:
            self.lockdown = lockdown
        else:
            self.lockdown = LockdownClient()

	ProductVersion = self.lockdown.getValue("", "ProductVersion")
	if ProductVersion[0] >= "5":
	    raise DeviceVersionNotSupported

        self.service = self.lockdown.startService("com.apple.mobilebackup")
        self.udid = self.lockdown.udid
        DLMessageVersionExchange = self.service.recvPlist()
        version_major = DLMessageVersionExchange[1]
        self.service.sendPlist(["DLMessageVersionExchange", "DLVersionsOk", version_major])
        DLMessageDeviceReady = self.service.recvPlist()
        if DLMessageDeviceReady and DLMessageDeviceReady[0] == "DLMessageDeviceReady":
            print "Got DLMessageDeviceReady"
Example #22
0
    def __init__(self, lockdown=None, backupPath=None):
        if lockdown:
            self.lockdown = lockdown
        else:
            self.lockdown = LockdownClient()

        ProductVersion = self.lockdown.getValue("", "ProductVersion")
        if ProductVersion[0] < "5":
            raise DeviceVersionNotSupported

        self.udid = lockdown.getValue("", "UniqueDeviceID")
        self.willEncrypt = lockdown.getValue("com.apple.mobile.backup",
                                             "WillEncrypt")

        self.service = self.lockdown.startService("com.apple.mobilebackup2")
        if not self.service:
            raise Exception(
                "MobileBackup2 init error : Could not start com.apple.mobilebackup2"
            )

        if backupPath:
            self.backupPath = backupPath
        else:
            self.backupPath = "backups"
        if not os.path.isdir(self.backupPath):
            os.makedirs(self.backupPath, 0o0755)

        print "Starting new com.apple.mobilebackup2 service with working dir: %s" % self.backupPath

        self.password = ""
        DLMessageVersionExchange = self.service.recvPlist()
        version_major = DLMessageVersionExchange[1]
        self.service.sendPlist(
            ["DLMessageVersionExchange", "DLVersionsOk", version_major])
        DLMessageDeviceReady = self.service.recvPlist()
        if DLMessageDeviceReady and DLMessageDeviceReady[
                0] == "DLMessageDeviceReady":
            self.version_exchange()
        else:
            raise Exception("MobileBackup2 init error %s" %
                            DLMessageDeviceReady)
Example #23
0
    def file_read(self, handle, sz):
        MAXIMUM_READ_SIZE = 1 << 16
        data = ""
        while sz > 0:
            if sz > MAXIMUM_READ_SIZE:
                toRead = MAXIMUM_READ_SIZE
            else:
                toRead = sz
            try:
                self.dispatch_packet(AFC_OP_READ, struct.pack("<QQ", handle, toRead))
                s, d = self.receive_data()
            except:
                self.lockdown = LockdownClient()
                self.service = self.lockdown.startService("com.apple.afc")
                return  self.file_read(handle, sz)

            if s != AFC_E_SUCCESS:
                break
            sz -= toRead
            data += d
        return data
Example #24
0

if __name__ == "__main__":
    parser = OptionParser(usage="%prog")
    parser.add_option("-b", "--backup", dest="backup", action="store_true", default=True,
                  help="Backup device")
    parser.add_option("-r", "--restore", dest="restore", action="store_true", default=False,
                  help="Restore device")
    parser.add_option("-i", "--info", dest="info", action="store_true", default=False,
                  help="Show backup info")
    parser.add_option("-l", "--list", dest="list", action="store_true", default=False,
                  help="Show backup info")
    parser.add_option("-u", "--uuid", dest="uuid", action="store", default=None,
                  help="uuid of device to backup/restore")
    parser.add_option("-p", "--path", dest="path", action="store", default=None,
                  help="path to backup/restore to")
    (options, args) = parser.parse_args()

    lockdown = LockdownClient(options.uuid)
    mb = MobileBackup2(lockdown, options.path)

    if options.backup:
        mb.backup()
    elif options.restore:
        mb.restore()
    if options.info:
        mb.info()
    if options.list:
        mb.list()

Example #25
0
 def __init__(self, bid, sandbox="VendContainer", lockdown=None):
     self.lockdown = lockdown if lockdown else LockdownClient()
     service = self.lockdown.startService("com.apple.mobile.house_arrest") 
 	res = service.sendRequest({"Command": sandbox, "Identifier": bid})
     super(HouseArrestAFCClient, self).__init__(self.lockdown, service=service)
Example #26
0
                      action="store_true",
                      default=False,
                      help="List installed applications (non system apps)")
    parser.add_option("-a",
                      "--app",
                      dest="app",
                      action="store",
                      default=None,
                      metavar="FILE",
                      help="Access application files with AFC")
    parser.add_option("-i",
                      "--install",
                      dest="installapp",
                      action="store",
                      default=None,
                      metavar="FILE",
                      help="Install an application package")

    (options, args) = parser.parse_args()
    if options.list:
        lockdown = LockdownClient()
        list_apps(lockdown)
    elif options.app:
        lockdown = LockdownClient()
        house_arrest_shell(lockdown, options.app)
    elif options.installapp:
        lockdown = LockdownClient()
        mobile_install(lockdown, options.installapp)
    else:
        parser.print_help()