summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am2
-rw-r--r--include/endianness.h7
-rw-r--r--include/libimobiledevice/afc.h30
-rw-r--r--include/libimobiledevice/libimobiledevice.h33
-rw-r--r--include/libimobiledevice/ostrace.h198
5 files changed, 267 insertions, 3 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 2abaf49..a41f53d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -23,9 +23,11 @@ nobase_include_HEADERS = \
23 libimobiledevice/diagnostics_relay.h \ 23 libimobiledevice/diagnostics_relay.h \
24 libimobiledevice/debugserver.h \ 24 libimobiledevice/debugserver.h \
25 libimobiledevice/syslog_relay.h \ 25 libimobiledevice/syslog_relay.h \
26 libimobiledevice/ostrace.h \
26 libimobiledevice/mobileactivation.h \ 27 libimobiledevice/mobileactivation.h \
27 libimobiledevice/preboard.h \ 28 libimobiledevice/preboard.h \
28 libimobiledevice/companion_proxy.h \ 29 libimobiledevice/companion_proxy.h \
29 libimobiledevice/reverse_proxy.h \ 30 libimobiledevice/reverse_proxy.h \
31 libimobiledevice/bt_packet_logger.h \
30 libimobiledevice/property_list_service.h \ 32 libimobiledevice/property_list_service.h \
31 libimobiledevice/service.h 33 libimobiledevice/service.h
diff --git a/include/endianness.h b/include/endianness.h
index 88b63db..972e51b 100644
--- a/include/endianness.h
+++ b/include/endianness.h
@@ -19,6 +19,13 @@
19#endif 19#endif
20#endif 20#endif
21 21
22#ifndef __BYTE_ORDER
23#ifndef _WIN32
24#warning __BYTE_ORDER is not defined, assuming little endian
25#endif
26#define __BYTE_ORDER __LITTLE_ENDIAN
27#endif
28
22#ifndef be16toh 29#ifndef be16toh
23#if __BYTE_ORDER == __BIG_ENDIAN 30#if __BYTE_ORDER == __BIG_ENDIAN
24#define be16toh(x) (x) 31#define be16toh(x) (x)
diff --git a/include/libimobiledevice/afc.h b/include/libimobiledevice/afc.h
index 4ad3dbd..6e404c3 100644
--- a/include/libimobiledevice/afc.h
+++ b/include/libimobiledevice/afc.h
@@ -64,6 +64,7 @@ typedef enum {
64 AFC_E_NO_MEM = 31, 64 AFC_E_NO_MEM = 31,
65 AFC_E_NOT_ENOUGH_DATA = 32, 65 AFC_E_NOT_ENOUGH_DATA = 32,
66 AFC_E_DIR_NOT_EMPTY = 33, 66 AFC_E_DIR_NOT_EMPTY = 33,
67 AFC_E_SSL_ERROR = 34,
67 AFC_E_FORCE_SIGNED_TYPE = -1 68 AFC_E_FORCE_SIGNED_TYPE = -1
68} afc_error_t; 69} afc_error_t;
69 70
@@ -145,6 +146,20 @@ LIBIMOBILEDEVICE_API afc_error_t afc_client_free(afc_client_t client);
145LIBIMOBILEDEVICE_API afc_error_t afc_get_device_info(afc_client_t client, char ***device_information); 146LIBIMOBILEDEVICE_API afc_error_t afc_get_device_info(afc_client_t client, char ***device_information);
146 147
147/** 148/**
149 * Get device information for a connected client. The device information
150 * returned is the device model as well as the free space, the total capacity
151 * and blocksize on the accessed disk partition.
152 *
153 * @param client The client to get device info for.
154 * @param device_information A pointer to a plist_t that will be populated
155 * with key-value pairs (dictionary) representing the device’s
156 * storage and model information. Free with plist_free().
157 *
158 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
159 */
160LIBIMOBILEDEVICE_API afc_error_t afc_get_device_info_plist(afc_client_t client, plist_t *device_information);
161
162/**
148 * Gets a directory listing of the directory requested. 163 * Gets a directory listing of the directory requested.
149 * 164 *
150 * @param client The client to get a directory listing from. 165 * @param client The client to get a directory listing from.
@@ -163,7 +178,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_read_directory(afc_client_t client, const c
163 * @param client The client to use to get the information of the file. 178 * @param client The client to use to get the information of the file.
164 * @param path The fully-qualified path to the file. 179 * @param path The fully-qualified path to the file.
165 * @param file_information Pointer to a buffer that will be filled with a 180 * @param file_information Pointer to a buffer that will be filled with a
166 * NULL-terminated list of strings with the file information. Set to NULL 181 * NULL-terminated list of strings with the file attributes. Set to NULL
167 * before calling this function. Free with afc_dictionary_free(). 182 * before calling this function. Free with afc_dictionary_free().
168 * 183 *
169 * @return AFC_E_SUCCESS on success or an AFC_E_* error value. 184 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
@@ -171,6 +186,19 @@ LIBIMOBILEDEVICE_API afc_error_t afc_read_directory(afc_client_t client, const c
171LIBIMOBILEDEVICE_API afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***file_information); 186LIBIMOBILEDEVICE_API afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***file_information);
172 187
173/** 188/**
189 * Gets information about a specific file.
190 *
191 * @param client The client to use to get the information of the file.
192 * @param path The fully-qualified path to the file.
193 * @param file_information A pointer to a plist_t that will be populated
194 * with key-value pairs (dictionary) representing the file attributes.
195 * Free with plist_free().
196 *
197 * @return AFC_E_SUCCESS on success or an AFC_E_* error value.
198 */
199LIBIMOBILEDEVICE_API afc_error_t afc_get_file_info_plist(afc_client_t client, const char *path, plist_t *file_information);
200
201/**
174 * Opens a file on the device. 202 * Opens a file on the device.
175 * 203 *
176 * @param client The client to use to open the file. 204 * @param client The client to use to open the file.
diff --git a/include/libimobiledevice/libimobiledevice.h b/include/libimobiledevice/libimobiledevice.h
index a9d270b..bc57778 100644
--- a/include/libimobiledevice/libimobiledevice.h
+++ b/include/libimobiledevice/libimobiledevice.h
@@ -31,10 +31,13 @@ extern "C" {
31#endif 31#endif
32 32
33#include <stdint.h> 33#include <stdint.h>
34#include <sys/types.h>
35#include <sys/stat.h>
36#include <plist/plist.h> 34#include <plist/plist.h>
37 35
36#if defined(_MSC_VER)
37#include <basetsd.h>
38typedef SSIZE_T ssize_t;
39#endif
40
38#ifndef LIBIMOBILEDEVICE_API 41#ifndef LIBIMOBILEDEVICE_API
39 #ifdef LIBIMOBILEDEVICE_STATIC 42 #ifdef LIBIMOBILEDEVICE_STATIC
40 #define LIBIMOBILEDEVICE_API 43 #define LIBIMOBILEDEVICE_API
@@ -401,12 +404,38 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32
401LIBIMOBILEDEVICE_API idevice_error_t idevice_get_udid(idevice_t device, char **udid); 404LIBIMOBILEDEVICE_API idevice_error_t idevice_get_udid(idevice_t device, char **udid);
402 405
403/** 406/**
407 * Returns the device ProductVersion in numerical form, where "X.Y.Z"
408 * will be returned as (X << 16) | (Y << 8) | Z .
409 * Use IDEVICE_DEVICE_VERSION macro for easy version comparison.
410 * @see IDEVICE_DEVICE_VERSION
411 *
412 * @param client Initialized device client
413 *
414 * @return A numerical representation of the X.Y.Z ProductVersion string
415 * or 0 if the version cannot be retrieved.
416 */
417LIBIMOBILEDEVICE_API unsigned int idevice_get_device_version(idevice_t device);
418
419/**
420 * Gets a readable error string for a given idevice error code.
421 *
422 * @param err An idevice error code
423 *
424 * @return A readable error string
425 */
426LIBIMOBILEDEVICE_API const char* idevice_strerror(idevice_error_t err);
427
428/**
404 * Returns a static string of the libimobiledevice version. 429 * Returns a static string of the libimobiledevice version.
405 * 430 *
406 * @return The libimobiledevice version as static ascii string 431 * @return The libimobiledevice version as static ascii string
407 */ 432 */
408LIBIMOBILEDEVICE_API const char* libimobiledevice_version(); 433LIBIMOBILEDEVICE_API const char* libimobiledevice_version();
409 434
435/* macros */
436/** Helper macro to get a numerical representation of a product version tuple */
437#define IDEVICE_DEVICE_VERSION(maj, min, patch) ((((maj) & 0xFF) << 16) | (((min) & 0xFF) << 8) | ((patch) & 0xFF))
438
410#ifdef __cplusplus 439#ifdef __cplusplus
411} 440}
412#endif 441#endif
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
27extern "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 */
37typedef 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
49typedef struct ostrace_client_private ostrace_client_private; /**< \private */
50typedef ostrace_client_private *ostrace_client_t; /**< The client handle. */
51
52#pragma pack(push,1)
53struct 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 */
89typedef void (*ostrace_activity_cb_t)(const void* buf, size_t len, void *user_data);
90
91/** Receives archive data from the ostrace service */
92typedef 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 */
108LIBIMOBILEDEVICE_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 */
122LIBIMOBILEDEVICE_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 */
133LIBIMOBILEDEVICE_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 */
154LIBIMOBILEDEVICE_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 */
168LIBIMOBILEDEVICE_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 */
178LIBIMOBILEDEVICE_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 */
192LIBIMOBILEDEVICE_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