diff options
Diffstat (limited to 'include/libimobiledevice/debugserver.h')
| -rw-r--r-- | include/libimobiledevice/debugserver.h | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/include/libimobiledevice/debugserver.h b/include/libimobiledevice/debugserver.h new file mode 100644 index 0000000..809b97f --- /dev/null +++ b/include/libimobiledevice/debugserver.h | |||
| @@ -0,0 +1,272 @@ | |||
| 1 | /** | ||
| 2 | * @file libimobiledevice/debugserver.h | ||
| 3 | * @brief Communicate with debugserver on the device. | ||
| 4 | * \internal | ||
| 5 | * | ||
| 6 | * Copyright (c) 2014 Martin Szulecki 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 IDEBUGSERVER_H | ||
| 24 | #define IDEBUGSERVER_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 debugserver service */ | ||
| 34 | #define DEBUGSERVER_SERVICE_NAME "com.apple.debugserver" | ||
| 35 | /** Service identifier passed to lockdownd_start_service() to start the secure debugserver service */ | ||
| 36 | #define DEBUGSERVER_SECURE_SERVICE_NAME DEBUGSERVER_SERVICE_NAME ".DVTSecureSocketProxy" | ||
| 37 | |||
| 38 | /** Error Codes */ | ||
| 39 | typedef enum { | ||
| 40 | DEBUGSERVER_E_SUCCESS = 0, | ||
| 41 | DEBUGSERVER_E_INVALID_ARG = -1, | ||
| 42 | DEBUGSERVER_E_MUX_ERROR = -2, | ||
| 43 | DEBUGSERVER_E_SSL_ERROR = -3, | ||
| 44 | DEBUGSERVER_E_RESPONSE_ERROR = -4, | ||
| 45 | DEBUGSERVER_E_TIMEOUT = -5, | ||
| 46 | DEBUGSERVER_E_UNKNOWN_ERROR = -256 | ||
| 47 | } debugserver_error_t; | ||
| 48 | |||
| 49 | typedef struct debugserver_client_private debugserver_client_private; /**< \private */ | ||
| 50 | typedef debugserver_client_private *debugserver_client_t; /**< The client handle. */ | ||
| 51 | |||
| 52 | typedef struct debugserver_command_private debugserver_command_private; /**< \private */ | ||
| 53 | typedef debugserver_command_private *debugserver_command_t; /**< The command handle. */ | ||
| 54 | |||
| 55 | /* Interface */ | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Connects to the debugserver service on the specified device. | ||
| 59 | * | ||
| 60 | * @param device The device to connect to. | ||
| 61 | * @param service The service descriptor returned by lockdownd_start_service. | ||
| 62 | * @param client Pointer that will point to a newly allocated | ||
| 63 | * debugserver_client_t upon successful return. Must be freed using | ||
| 64 | * debugserver_client_free() after use. | ||
| 65 | * | ||
| 66 | * @return DEBUGSERVER_E_SUCCESS on success, DEBUGSERVER_E_INVALID_ARG when | ||
| 67 | * client is NULL, or an DEBUGSERVER_E_* error code otherwise. | ||
| 68 | */ | ||
| 69 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_new(idevice_t device, lockdownd_service_descriptor_t service, debugserver_client_t * client); | ||
| 70 | |||
| 71 | /** | ||
| 72 | * Starts a new debugserver service on the specified device and connects to it. | ||
| 73 | * | ||
| 74 | * @param device The device to connect to. | ||
| 75 | * @param client Pointer that will point to a newly allocated | ||
| 76 | * debugserver_client_t upon successful return. Must be freed using | ||
| 77 | * debugserver_client_free() after use. | ||
| 78 | * @param label The label to use for communication. Usually the program name. | ||
| 79 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
| 80 | * | ||
| 81 | * @return DEBUGSERVER_E_SUCCESS on success, or an DEBUGSERVER_E_* error | ||
| 82 | * code otherwise. | ||
| 83 | */ | ||
| 84 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_start_service(idevice_t device, debugserver_client_t * client, const char* label); | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Disconnects a debugserver client from the device and frees up the | ||
| 88 | * debugserver client data. | ||
| 89 | * | ||
| 90 | * @param client The debugserver client to disconnect and free. | ||
| 91 | * | ||
| 92 | * @return DEBUGSERVER_E_SUCCESS on success, DEBUGSERVER_E_INVALID_ARG when | ||
| 93 | * client is NULL, or an DEBUGSERVER_E_* error code otherwise. | ||
| 94 | */ | ||
| 95 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_free(debugserver_client_t client); | ||
| 96 | |||
| 97 | /** | ||
| 98 | * Sends raw data using the given debugserver service client. | ||
| 99 | * | ||
| 100 | * @param client The debugserver client to use for sending | ||
| 101 | * @param data Data to send | ||
| 102 | * @param size Size of the data to send | ||
| 103 | * @param sent Number of bytes sent (can be NULL to ignore) | ||
| 104 | * | ||
| 105 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 106 | * DEBUGSERVER_E_INVALID_ARG when one or more parameters are | ||
| 107 | * invalid, or DEBUGSERVER_E_UNKNOWN_ERROR when an unspecified | ||
| 108 | * error occurs. | ||
| 109 | */ | ||
| 110 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send(debugserver_client_t client, const char* data, uint32_t size, uint32_t *sent); | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Receives raw data using the given debugserver client with specified timeout. | ||
| 114 | * | ||
| 115 | * @param client The debugserver client to use for receiving | ||
| 116 | * @param data Buffer that will be filled with the data received | ||
| 117 | * @param size Number of bytes to receive | ||
| 118 | * @param received Number of bytes received (can be NULL to ignore) | ||
| 119 | * @param timeout Maximum time in milliseconds to wait for data. | ||
| 120 | * | ||
| 121 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 122 | * DEBUGSERVER_E_INVALID_ARG when one or more parameters are | ||
| 123 | * invalid, DEBUGSERVER_E_MUX_ERROR when a communication error | ||
| 124 | * occurs, DEBUGSERVER_E_TIMEOUT when the timeout is reached, | ||
| 125 | * or DEBUGSERVER_E_UNKNOWN_ERROR when an unspecified | ||
| 126 | * error occurs. | ||
| 127 | */ | ||
| 128 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_with_timeout(debugserver_client_t client, char *data, uint32_t size, uint32_t *received, unsigned int timeout); | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Receives raw data from the debugserver service. | ||
| 132 | * | ||
| 133 | * @param client The debugserver client | ||
| 134 | * @param data Buffer that will be filled with the data received | ||
| 135 | * @param size Number of bytes to receive | ||
| 136 | * @param received Number of bytes received (can be NULL to ignore) | ||
| 137 | * @note The default read timeout is 10 seconds. | ||
| 138 | * | ||
| 139 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 140 | * DEBUGSERVER_E_INVALID_ARG when client or plist is NULL | ||
| 141 | */ | ||
| 142 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive(debugserver_client_t client, char *data, uint32_t size, uint32_t *received); | ||
| 143 | |||
| 144 | /** | ||
| 145 | * Sends a command to the debugserver service. | ||
| 146 | * | ||
| 147 | * @param client The debugserver client | ||
| 148 | * @param command Command to process and send | ||
| 149 | * @param response Response received for the command (can be NULL to ignore) | ||
| 150 | * @param response_size Pointer to receive response size. Set to NULL to ignore. | ||
| 151 | * | ||
| 152 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 153 | * DEBUGSERVER_E_INVALID_ARG when client or command is NULL | ||
| 154 | */ | ||
| 155 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response, size_t* response_size); | ||
| 156 | |||
| 157 | /** | ||
| 158 | * Receives and parses response of debugserver service. | ||
| 159 | * | ||
| 160 | * @param client The debugserver client | ||
| 161 | * @param response Response received for last command (can be NULL to ignore) | ||
| 162 | * @param response_size Pointer to receive response size. Set to NULL to ignore. | ||
| 163 | * | ||
| 164 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 165 | * DEBUGSERVER_E_INVALID_ARG when client is NULL | ||
| 166 | */ | ||
| 167 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response, size_t* response_size); | ||
| 168 | |||
| 169 | /** | ||
| 170 | * Controls status of ACK mode when sending commands or receiving responses. | ||
| 171 | * | ||
| 172 | * @see debugserver_client_send_command, debugserver_client_receive_response | ||
| 173 | * | ||
| 174 | * @param client The debugserver client | ||
| 175 | * @param enabled A boolean flag indicating whether the internal ACK mode | ||
| 176 | * handling should be enabled or disabled. | ||
| 177 | * | ||
| 178 | * @return DEBUGSERVER_E_SUCCESS on success, or an DEBUGSERVER_E_* error | ||
| 179 | * code otherwise. | ||
| 180 | */ | ||
| 181 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_ack_mode(debugserver_client_t client, int enabled); | ||
| 182 | |||
| 183 | /** | ||
| 184 | * Sets behavior when awaiting a response from the server. | ||
| 185 | * | ||
| 186 | * @see debugserver_client_send_command, debugserver_client_receive_response, | ||
| 187 | * debugserver_client_receive | ||
| 188 | * | ||
| 189 | * @param client The debugserver client | ||
| 190 | * @param cancel_receive A function pointer that will be called approximately | ||
| 191 | * every receive_loop_timeout milliseconds; the function should return a | ||
| 192 | * boolean flag specifying whether to stop waiting for a response. If NULL, | ||
| 193 | * behaves as if it always returns true. | ||
| 194 | * @param receive_loop_timeout Time in milliseconds between calls to | ||
| 195 | * cancel_receive. | ||
| 196 | * | ||
| 197 | * @return DEBUGSERVER_E_SUCCESS on success, or an DEBUGSERVER_E_* error | ||
| 198 | * code otherwise. | ||
| 199 | */ | ||
| 200 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_receive_params(debugserver_client_t client, int (*cancel_receive)(), int receive_loop_timeout); | ||
| 201 | |||
| 202 | /** | ||
| 203 | * Sets the argv which launches an app. | ||
| 204 | * | ||
| 205 | * @param client The debugserver client | ||
| 206 | * @param argc Number of arguments | ||
| 207 | * @param argv Array starting with the executable to be run followed by it's arguments | ||
| 208 | * @param response Response received for the command (can be NULL to ignore) | ||
| 209 | * | ||
| 210 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 211 | * DEBUGSERVER_E_INVALID_ARG when client is NULL | ||
| 212 | */ | ||
| 213 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_argv(debugserver_client_t client, int argc, char* argv[], char** response); | ||
| 214 | |||
| 215 | /** | ||
| 216 | * Adds or sets an environment variable. | ||
| 217 | * | ||
| 218 | * @param client The debugserver client | ||
| 219 | * @param env The environment variable in "KEY=VALUE" notation | ||
| 220 | * @param response Response received for the command (can be NULL to ignore) | ||
| 221 | * | ||
| 222 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 223 | * DEBUGSERVER_E_INVALID_ARG when client is NULL | ||
| 224 | */ | ||
| 225 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_environment_hex_encoded(debugserver_client_t client, const char* env, char** response); | ||
| 226 | |||
| 227 | /** | ||
| 228 | * Creates and initializes a new command object. | ||
| 229 | * | ||
| 230 | * @param name The name of the command which is sent in plain text | ||
| 231 | * @param argv Array of tokens for the command ment to be encoded | ||
| 232 | * @param argc Number of items in the token array | ||
| 233 | * @param command New command object | ||
| 234 | * | ||
| 235 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 236 | * DEBUGSERVER_E_INVALID_ARG when name or command is NULL | ||
| 237 | */ | ||
| 238 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_command_new(const char* name, int argc, char* argv[], debugserver_command_t* command); | ||
| 239 | |||
| 240 | /** | ||
| 241 | * Frees memory of command object. | ||
| 242 | * | ||
| 243 | * @param command The command object | ||
| 244 | * | ||
| 245 | * @return DEBUGSERVER_E_SUCCESS on success, | ||
| 246 | * DEBUGSERVER_E_INVALID_ARG when command is NULL | ||
| 247 | */ | ||
| 248 | LIBIMOBILEDEVICE_API debugserver_error_t debugserver_command_free(debugserver_command_t command); | ||
| 249 | |||
| 250 | /** | ||
| 251 | * Encodes a string into hex notation. | ||
| 252 | * | ||
| 253 | * @param buffer String to encode into hex notiation | ||
| 254 | * @param encoded_buffer The buffer receives a hex encoded string | ||
| 255 | * @param encoded_length Length of the hex encoded string | ||
| 256 | */ | ||
| 257 | LIBIMOBILEDEVICE_API void debugserver_encode_string(const char* buffer, char** encoded_buffer, uint32_t* encoded_length); | ||
| 258 | |||
| 259 | /** | ||
| 260 | * Decodes a hex encoded string. | ||
| 261 | * | ||
| 262 | * @param encoded_buffer The buffer with a hex encoded string | ||
| 263 | * @param encoded_length Length of the encoded buffer | ||
| 264 | * @param buffer Decoded string to be freed by the caller | ||
| 265 | */ | ||
| 266 | LIBIMOBILEDEVICE_API void debugserver_decode_string(const char *encoded_buffer, size_t encoded_length, char** buffer); | ||
| 267 | |||
| 268 | #ifdef __cplusplus | ||
| 269 | } | ||
| 270 | #endif | ||
| 271 | |||
| 272 | #endif | ||
