diff options
Diffstat (limited to 'include/libimobiledevice/ostrace.h')
-rw-r--r-- | include/libimobiledevice/ostrace.h | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/include/libimobiledevice/ostrace.h b/include/libimobiledevice/ostrace.h new file mode 100644 index 0000000..f083ba7 --- /dev/null +++ b/include/libimobiledevice/ostrace.h | |||
@@ -0,0 +1,198 @@ | |||
1 | /** | ||
2 | * @file libimobiledevice/ostrace.h | ||
3 | * @brief System log and tracing capabilities. | ||
4 | * \internal | ||
5 | * | ||
6 | * Copyright (c) 2020-2025 Nikias Bassen, All Rights Reserved. | ||
7 | * | ||
8 | * This library is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * This library is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with this library; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #ifndef OSTRACE_H | ||
24 | #define OSTRACE_H | ||
25 | |||
26 | #ifdef __cplusplus | ||
27 | extern "C" { | ||
28 | #endif | ||
29 | |||
30 | #include <libimobiledevice/libimobiledevice.h> | ||
31 | #include <libimobiledevice/lockdown.h> | ||
32 | |||
33 | /** Service identifier passed to lockdownd_start_service() to start the os trace relay service */ | ||
34 | #define OSTRACE_SERVICE_NAME "com.apple.os_trace_relay" | ||
35 | |||
36 | /** Error Codes */ | ||
37 | typedef enum { | ||
38 | OSTRACE_E_SUCCESS = 0, | ||
39 | OSTRACE_E_INVALID_ARG = -1, | ||
40 | OSTRACE_E_MUX_ERROR = -2, | ||
41 | OSTRACE_E_SSL_ERROR = -3, | ||
42 | OSTRACE_E_NOT_ENOUGH_DATA = -4, | ||
43 | OSTRACE_E_TIMEOUT = -5, | ||
44 | OSTRACE_E_PLIST_ERROR = -6, | ||
45 | OSTRACE_E_REQUEST_FAILED = -7, | ||
46 | OSTRACE_E_UNKNOWN_ERROR = -256 | ||
47 | } ostrace_error_t; | ||
48 | |||
49 | typedef struct ostrace_client_private ostrace_client_private; /**< \private */ | ||
50 | typedef ostrace_client_private *ostrace_client_t; /**< The client handle. */ | ||
51 | |||
52 | #pragma pack(push,1) | ||
53 | struct ostrace_packet_header_t { | ||
54 | uint8_t marker; | ||
55 | uint32_t type; | ||
56 | uint32_t header_size; // 0x81 | ||
57 | uint32_t pid; | ||
58 | uint64_t procid; // == pid | ||
59 | unsigned char procuuid[16]; // procuuid | ||
60 | uint16_t procpath_len; // path to process | ||
61 | uint64_t aid; // activity id, usually 0 | ||
62 | uint64_t paid; // (parent?) activity id, usually 0 | ||
63 | uint64_t time_sec; // tv.tv_sec 64 bit | ||
64 | uint32_t time_usec; // tv.usec 32 bit | ||
65 | uint8_t unk06; | ||
66 | uint8_t level; // Notice=0, Info=0x01, Debug=0x02, Error=0x10, Fault=0x11 | ||
67 | uint8_t unk07; | ||
68 | uint8_t unk08; | ||
69 | uint8_t unk09; | ||
70 | uint8_t unk10; | ||
71 | uint8_t unk11; | ||
72 | uint8_t unk12; | ||
73 | uint64_t timestamp; // ? | ||
74 | uint32_t thread_id; | ||
75 | uint32_t unk13; // 0 | ||
76 | unsigned char imageuuid[16]; // framework/dylib uuid | ||
77 | uint16_t imagepath_len; // framework/dylib | ||
78 | uint32_t message_len; // actual log message | ||
79 | uint32_t offset; // offset for like timestamp or sth | ||
80 | uint16_t subsystem_len; // "subsystem" | ||
81 | uint16_t unk14; | ||
82 | uint16_t category_len; // "category" | ||
83 | uint16_t unk15; | ||
84 | uint32_t unk16; // 0 | ||
85 | }; | ||
86 | #pragma pack(pop) | ||
87 | |||
88 | /** Receives unparsed ostrace data from the ostrace service */ | ||
89 | typedef void (*ostrace_activity_cb_t)(const void* buf, size_t len, void *user_data); | ||
90 | |||
91 | /** Receives archive data from the ostrace service */ | ||
92 | typedef int (*ostrace_archive_write_cb_t)(const void* buf, size_t len, void *user_data); | ||
93 | |||
94 | /* Interface */ | ||
95 | |||
96 | /** | ||
97 | * Connects to the os_trace_relay service on the specified device. | ||
98 | * | ||
99 | * @param device The device to connect to. | ||
100 | * @param service The service descriptor returned by lockdownd_start_service. | ||
101 | * @param client Pointer that will point to a newly allocated | ||
102 | * ostrace_client_t upon successful return. Must be freed using | ||
103 | * ostrace_client_free() after use. | ||
104 | * | ||
105 | * @return OSTRACE_E_SUCCESS on success, OSTRACE_E_INVALID_ARG when | ||
106 | * client is NULL, or an OSTRACE_E_* error code otherwise. | ||
107 | */ | ||
108 | LIBIMOBILEDEVICE_API ostrace_error_t ostrace_client_new(idevice_t device, lockdownd_service_descriptor_t service, ostrace_client_t * client); | ||
109 | |||
110 | /** | ||
111 | * Starts a new os_trace_relay service on the specified device and connects to it. | ||
112 | * | ||
113 | * @param device The device to connect to. | ||
114 | * @param client Pointer that will point to a newly allocated | ||
115 | * ostrace_client_t upon successful return. Must be freed using | ||
116 | * ostrace_client_free() after use. | ||
117 | * @param label The label to use for communication. Usually the program name. | ||
118 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
119 | * | ||
120 | * @return OSTRACE_E_SUCCESS on success, or an OSTRACE_E_* error code otherwise. | ||
121 | */ | ||
122 | LIBIMOBILEDEVICE_API ostrace_error_t ostrace_client_start_service(idevice_t device, ostrace_client_t * client, const char* label); | ||
123 | |||
124 | /** | ||
125 | * Disconnects a ostrace client from the device and frees up the | ||
126 | * ostrace client data. | ||
127 | * | ||
128 | * @param client The ostrace client to disconnect and free. | ||
129 | * | ||
130 | * @return OSTRACE_E_SUCCESS on success, OSTRACE_E_INVALID_ARG when | ||
131 | * client is NULL, or an OSTRACE_E_* error code otherwise. | ||
132 | */ | ||
133 | LIBIMOBILEDEVICE_API ostrace_error_t ostrace_client_free(ostrace_client_t client); | ||
134 | |||
135 | /** | ||
136 | * Starts capturing OS trace activity data of the device using a callback. | ||
137 | * | ||
138 | * Use ostrace_stop_activity() to stop receiving the ostrace. | ||
139 | * | ||
140 | * @param client The ostrace client to use | ||
141 | * @param options Options dictionary to pass to StartActivity request. | ||
142 | * Valid options are MessageFilter (PLIST_INT, default 65535), | ||
143 | * Pid (PLIST_INT, default -1), and StreamFlags (PLIST_INT, default 60) | ||
144 | * @param callback Callback to receive data from ostrace. | ||
145 | * @param user_data Custom pointer passed to the callback function. | ||
146 | * @param user_data_free_func Function pointer that will be called when the | ||
147 | * activity is stopped to release user_data. Can be NULL for none. | ||
148 | * | ||
149 | * @return OSTRACE_E_SUCCESS on success, | ||
150 | * OSTRACE_E_INVALID_ARG when one or more parameters are | ||
151 | * invalid or OSTRACE_E_UNKNOWN_ERROR when an unspecified | ||
152 | * error occurs or an ostrace activity has already been started. | ||
153 | */ | ||
154 | LIBIMOBILEDEVICE_API ostrace_error_t ostrace_start_activity(ostrace_client_t client, plist_t options, ostrace_activity_cb_t callback, void* user_data); | ||
155 | |||
156 | /** | ||
157 | * Stops the ostrace activity. | ||
158 | * | ||
159 | * Use ostrace_start_activity() to start receiving OS trace data. | ||
160 | * | ||
161 | * @param client The ostrace client to use | ||
162 | * | ||
163 | * @return OSTRACE_E_SUCCESS on success, | ||
164 | * OSTRACE_E_INVALID_ARG when one or more parameters are | ||
165 | * invalid or OSTRACE_E_UNKNOWN_ERROR when an unspecified | ||
166 | * error occurs or an ostrace activity has already been started. | ||
167 | */ | ||
168 | LIBIMOBILEDEVICE_API ostrace_error_t ostrace_stop_activity(ostrace_client_t client); | ||
169 | |||
170 | /** | ||
171 | * Returns a dictionary with all currently running processes on the device. | ||
172 | * | ||
173 | * @param client The ostrace client to use | ||
174 | * @param list Pointer that will receive an allocated PLIST_DICT structure with the process data | ||
175 | * | ||
176 | * @return OSTRACE_E_SUCCESS on success, or an OSTRACE_E_* error code otherwise | ||
177 | */ | ||
178 | LIBIMOBILEDEVICE_API ostrace_error_t ostrace_get_pid_list(ostrace_client_t client, plist_t* list); | ||
179 | |||
180 | /** | ||
181 | * Creates a syslog archive. | ||
182 | * | ||
183 | * @note The device will close the connection once the transfer is complete. The client | ||
184 | * is not usable after that anymore and must be disposed with ostrace_client_free. | ||
185 | * | ||
186 | * @param client The ostrace client to use | ||
187 | * @param options A dictionary with options for the request. | ||
188 | * Valid parameters are StartTime (PLIST_UINT), SizeLimit (PLIST_UINT), and AgeLimit (PLIST_UINT). | ||
189 | * | ||
190 | * @return OSTRACE_E_SUCCESS on success, or an OSTRACE_E_* error code otherwise | ||
191 | */ | ||
192 | LIBIMOBILEDEVICE_API ostrace_error_t ostrace_create_archive(ostrace_client_t client, plist_t options, ostrace_archive_write_cb_t callback, void* user_data); | ||
193 | |||
194 | #ifdef __cplusplus | ||
195 | } | ||
196 | #endif | ||
197 | |||
198 | #endif | ||