summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-11-20 01:39:46 +0100
committerGravatar Nikias Bassen2019-11-20 01:39:46 +0100
commit43852c74160394c0be876945b85c0656fa2bff81 (patch)
tree00c22f445e13fadf344d7977e00cf2b2dee34856
parentaf91dc6376946daffd5c9ece916d9f33af828890 (diff)
downloadlibimobiledevice-43852c74160394c0be876945b85c0656fa2bff81.tar.gz
libimobiledevice-43852c74160394c0be876945b85c0656fa2bff81.tar.bz2
debugserver: Return size of the returned buffer
-rw-r--r--include/libimobiledevice/debugserver.h6
-rw-r--r--src/debugserver.c19
-rw-r--r--tools/idevicedebug.c20
3 files changed, 24 insertions, 21 deletions
diff --git a/include/libimobiledevice/debugserver.h b/include/libimobiledevice/debugserver.h
index 19a4f5d..8ac116c 100644
--- a/include/libimobiledevice/debugserver.h
+++ b/include/libimobiledevice/debugserver.h
@@ -142,22 +142,24 @@ debugserver_error_t debugserver_client_receive(debugserver_client_t client, char
142 * @param client The debugserver client 142 * @param client The debugserver client
143 * @param command Command to process and send 143 * @param command Command to process and send
144 * @param response Response received for the command (can be NULL to ignore) 144 * @param response Response received for the command (can be NULL to ignore)
145 * @param response_size Pointer to receive response size. Set to NULL to ignore.
145 * 146 *
146 * @return DEBUGSERVER_E_SUCCESS on success, 147 * @return DEBUGSERVER_E_SUCCESS on success,
147 * DEBUGSERVER_E_INVALID_ARG when client or command is NULL 148 * DEBUGSERVER_E_INVALID_ARG when client or command is NULL
148 */ 149 */
149debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response); 150debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response, size_t* response_size);
150 151
151/** 152/**
152 * Receives and parses response of debugserver service. 153 * Receives and parses response of debugserver service.
153 * 154 *
154 * @param client The debugserver client 155 * @param client The debugserver client
155 * @param response Response received for last command (can be NULL to ignore) 156 * @param response Response received for last command (can be NULL to ignore)
157 * @param response_size Pointer to receive response size. Set to NULL to ignore.
156 * 158 *
157 * @return DEBUGSERVER_E_SUCCESS on success, 159 * @return DEBUGSERVER_E_SUCCESS on success,
158 * DEBUGSERVER_E_INVALID_ARG when client is NULL 160 * DEBUGSERVER_E_INVALID_ARG when client is NULL
159 */ 161 */
160debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response); 162debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response, size_t* response_size);
161 163
162/** 164/**
163 * Controls status of ACK mode when sending commands or receiving responses. 165 * Controls status of ACK mode when sending commands or receiving responses.
diff --git a/src/debugserver.c b/src/debugserver.c
index 967d01d..0b0d614 100644
--- a/src/debugserver.c
+++ b/src/debugserver.c
@@ -369,7 +369,7 @@ static int debugserver_client_receive_internal_check(debugserver_client_t client
369 return did_receive_char; 369 return did_receive_char;
370} 370}
371 371
372LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response) 372LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response, size_t* response_size)
373{ 373{
374 debugserver_error_t res = DEBUGSERVER_E_SUCCESS; 374 debugserver_error_t res = DEBUGSERVER_E_SUCCESS;
375 375
@@ -449,10 +449,11 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(deb
449 if (client->noack_mode || debugserver_response_is_checksum_valid(buffer, buffer_size)) { 449 if (client->noack_mode || debugserver_response_is_checksum_valid(buffer, buffer_size)) {
450 if (response) { 450 if (response) {
451 /* assemble response string */ 451 /* assemble response string */
452 uint32_t response_size = sizeof(char) * (buffer_size - DEBUGSERVER_CHECKSUM_HASH_LENGTH - 1); 452 uint32_t resp_size = sizeof(char) * (buffer_size - DEBUGSERVER_CHECKSUM_HASH_LENGTH - 1);
453 *response = (char*)malloc(response_size + 1); 453 *response = (char*)malloc(resp_size + 1);
454 memcpy(*response, buffer + 1, response_size); 454 memcpy(*response, buffer + 1, resp_size);
455 (*response)[response_size] = '\0'; 455 (*response)[resp_size] = '\0';
456 if (response_size) *response_size = resp_size;
456 } 457 }
457 if (!client->noack_mode) { 458 if (!client->noack_mode) {
458 /* confirm valid command */ 459 /* confirm valid command */
@@ -481,7 +482,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(deb
481 return res; 482 return res;
482} 483}
483 484
484LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response) 485LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response, size_t* response_size)
485{ 486{
486 debugserver_error_t res = DEBUGSERVER_E_SUCCESS; 487 debugserver_error_t res = DEBUGSERVER_E_SUCCESS;
487 int i; 488 int i;
@@ -512,7 +513,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send_command(debugse
512 } 513 }
513 514
514 /* receive response */ 515 /* receive response */
515 res = debugserver_client_receive_response(client, response); 516 res = debugserver_client_receive_response(client, response, response_size);
516 debug_info("response result: %d", res); 517 debug_info("response result: %d", res);
517 if (res != DEBUGSERVER_E_SUCCESS) { 518 if (res != DEBUGSERVER_E_SUCCESS) {
518 goto cleanup; 519 goto cleanup;
@@ -548,7 +549,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_environment_hex_
548 549
549 debugserver_command_t command = NULL; 550 debugserver_command_t command = NULL;
550 debugserver_command_new("QEnvironmentHexEncoded:", 1, env_arg, &command); 551 debugserver_command_new("QEnvironmentHexEncoded:", 1, env_arg, &command);
551 result = debugserver_client_send_command(client, command, response); 552 result = debugserver_client_send_command(client, command, response, NULL);
552 debugserver_command_free(command); 553 debugserver_command_free(command);
553 554
554 free(env_tmp); 555 free(env_tmp);
@@ -617,7 +618,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_argv(debugserver
617 618
618 debugserver_command_t command = NULL; 619 debugserver_command_t command = NULL;
619 debugserver_command_new(pkt, 0, NULL, &command); 620 debugserver_command_new(pkt, 0, NULL, &command);
620 result = debugserver_client_send_command(client, command, response); 621 result = debugserver_client_send_command(client, command, response, NULL);
621 debugserver_command_free(command); 622 debugserver_command_free(command);
622 623
623 if (pkt) 624 if (pkt)
diff --git a/tools/idevicedebug.c b/tools/idevicedebug.c
index c7508e3..6c2f5cf 100644
--- a/tools/idevicedebug.c
+++ b/tools/idevicedebug.c
@@ -127,7 +127,7 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client
127 127
128 /* send reply */ 128 /* send reply */
129 debugserver_command_new("OK", 0, NULL, &command); 129 debugserver_command_new("OK", 0, NULL, &command);
130 dres = debugserver_client_send_command(client, command, response); 130 dres = debugserver_client_send_command(client, command, response, NULL);
131 debug_info("result: %d", dres); 131 debug_info("result: %d", dres);
132 debugserver_command_free(command); 132 debugserver_command_free(command);
133 command = NULL; 133 command = NULL;
@@ -153,7 +153,7 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client
153 153
154 /* send reply */ 154 /* send reply */
155 debugserver_command_new("OK", 0, NULL, &command); 155 debugserver_command_new("OK", 0, NULL, &command);
156 dres = debugserver_client_send_command(client, command, response); 156 dres = debugserver_client_send_command(client, command, response, NULL);
157 debug_info("result: %d", dres); 157 debug_info("result: %d", dres);
158 debugserver_command_free(command); 158 debugserver_command_free(command);
159 command = NULL; 159 command = NULL;
@@ -166,7 +166,7 @@ static debugserver_error_t debugserver_client_handle_response(debugserver_client
166 166
167 /* no command */ 167 /* no command */
168 debugserver_command_new("OK", 0, NULL, &command); 168 debugserver_command_new("OK", 0, NULL, &command);
169 dres = debugserver_client_send_command(client, command, response); 169 dres = debugserver_client_send_command(client, command, response, NULL);
170 debug_info("result: %d", dres); 170 debug_info("result: %d", dres);
171 debugserver_command_free(command); 171 debugserver_command_free(command);
172 command = NULL; 172 command = NULL;
@@ -342,7 +342,7 @@ int main(int argc, char *argv[])
342 if (debug_level) { 342 if (debug_level) {
343 debug_info("Setting logging bitmask..."); 343 debug_info("Setting logging bitmask...");
344 debugserver_command_new("QSetLogging:bitmask=LOG_ALL|LOG_RNB_REMOTE|LOG_RNB_PACKETS", 0, NULL, &command); 344 debugserver_command_new("QSetLogging:bitmask=LOG_ALL|LOG_RNB_REMOTE|LOG_RNB_PACKETS", 0, NULL, &command);
345 dres = debugserver_client_send_command(debugserver_client, command, &response); 345 dres = debugserver_client_send_command(debugserver_client, command, &response, NULL);
346 debugserver_command_free(command); 346 debugserver_command_free(command);
347 command = NULL; 347 command = NULL;
348 if (response) { 348 if (response) {
@@ -360,7 +360,7 @@ int main(int argc, char *argv[])
360 char* packet_size[2] = {strdup("1024"), NULL}; 360 char* packet_size[2] = {strdup("1024"), NULL};
361 debugserver_command_new("QSetMaxPacketSize:", 1, packet_size, &command); 361 debugserver_command_new("QSetMaxPacketSize:", 1, packet_size, &command);
362 free(packet_size[0]); 362 free(packet_size[0]);
363 dres = debugserver_client_send_command(debugserver_client, command, &response); 363 dres = debugserver_client_send_command(debugserver_client, command, &response, NULL);
364 debugserver_command_free(command); 364 debugserver_command_free(command);
365 command = NULL; 365 command = NULL;
366 if (response) { 366 if (response) {
@@ -376,7 +376,7 @@ int main(int argc, char *argv[])
376 debug_info("Setting working directory..."); 376 debug_info("Setting working directory...");
377 char* working_dir[2] = {working_directory, NULL}; 377 char* working_dir[2] = {working_directory, NULL};
378 debugserver_command_new("QSetWorkingDir:", 1, working_dir, &command); 378 debugserver_command_new("QSetWorkingDir:", 1, working_dir, &command);
379 dres = debugserver_client_send_command(debugserver_client, command, &response); 379 dres = debugserver_client_send_command(debugserver_client, command, &response, NULL);
380 debugserver_command_free(command); 380 debugserver_command_free(command);
381 command = NULL; 381 command = NULL;
382 if (response) { 382 if (response) {
@@ -417,7 +417,7 @@ int main(int argc, char *argv[])
417 /* check if launch succeeded */ 417 /* check if launch succeeded */
418 debug_info("Checking if launch succeeded..."); 418 debug_info("Checking if launch succeeded...");
419 debugserver_command_new("qLaunchSuccess", 0, NULL, &command); 419 debugserver_command_new("qLaunchSuccess", 0, NULL, &command);
420 dres = debugserver_client_send_command(debugserver_client, command, &response); 420 dres = debugserver_client_send_command(debugserver_client, command, &response, NULL);
421 debugserver_command_free(command); 421 debugserver_command_free(command);
422 command = NULL; 422 command = NULL;
423 if (response) { 423 if (response) {
@@ -432,7 +432,7 @@ int main(int argc, char *argv[])
432 /* set thread */ 432 /* set thread */
433 debug_info("Setting thread..."); 433 debug_info("Setting thread...");
434 debugserver_command_new("Hc0", 0, NULL, &command); 434 debugserver_command_new("Hc0", 0, NULL, &command);
435 dres = debugserver_client_send_command(debugserver_client, command, &response); 435 dres = debugserver_client_send_command(debugserver_client, command, &response, NULL);
436 debugserver_command_free(command); 436 debugserver_command_free(command);
437 command = NULL; 437 command = NULL;
438 if (response) { 438 if (response) {
@@ -447,7 +447,7 @@ int main(int argc, char *argv[])
447 /* continue running process */ 447 /* continue running process */
448 debug_info("Continue running process..."); 448 debug_info("Continue running process...");
449 debugserver_command_new("c", 0, NULL, &command); 449 debugserver_command_new("c", 0, NULL, &command);
450 dres = debugserver_client_send_command(debugserver_client, command, &response); 450 dres = debugserver_client_send_command(debugserver_client, command, &response, NULL);
451 debugserver_command_free(command); 451 debugserver_command_free(command);
452 command = NULL; 452 command = NULL;
453 453
@@ -470,7 +470,7 @@ int main(int argc, char *argv[])
470 /* kill process after we finished */ 470 /* kill process after we finished */
471 debug_info("Killing process..."); 471 debug_info("Killing process...");
472 debugserver_command_new("k", 0, NULL, &command); 472 debugserver_command_new("k", 0, NULL, &command);
473 dres = debugserver_client_send_command(debugserver_client, command, &response); 473 dres = debugserver_client_send_command(debugserver_client, command, &response, NULL);
474 debugserver_command_free(command); 474 debugserver_command_free(command);
475 command = NULL; 475 command = NULL;
476 if (response) { 476 if (response) {