forked from dkw72n/idb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spring_board_service.py
72 lines (57 loc) · 2.75 KB
/
spring_board_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import struct
import logging
from ctypes import cdll, c_int, c_char, POINTER, c_char_p, c_byte, pointer, cast, c_void_p, c_uint, create_string_buffer, Structure, c_uint32, c_int32, c_uint16, c_uint64, c_int64, sizeof, create_string_buffer, string_at
from service import Service
# lockdown
from libimobiledevice import SbservicesError, SbservicesInterfaceOrientation
from libimobiledevice import sbservices_client_start_service, sbservices_client_free, sbservices_get_icon_pngdata, sbservices_get_interface_orientation, libimobiledevice_free
from libimobiledevice import plist_free, plist_to_bin, plist_to_bin_free, plist_to_xml, plist_to_xml_free
import plistlib
from utils import read_buffer_from_pointer
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
class SpringBoardService(Service):
"""
SprintBoard服务,负责获取应用图标
"""
def new_client(self, device):
"""
创建SprintBoard client,用于调用其他接口
:param device: 由DeviceService创建的device对象(C对象)
:return: SprintBoard client(C对象), 在使用完毕后请务必调用free_client来释放该对象内存
"""
client = c_void_p()
ret = sbservices_client_start_service(device, pointer(client), "ideviceinfo".encode("utf-8"))
if ret != SbservicesError.SBSERVICES_E_SUCCESS:
return None
return client
def free_client(self, client):
"""
释放SprintBoard Client
:param client: SprintBoard client(C对象)
:return: bool 是否成功
"""
ret = sbservices_client_free(client)
return ret == SbservicesError.SBSERVICES_E_SUCCESS
def get_icon_pngdata(self, client, bundle_id):
"""
获取应用图标
:param client: SprintBoard client(C对象)
:param bundle_id: 应用ID
:return: 应用图标(PNG data)
"""
pngdata_p = c_void_p()
pngsize = c_uint64()
ret = sbservices_get_icon_pngdata(client, bundle_id.encode("utf-8"), pointer(pngdata_p), pointer(pngsize))
if ret != SbservicesError.SBSERVICES_E_SUCCESS:
return None
buffer = read_buffer_from_pointer(pngdata_p, pngsize.value)
# print("buffer.length", len(buffer))
libimobiledevice_free(pngdata_p)
return buffer
def get_interface_orientation(self, client):
interface_orientation = c_uint()
ret = sbservices_get_interface_orientation(client, pointer(interface_orientation))
if ret != SbservicesError.SBSERVICES_E_SUCCESS:
return SbservicesInterfaceOrientation.SBSERVICES_INTERFACE_ORIENTATION_UNKNOWN
return int(interface_orientation.value)