import plistlib import struct import socket from datetime import datetime from progressbar import ProgressBar, Percentage, Bar, SimpleProgress, ETA from usbmux import usbmux from util import sizeof_fmt kIOAESAcceleratorEncrypt = 0 kIOAESAcceleratorDecrypt = 1 kIOAESAcceleratorGIDMask = 0x3E8 kIOAESAcceleratorUIDMask = 0x7D0 class DeviceInfo(dict): @staticmethod def create(dict): try: assert dict.has_key("dataVolumeUUID") filename = "%s.plist" % dict.get("dataVolumeUUID") return DeviceInfo(plistlib.readPlist(filename)) except: return DeviceInfo(dict) def save(self): filename = "%s.plist" % self.get("dataVolumeUUID", "unk") plistlib.writePlist(self, filename) #stop doing magic stuff #def __del__(self): # self.save() class RamdiskToolClient(object): instance = None @staticmethod def get(): if not RamdiskToolClient.instance: RamdiskToolClient.instance = RamdiskToolClient() return RamdiskToolClient.instance def __init__(self, udid=None, host="localhost", port=1999): self.host = host self.port = port self.device_infos = {} self.s = None self.connect(udid) self.getDeviceInfos() def close(self): if self.s: self.s.close() self.s = None def connect(self, udid=None): mux = usbmux.USBMux() mux.process(1.0) if not mux.devices: print "Waiting for iOS device" while not mux.devices: mux.process(1.0) if not mux.devices: print "No device found" return dev = mux.devices[0] print "Connecting to device : " + dev.serial try: self.s = mux.connect(dev, self.port) except: raise Exception("Connexion to device port %d failed" % self.port) def getDeviceInfos(self): self.device_infos = self.send_req({"Request":"DeviceInfo"}) keys = self.grabDeviceKeys() if keys: self.device_infos.update(keys) return DeviceInfo.create(self.device_infos) def downloadFile(self, path): res = self.send_req({"Request": "DownloadFile", "Path": path}) if type(res) == plistlib._InternalDict and res.has_key("Data"): return res["Data"].data def getSystemKeyBag(self): return self.send_req({"Request":"GetSystemKeyBag"}) def bruteforceKeyBag(self, KeyBagKeys): return self.send_req({"Request":"BruteforceSystemKeyBag", "KeyBagKeys": plistlib.Data(KeyBagKeys)}) def getEscrowRecord(self, hostID): return self.send_req({"Request":"GetEscrowRecord", "HostID": hostID}) def getPasscodeKey(self, keybagkeys, passcode): return self.send_req({"Request":"KeyBagGetPasscodeKey", "KeyBagKeys": plistlib.Data(keybagkeys), "passcode": passcode}) def send_msg(self, dict): plist = plistlib.writePlistToString(dict) data = struct.pack("