diff options
Diffstat (limited to 'cython/mobile_image_mounter.pxi')
| -rw-r--r-- | cython/mobile_image_mounter.pxi | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/cython/mobile_image_mounter.pxi b/cython/mobile_image_mounter.pxi new file mode 100644 index 0000000..8ec30d1 --- /dev/null +++ b/cython/mobile_image_mounter.pxi | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | cdef extern from "libimobiledevice/mobile_image_mounter.h": | ||
| 2 | cdef struct mobile_image_mounter_client_private: | ||
| 3 | pass | ||
| 4 | ctypedef mobile_image_mounter_client_private *mobile_image_mounter_client_t | ||
| 5 | |||
| 6 | ctypedef enum mobile_image_mounter_error_t: | ||
| 7 | MOBILE_IMAGE_MOUNTER_E_SUCCESS = 0 | ||
| 8 | MOBILE_IMAGE_MOUNTER_E_INVALID_ARG = -1 | ||
| 9 | MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR = -2 | ||
| 10 | MOBILE_IMAGE_MOUNTER_E_CONN_FAILED = -3 | ||
| 11 | MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR = -256 | ||
| 12 | |||
| 13 | mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client) | ||
| 14 | mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client) | ||
| 15 | mobile_image_mounter_error_t mobile_image_mounter_lookup_image(mobile_image_mounter_client_t client, char *image_type, plist.plist_t *result) | ||
| 16 | mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, char *image_path, char *image_signature, uint16_t signature_length, char *image_type, plist.plist_t *result) | ||
| 17 | mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client) | ||
| 18 | |||
| 19 | cdef class MobileImageMounterError(BaseError): | ||
| 20 | def __init__(self, *args, **kwargs): | ||
| 21 | self._lookup_table = { | ||
| 22 | MOBILE_IMAGE_MOUNTER_E_SUCCESS: "Success", | ||
| 23 | MOBILE_IMAGE_MOUNTER_E_INVALID_ARG: "Invalid argument", | ||
| 24 | MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR: "Property list error", | ||
| 25 | MOBILE_IMAGE_MOUNTER_E_CONN_FAILED: "Connection failed", | ||
| 26 | MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR: "Unknown error" | ||
| 27 | } | ||
| 28 | BaseError.__init__(self, *args, **kwargs) | ||
| 29 | |||
| 30 | cdef class MobileImageMounterClient(PropertyListClient): | ||
| 31 | cdef mobile_image_mounter_client_t _c_client | ||
| 32 | |||
| 33 | def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): | ||
| 34 | cdef: | ||
| 35 | iDevice dev = device | ||
| 36 | LockdownClient lckd | ||
| 37 | mobile_image_mounter_error_t err | ||
| 38 | if lockdown is None: | ||
| 39 | lckd = LockdownClient(dev) | ||
| 40 | else: | ||
| 41 | lckd = lockdown | ||
| 42 | port = lckd.start_service("com.apple.mobile.mobile_image_mounter") | ||
| 43 | err = mobile_image_mounter_new(dev._c_dev, port, &self._c_client) | ||
| 44 | self.handle_error(err) | ||
| 45 | |||
| 46 | def __dealloc__(self): | ||
| 47 | cdef mobile_image_mounter_error_t err | ||
| 48 | if self._c_client is not NULL: | ||
| 49 | err = mobile_image_mounter_free(self._c_client) | ||
| 50 | self.handle_error(err) | ||
| 51 | |||
| 52 | cdef inline BaseError _error(self, int16_t ret): | ||
| 53 | return MobileImageMounterError(ret) | ||
| 54 | |||
| 55 | cpdef plist.Node lookup_image(self, bytes image_type): | ||
| 56 | cdef: | ||
| 57 | plist.plist_t c_node = NULL | ||
| 58 | mobile_image_mounter_error_t err | ||
| 59 | err = mobile_image_mounter_lookup_image(self._c_client, image_type, &c_node) | ||
| 60 | self.handle_error(err) | ||
| 61 | return plist.plist_t_to_node(c_node) | ||
| 62 | |||
| 63 | cpdef plist.Node mount_image(self, bytes image_path, bytes image_signature, bytes image_type): | ||
| 64 | cdef: | ||
| 65 | plist.plist_t c_node = NULL | ||
| 66 | mobile_image_mounter_error_t err | ||
| 67 | err = mobile_image_mounter_mount_image(self._c_client, image_path, image_signature, len(image_signature), | ||
| 68 | image_type, &c_node) | ||
| 69 | self.handle_error(err) | ||
| 70 | return plist.plist_t_to_node(c_node) | ||
| 71 | |||
| 72 | cpdef hangup(self): | ||
| 73 | cdef mobile_image_mounter_error_t err | ||
| 74 | err = mobile_image_mounter_hangup(self._c_client) | ||
| 75 | self.handle_error(err) | ||
