diff options
| -rw-r--r-- | include/Makefile.am | 1 | ||||
| -rw-r--r-- | include/libimobiledevice/preboard.h | 168 | ||||
| -rw-r--r-- | src/Makefile.am | 1 | ||||
| -rw-r--r-- | src/preboard.c | 318 | ||||
| -rw-r--r-- | src/preboard.h | 34 |
5 files changed, 522 insertions, 0 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index f2b93ed..eaf052a 100644 --- a/include/Makefile.am +++ b/include/Makefile.am | |||
| @@ -21,5 +21,6 @@ nobase_include_HEADERS = libimobiledevice/libimobiledevice.h \ | |||
| 21 | libimobiledevice/debugserver.h\ | 21 | libimobiledevice/debugserver.h\ |
| 22 | libimobiledevice/syslog_relay.h\ | 22 | libimobiledevice/syslog_relay.h\ |
| 23 | libimobiledevice/mobileactivation.h\ | 23 | libimobiledevice/mobileactivation.h\ |
| 24 | libimobiledevice/preboard.h\ | ||
| 24 | libimobiledevice/property_list_service.h\ | 25 | libimobiledevice/property_list_service.h\ |
| 25 | libimobiledevice/service.h | 26 | libimobiledevice/service.h |
diff --git a/include/libimobiledevice/preboard.h b/include/libimobiledevice/preboard.h new file mode 100644 index 0000000..dc4e5f3 --- /dev/null +++ b/include/libimobiledevice/preboard.h | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | /** | ||
| 2 | * @file libimobiledevice/preboard.h | ||
| 3 | * @brief Service to 'preboard' a device, which allows to ask for passcode during firmware updates. | ||
| 4 | * \internal | ||
| 5 | * | ||
| 6 | * Copyright (c) 2019 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 IPREBOARD_H | ||
| 24 | #define IPREBOARD_H | ||
| 25 | |||
| 26 | #ifdef __cplusplus | ||
| 27 | extern "C" { | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #include <libimobiledevice/libimobiledevice.h> | ||
| 31 | #include <libimobiledevice/lockdown.h> | ||
| 32 | |||
| 33 | #define PREBOARD_SERVICE_NAME "com.apple.preboardservice_v2" | ||
| 34 | |||
| 35 | /** Error Codes */ | ||
| 36 | typedef enum { | ||
| 37 | PREBOARD_E_SUCCESS = 0, | ||
| 38 | PREBOARD_E_INVALID_ARG = -1, | ||
| 39 | PREBOARD_E_PLIST_ERROR = -2, | ||
| 40 | PREBOARD_E_MUX_ERROR = -3, | ||
| 41 | PREBOARD_E_SSL_ERROR = -4, | ||
| 42 | PREBOARD_E_NOT_ENOUGH_DATA = -5, | ||
| 43 | PREBOARD_E_TIMEOUT = -6, | ||
| 44 | PREBOARD_E_OP_IN_PROGRESS = -10, | ||
| 45 | PREBOARD_E_UNKNOWN_ERROR = -256 | ||
| 46 | } preboard_error_t; | ||
| 47 | |||
| 48 | typedef struct preboard_client_private preboard_client_private; | ||
| 49 | typedef preboard_client_private *preboard_client_t; /**< The client handle. */ | ||
| 50 | |||
| 51 | /** Reports the status response of the given command */ | ||
| 52 | typedef void (*preboard_status_cb_t) (plist_t message, void *user_data); | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Connects to the preboard service on the specified device. | ||
| 56 | * | ||
| 57 | * @param device The device to connect to. | ||
| 58 | * @param service The service descriptor returned by lockdownd_start_service. | ||
| 59 | * @param client Pointer that will point to a newly allocated | ||
| 60 | * preboard_client_t upon successful return. Must be freed using | ||
| 61 | * preboard_client_free() after use. | ||
| 62 | * | ||
| 63 | * @return PREBOARD_E_SUCCESS on success, PREBOARD_E_INVALID_ARG when | ||
| 64 | * client is NULL, or an PREBOARD_E_* error code otherwise. | ||
| 65 | */ | ||
| 66 | preboard_error_t preboard_client_new(idevice_t device, lockdownd_service_descriptor_t service, preboard_client_t * client); | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Starts a new preboard service on the specified device and connects to it. | ||
| 70 | * | ||
| 71 | * @param device The device to connect to. | ||
| 72 | * @param client Pointer that will point to a newly allocated | ||
| 73 | * preboard_client_t upon successful return. Must be freed using | ||
| 74 | * preboard_client_free() after use. | ||
| 75 | * @param label The label to use for communication. Usually the program name. | ||
| 76 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
| 77 | * | ||
| 78 | * @return PREBOARD_E_SUCCESS on success, or a PREBOARD_E_* error | ||
| 79 | * code otherwise. | ||
| 80 | */ | ||
| 81 | preboard_error_t preboard_client_start_service(idevice_t device, preboard_client_t * client, const char* label); | ||
| 82 | |||
| 83 | /** | ||
| 84 | * Disconnects a preboard client from the device and frees up the | ||
| 85 | * preboard client data. | ||
| 86 | * | ||
| 87 | * @param client The preboard client to disconnect and free. | ||
| 88 | * | ||
| 89 | * @return PREBOARD_E_SUCCESS on success, PREBOARD_E_INVALID_ARG when | ||
| 90 | * client is NULL, or a PREBOARD_E_* error code otherwise. | ||
| 91 | */ | ||
| 92 | preboard_error_t preboard_client_free(preboard_client_t client); | ||
| 93 | |||
| 94 | /** | ||
| 95 | * Sends a plist to the service. | ||
| 96 | * | ||
| 97 | * @param client The preboard client | ||
| 98 | * @param plist The plist to send | ||
| 99 | * | ||
| 100 | * @return PREBOARD_E_SUCCESS on success, | ||
| 101 | * PREBOARD_E_INVALID_ARG when client or plist is NULL, | ||
| 102 | * or a PREBOARD_E_* error code on error | ||
| 103 | */ | ||
| 104 | preboard_error_t preboard_send(preboard_client_t client, plist_t plist); | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Receives a plist from the service. | ||
| 108 | * | ||
| 109 | * @param client The preboard client | ||
| 110 | * @param plist Pointer to a plist_t what will be set to the received plist | ||
| 111 | * | ||
| 112 | * @return PREBOARD_E_SUCCESS on success, | ||
| 113 | * PREBOARD_E_INVALID_ARG when client or plist is NULL, | ||
| 114 | * PREBOARD_E_TIMEOUT when no data was received after 5 seconds, | ||
| 115 | * or a PREBOARD_E_* error code on error | ||
| 116 | */ | ||
| 117 | preboard_error_t preboard_receive(preboard_client_t client, plist_t * plist); | ||
| 118 | |||
| 119 | /** | ||
| 120 | * Receives a plist from the service with the specified timeout. | ||
| 121 | * | ||
| 122 | * @param client The preboard client | ||
| 123 | * @param plist Pointer to a plist_t what will be set to the received plist | ||
| 124 | * | ||
| 125 | * @return PREBOARD_E_SUCCESS on success, | ||
| 126 | * PREBOARD_E_INVALID_ARG when client or plist is NULL, | ||
| 127 | * PREBOARD_E_TIMEOUT when no data was received after the given timeout, | ||
| 128 | * or a PREBOARD_E_* error code on error. | ||
| 129 | */ | ||
| 130 | preboard_error_t preboard_receive_with_timeout(preboard_client_t client, plist_t * plist, uint32_t timeout_ms); | ||
| 131 | |||
| 132 | /** | ||
| 133 | * Tells the preboard service to create a stashbag. This will make the device | ||
| 134 | * show a passcode entry so it can generate and store a token that is later | ||
| 135 | * used during restore. | ||
| 136 | * | ||
| 137 | * @param client The preboard client | ||
| 138 | * @param manifest An optional manifest | ||
| 139 | * @param status_cb Callback function that will receive status and error messages. | ||
| 140 | * Can be NULL if you want to handle receiving messages in your own code. | ||
| 141 | * @param user_data User data for callback function or NULL. | ||
| 142 | * | ||
| 143 | * @return PREBOARD_E_SUCCESS if the command was successfully submitted, | ||
| 144 | * PREBOARD_E_INVALID_ARG when client is invalid, | ||
| 145 | * or a PREBOARD_E_* error code on error. | ||
| 146 | */ | ||
| 147 | preboard_error_t preboard_create_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data); | ||
| 148 | |||
| 149 | /** | ||
| 150 | * Instructs the preboard service to commit a previously created stashbag. | ||
| 151 | * | ||
| 152 | * @param client The preboard client to use for receiving | ||
| 153 | * @param manifest An optional manifest | ||
| 154 | * @param status_cb Callback function that will receive status and error messages | ||
| 155 | * Can be NULL if you want to handle receiving messages in your own code. | ||
| 156 | * @param user_data User data for callback function or NULL. | ||
| 157 | * | ||
| 158 | * @return PREBOARD_E_SUCCESS if the command was successfully submitted, | ||
| 159 | * PREBOARD_E_INVALID_ARG when client is invalid, | ||
| 160 | * or a PREBOARD_E_* error code on error. | ||
| 161 | */ | ||
| 162 | preboard_error_t preboard_commit_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data); | ||
| 163 | |||
| 164 | #ifdef __cplusplus | ||
| 165 | } | ||
| 166 | #endif | ||
| 167 | |||
| 168 | #endif | ||
diff --git a/src/Makefile.am b/src/Makefile.am index fcde8ae..5fcf097 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -29,6 +29,7 @@ libimobiledevice_la_SOURCES = idevice.c idevice.h \ | |||
| 29 | debugserver.c debugserver.h\ | 29 | debugserver.c debugserver.h\ |
| 30 | webinspector.c webinspector.h\ | 30 | webinspector.c webinspector.h\ |
| 31 | mobileactivation.c mobileactivation.h\ | 31 | mobileactivation.c mobileactivation.h\ |
| 32 | preboard.c preboard.h \ | ||
| 32 | syslog_relay.c syslog_relay.h | 33 | syslog_relay.c syslog_relay.h |
| 33 | 34 | ||
| 34 | if WIN32 | 35 | if WIN32 |
diff --git a/src/preboard.c b/src/preboard.c new file mode 100644 index 0000000..7b27a34 --- /dev/null +++ b/src/preboard.c | |||
| @@ -0,0 +1,318 @@ | |||
| 1 | /* | ||
| 2 | * preboard.c | ||
| 3 | * com.apple.preboardservice_v2 service implementation. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2019 Nikias Bassen, All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifdef HAVE_CONFIG_H | ||
| 23 | #include <config.h> | ||
| 24 | #endif | ||
| 25 | #include <string.h> | ||
| 26 | #include <stdlib.h> | ||
| 27 | #include <plist/plist.h> | ||
| 28 | |||
| 29 | #include "preboard.h" | ||
| 30 | #include "lockdown.h" | ||
| 31 | #include "common/debug.h" | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Convert a property_list_service_error_t value to a preboard_error_t value. | ||
| 35 | * Used internally to get correct error codes. | ||
| 36 | * | ||
| 37 | * @param err An property_list_service_error_t error code | ||
| 38 | * | ||
| 39 | * @return A matching preboard_error_t error code, | ||
| 40 | * PREBOARD_E_UNKNOWN_ERROR otherwise. | ||
| 41 | */ | ||
| 42 | static preboard_error_t preboard_error(property_list_service_error_t err) | ||
| 43 | { | ||
| 44 | switch (err) { | ||
| 45 | case PROPERTY_LIST_SERVICE_E_SUCCESS: | ||
| 46 | return PREBOARD_E_SUCCESS; | ||
| 47 | case PROPERTY_LIST_SERVICE_E_INVALID_ARG: | ||
| 48 | return PREBOARD_E_INVALID_ARG; | ||
| 49 | case PROPERTY_LIST_SERVICE_E_PLIST_ERROR: | ||
| 50 | return PREBOARD_E_PLIST_ERROR; | ||
| 51 | case PROPERTY_LIST_SERVICE_E_MUX_ERROR: | ||
| 52 | return PREBOARD_E_MUX_ERROR; | ||
| 53 | case PROPERTY_LIST_SERVICE_E_SSL_ERROR: | ||
| 54 | return PREBOARD_E_SSL_ERROR; | ||
| 55 | case PROPERTY_LIST_SERVICE_E_NOT_ENOUGH_DATA: | ||
| 56 | return PREBOARD_E_NOT_ENOUGH_DATA; | ||
| 57 | case PROPERTY_LIST_SERVICE_E_RECEIVE_TIMEOUT: | ||
| 58 | return PREBOARD_E_TIMEOUT; | ||
| 59 | default: | ||
| 60 | break; | ||
| 61 | } | ||
| 62 | return PREBOARD_E_UNKNOWN_ERROR; | ||
| 63 | } | ||
| 64 | |||
| 65 | LIBIMOBILEDEVICE_API preboard_error_t preboard_client_new(idevice_t device, lockdownd_service_descriptor_t service, preboard_client_t * client) | ||
| 66 | { | ||
| 67 | *client = NULL; | ||
| 68 | |||
| 69 | if (!device || !service || service->port == 0 || !client || *client) { | ||
| 70 | debug_info("Incorrect parameter passed to preboard_client_new."); | ||
| 71 | return PREBOARD_E_INVALID_ARG; | ||
| 72 | } | ||
| 73 | |||
| 74 | debug_info("Creating preboard_client, port = %d.", service->port); | ||
| 75 | |||
| 76 | property_list_service_client_t plclient = NULL; | ||
| 77 | preboard_error_t ret = preboard_error(property_list_service_client_new(device, service, &plclient)); | ||
| 78 | if (ret != PREBOARD_E_SUCCESS) { | ||
| 79 | debug_info("Creating a property list client failed. Error: %i", ret); | ||
| 80 | return ret; | ||
| 81 | } | ||
| 82 | |||
| 83 | preboard_client_t client_loc = (preboard_client_t) malloc(sizeof(struct preboard_client_private)); | ||
| 84 | client_loc->parent = plclient; | ||
| 85 | client_loc->receive_status_thread = THREAD_T_NULL; | ||
| 86 | |||
| 87 | *client = client_loc; | ||
| 88 | |||
| 89 | debug_info("preboard_client successfully created."); | ||
| 90 | return 0; | ||
| 91 | } | ||
| 92 | |||
| 93 | LIBIMOBILEDEVICE_API preboard_error_t preboard_client_start_service(idevice_t device, preboard_client_t * client, const char* label) | ||
| 94 | { | ||
| 95 | preboard_error_t err = PREBOARD_E_UNKNOWN_ERROR; | ||
| 96 | service_client_factory_start_service(device, PREBOARD_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(preboard_client_new), &err); | ||
| 97 | return err; | ||
| 98 | } | ||
| 99 | |||
| 100 | LIBIMOBILEDEVICE_API preboard_error_t preboard_client_free(preboard_client_t client) | ||
| 101 | { | ||
| 102 | if (!client) | ||
| 103 | return PREBOARD_E_INVALID_ARG; | ||
| 104 | |||
| 105 | property_list_service_client_t parent = client->parent; | ||
| 106 | client->parent = NULL; | ||
| 107 | if (client->receive_status_thread) { | ||
| 108 | debug_info("joining receive_status_thread"); | ||
| 109 | thread_join(client->receive_status_thread); | ||
| 110 | thread_free(client->receive_status_thread); | ||
| 111 | client->receive_status_thread = THREAD_T_NULL; | ||
| 112 | } | ||
| 113 | preboard_error_t err = preboard_error(property_list_service_client_free(parent)); | ||
| 114 | free(client); | ||
| 115 | |||
| 116 | return err; | ||
| 117 | } | ||
| 118 | |||
| 119 | LIBIMOBILEDEVICE_API preboard_error_t preboard_send(preboard_client_t client, plist_t plist) | ||
| 120 | { | ||
| 121 | preboard_error_t res = PREBOARD_E_UNKNOWN_ERROR; | ||
| 122 | res = preboard_error(property_list_service_send_binary_plist(client->parent, plist)); | ||
| 123 | if (res != PREBOARD_E_SUCCESS) { | ||
| 124 | debug_info("Sending plist failed with error %d", res); | ||
| 125 | return res; | ||
| 126 | } | ||
| 127 | return res; | ||
| 128 | } | ||
| 129 | |||
| 130 | LIBIMOBILEDEVICE_API preboard_error_t preboard_receive_with_timeout(preboard_client_t client, plist_t * plist, uint32_t timeout_ms) | ||
| 131 | { | ||
| 132 | preboard_error_t res = PREBOARD_E_UNKNOWN_ERROR; | ||
| 133 | plist_t outplist = NULL; | ||
| 134 | res = preboard_error(property_list_service_receive_plist_with_timeout(client->parent, &outplist, timeout_ms)); | ||
| 135 | if (res != PREBOARD_E_SUCCESS && res != PREBOARD_E_TIMEOUT) { | ||
| 136 | debug_info("Could not receive plist, error %d", res); | ||
| 137 | plist_free(outplist); | ||
| 138 | } else if (res == PREBOARD_E_SUCCESS) { | ||
| 139 | *plist = outplist; | ||
| 140 | } | ||
| 141 | return res; | ||
| 142 | } | ||
| 143 | |||
| 144 | LIBIMOBILEDEVICE_API preboard_error_t preboard_receive(preboard_client_t client, plist_t * plist) | ||
| 145 | { | ||
| 146 | return preboard_receive_with_timeout(client, plist, 5000); | ||
| 147 | } | ||
| 148 | |||
| 149 | struct preboard_status_data { | ||
| 150 | preboard_client_t client; | ||
| 151 | preboard_status_cb_t cbfunc; | ||
| 152 | void *user_data; | ||
| 153 | }; | ||
| 154 | |||
| 155 | static void* preboard_receive_status_loop_thread(void* arg) | ||
| 156 | { | ||
| 157 | struct preboard_status_data *data = (struct preboard_status_data*)arg; | ||
| 158 | |||
| 159 | /* run until the service disconnects or an error occurs */ | ||
| 160 | while (data->client && data->client->parent) { | ||
| 161 | plist_t pl = NULL; | ||
| 162 | preboard_error_t perr = preboard_receive_with_timeout(data->client, &pl, 1000); | ||
| 163 | if (perr == PREBOARD_E_TIMEOUT) { | ||
| 164 | continue; | ||
| 165 | } else if (perr == PREBOARD_E_SUCCESS) { | ||
| 166 | data->cbfunc(pl, data->user_data); | ||
| 167 | } | ||
| 168 | plist_free(pl); | ||
| 169 | if (perr != PREBOARD_E_SUCCESS) { | ||
| 170 | data->cbfunc(NULL, data->user_data); | ||
| 171 | break; | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | /* cleanup */ | ||
| 176 | debug_info("done, cleaning up."); | ||
| 177 | |||
| 178 | if (data->client->receive_status_thread) { | ||
| 179 | thread_free(data->client->receive_status_thread); | ||
| 180 | data->client->receive_status_thread = THREAD_T_NULL; | ||
| 181 | } | ||
| 182 | free(data); | ||
| 183 | |||
| 184 | return NULL; | ||
| 185 | } | ||
| 186 | |||
| 187 | static preboard_error_t preboard_receive_status_loop_with_callback(preboard_client_t client, preboard_status_cb_t status_cb, void *user_data) | ||
| 188 | { | ||
| 189 | if (!client || !client->parent) { | ||
| 190 | return PREBOARD_E_INVALID_ARG; | ||
| 191 | } | ||
| 192 | |||
| 193 | if (client->receive_status_thread) { | ||
| 194 | return PREBOARD_E_OP_IN_PROGRESS; | ||
| 195 | } | ||
| 196 | |||
| 197 | preboard_error_t res = PREBOARD_E_UNKNOWN_ERROR; | ||
| 198 | struct preboard_status_data *data = (struct preboard_status_data*)malloc(sizeof(struct preboard_status_data)); | ||
| 199 | if (data) { | ||
| 200 | data->client = client; | ||
| 201 | data->cbfunc = status_cb; | ||
| 202 | data->user_data = user_data; | ||
| 203 | if (thread_new(&client->receive_status_thread, preboard_receive_status_loop_thread, data) == 0) { | ||
| 204 | res = PREBOARD_E_SUCCESS; | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | return res; | ||
| 209 | } | ||
| 210 | |||
| 211 | LIBIMOBILEDEVICE_API preboard_error_t preboard_create_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data) | ||
| 212 | { | ||
| 213 | if (!client) { | ||
| 214 | return PREBOARD_E_INVALID_ARG; | ||
| 215 | } | ||
| 216 | |||
| 217 | plist_t dict = plist_new_dict(); | ||
| 218 | plist_dict_set_item(dict, "Command", plist_new_string("CreateStashbag")); | ||
| 219 | if (manifest) { | ||
| 220 | plist_dict_set_item(dict, "Manifest", plist_copy(manifest)); | ||
| 221 | } | ||
| 222 | preboard_error_t perr = preboard_send(client, dict); | ||
| 223 | plist_free(dict); | ||
| 224 | if (perr != PREBOARD_E_SUCCESS) { | ||
| 225 | return perr; | ||
| 226 | } | ||
| 227 | if (!status_cb) { | ||
| 228 | return PREBOARD_E_SUCCESS; | ||
| 229 | } | ||
| 230 | |||
| 231 | return preboard_receive_status_loop_with_callback(client, status_cb, user_data); | ||
| 232 | |||
| 233 | // return { ShowDialog: true} or {Timeout: true} followed by {HideDialog: true} | ||
| 234 | // or { Error: 1, ErrorString: <error string> } | ||
| 235 | |||
| 236 | |||
| 237 | /* | ||
| 238 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 239 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 240 | <plist version="1.0"> | ||
| 241 | <dict> | ||
| 242 | <key>ShowDialog</key> | ||
| 243 | <true/> | ||
| 244 | <key>Version</key> | ||
| 245 | <integer>2</integer> | ||
| 246 | </dict> | ||
| 247 | </plist> | ||
| 248 | |||
| 249 | for success, it will send the HideDialog message, then wait up to 14400 seconds (4h) for the device to reboot? | ||
| 250 | |||
| 251 | |||
| 252 | <!-- error: --> | ||
| 253 | |||
| 254 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 255 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 256 | <plist version="1.0"> | ||
| 257 | <dict> | ||
| 258 | <key>Error</key> | ||
| 259 | <integer>1</integer> | ||
| 260 | <key>ErrorString</key> | ||
| 261 | <string>user authentication failed: Error Domain=com.apple.LocalAuthentication Code=-2 "Canceled by user." UserInfo={BiometryType=1, NSLocalizedDescription=Canceled by user.}</string> | ||
| 262 | <key>Version</key> | ||
| 263 | <integer>2</integer> | ||
| 264 | </dict> | ||
| 265 | </plist> | ||
| 266 | |||
| 267 | <!-- or after 2 minutes --> | ||
| 268 | |||
| 269 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 270 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 271 | <plist version="1.0"> | ||
| 272 | <dict> | ||
| 273 | <key>Timeout</key> | ||
| 274 | <true/> | ||
| 275 | <key>Version</key> | ||
| 276 | <integer>2</integer> | ||
| 277 | </dict> | ||
| 278 | </plist> | ||
| 279 | |||
| 280 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 281 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| 282 | <plist version="1.0"> | ||
| 283 | <dict> | ||
| 284 | <key>HideDialog</key> | ||
| 285 | <true/> | ||
| 286 | <key>Version</key> | ||
| 287 | <integer>2</integer> | ||
| 288 | </dict> | ||
| 289 | </plist> | ||
| 290 | |||
| 291 | */ | ||
| 292 | } | ||
| 293 | |||
| 294 | LIBIMOBILEDEVICE_API preboard_error_t preboard_commit_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data) | ||
| 295 | { | ||
| 296 | // returns { StashbagCommitComplete: true } | ||
| 297 | // or { StashbagCommitComplete: 0, Error: 1, <optional> ErrorString: <error string> } | ||
| 298 | |||
| 299 | if (!client) { | ||
| 300 | return PREBOARD_E_INVALID_ARG; | ||
| 301 | } | ||
| 302 | |||
| 303 | plist_t dict = plist_new_dict(); | ||
| 304 | plist_dict_set_item(dict, "Command", plist_new_string("CommitStashbag")); | ||
| 305 | if (manifest) { | ||
| 306 | plist_dict_set_item(dict, "Manifest", plist_copy(manifest)); | ||
| 307 | } | ||
| 308 | preboard_error_t perr = preboard_send(client, dict); | ||
| 309 | plist_free(dict); | ||
| 310 | if (perr != PREBOARD_E_SUCCESS) { | ||
| 311 | return perr; | ||
| 312 | } | ||
| 313 | if (!status_cb) { | ||
| 314 | return PREBOARD_E_SUCCESS; | ||
| 315 | } | ||
| 316 | |||
| 317 | return preboard_receive_status_loop_with_callback(client, status_cb, user_data); | ||
| 318 | } | ||
diff --git a/src/preboard.h b/src/preboard.h new file mode 100644 index 0000000..c5143a9 --- /dev/null +++ b/src/preboard.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* | ||
| 2 | * preboard.h | ||
| 3 | * com.apple.preboard_v2 service header file. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2019 Nikias Bassen, All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef __PREBOARD_H | ||
| 23 | #define __PREBOARD_H | ||
| 24 | |||
| 25 | #include "libimobiledevice/preboard.h" | ||
| 26 | #include "property_list_service.h" | ||
| 27 | #include "common/thread.h" | ||
| 28 | |||
| 29 | struct preboard_client_private { | ||
| 30 | property_list_service_client_t parent; | ||
| 31 | THREAD_T receive_status_thread; | ||
| 32 | }; | ||
| 33 | |||
| 34 | #endif | ||
