diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/debugserver.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/debugserver.c b/src/debugserver.c index 1e06233..967d01d 100644 --- a/src/debugserver.c +++ b/src/debugserver.c | |||
| @@ -2,7 +2,8 @@ | |||
| 2 | * debugserver.c | 2 | * debugserver.c |
| 3 | * com.apple.debugserver service implementation. | 3 | * com.apple.debugserver service implementation. |
| 4 | * | 4 | * |
| 5 | * Copyright (c) 2014 Martin Szulecki All Rights Reserved. | 5 | * Copyright (c) 2019 Nikias Bassen, All Rights Reserved. |
| 6 | * Copyright (c) 2014-2015 Martin Szulecki All Rights Reserved. | ||
| 6 | * | 7 | * |
| 7 | * This library is free software; you can redistribute it and/or | 8 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public | 9 | * modify it under the terms of the GNU Lesser General Public |
| @@ -378,6 +379,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(deb | |||
| 378 | 379 | ||
| 379 | char* buffer = NULL; | 380 | char* buffer = NULL; |
| 380 | uint32_t buffer_size = 0; | 381 | uint32_t buffer_size = 0; |
| 382 | uint32_t buffer_capacity = 0; | ||
| 381 | 383 | ||
| 382 | if (response) | 384 | if (response) |
| 383 | *response = NULL; | 385 | *response = NULL; |
| @@ -390,7 +392,9 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(deb | |||
| 390 | if (strncmp(ack, command_prefix, sizeof(char)) == 0) { | 392 | if (strncmp(ack, command_prefix, sizeof(char)) == 0) { |
| 391 | should_receive = 1; | 393 | should_receive = 1; |
| 392 | skip_prefix = 1; | 394 | skip_prefix = 1; |
| 393 | buffer = strdup(command_prefix); | 395 | buffer = malloc(1024); |
| 396 | buffer_capacity = 1024; | ||
| 397 | strcpy(buffer, command_prefix); | ||
| 394 | buffer_size += sizeof(char); | 398 | buffer_size += sizeof(char); |
| 395 | debug_info("received ACK"); | 399 | debug_info("received ACK"); |
| 396 | } | 400 | } |
| @@ -404,9 +408,11 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(deb | |||
| 404 | debug_info("received command_prefix: %c", *command_prefix); | 408 | debug_info("received command_prefix: %c", *command_prefix); |
| 405 | if (should_receive) { | 409 | if (should_receive) { |
| 406 | if (buffer) { | 410 | if (buffer) { |
| 407 | memcpy(buffer, command_prefix, sizeof(char)); | 411 | strcpy(buffer, command_prefix); |
| 408 | } else { | 412 | } else { |
| 409 | buffer = strdup(command_prefix); | 413 | buffer = malloc(1024); |
| 414 | buffer_capacity = 1024; | ||
| 415 | strcpy(buffer, command_prefix); | ||
| 410 | buffer_size += sizeof(char); | 416 | buffer_size += sizeof(char); |
| 411 | } | 417 | } |
| 412 | } | 418 | } |
| @@ -418,6 +424,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(deb | |||
| 418 | uint32_t checksum_length = DEBUGSERVER_CHECKSUM_HASH_LENGTH; | 424 | uint32_t checksum_length = DEBUGSERVER_CHECKSUM_HASH_LENGTH; |
| 419 | int receiving_checksum_response = 0; | 425 | int receiving_checksum_response = 0; |
| 420 | debug_info("attempting to read up response until checksum"); | 426 | debug_info("attempting to read up response until checksum"); |
| 427 | |||
| 421 | while ((checksum_length > 0)) { | 428 | while ((checksum_length > 0)) { |
| 422 | char data[2] = {'#', '\0'}; | 429 | char data[2] = {'#', '\0'}; |
| 423 | if (debugserver_client_receive_internal_check(client, data)) { | 430 | if (debugserver_client_receive_internal_check(client, data)) { |
| @@ -426,16 +433,20 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(deb | |||
| 426 | if (receiving_checksum_response) { | 433 | if (receiving_checksum_response) { |
| 427 | checksum_length--; | 434 | checksum_length--; |
| 428 | } | 435 | } |
| 429 | char* newbuffer = string_concat(buffer, data, NULL); | 436 | if (buffer_size + 1 >= buffer_capacity) { |
| 437 | char* newbuffer = realloc(buffer, buffer_capacity+1024); | ||
| 438 | if (!newbuffer) { | ||
| 439 | return DEBUGSERVER_E_UNKNOWN_ERROR; | ||
| 440 | } | ||
| 441 | buffer = newbuffer; | ||
| 442 | buffer[buffer_capacity] = '\0'; | ||
| 443 | buffer_capacity += 1024; | ||
| 444 | } | ||
| 445 | strcat(buffer, data); | ||
| 430 | buffer_size += sizeof(char); | 446 | buffer_size += sizeof(char); |
| 431 | free(buffer); | ||
| 432 | buffer = NULL; | ||
| 433 | buffer = newbuffer; | ||
| 434 | newbuffer = NULL; | ||
| 435 | } | 447 | } |
| 436 | debug_info("validating response checksum..."); | 448 | debug_info("validating response checksum..."); |
| 437 | int valid_response = debugserver_response_is_checksum_valid(buffer, buffer_size); | 449 | if (client->noack_mode || debugserver_response_is_checksum_valid(buffer, buffer_size)) { |
| 438 | if (valid_response) { | ||
| 439 | if (response) { | 450 | if (response) { |
| 440 | /* assemble response string */ | 451 | /* assemble response string */ |
| 441 | uint32_t response_size = sizeof(char) * (buffer_size - DEBUGSERVER_CHECKSUM_HASH_LENGTH - 1); | 452 | uint32_t response_size = sizeof(char) * (buffer_size - DEBUGSERVER_CHECKSUM_HASH_LENGTH - 1); |
| @@ -482,25 +493,15 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send_command(debugse | |||
| 482 | char* command_arguments = NULL; | 493 | char* command_arguments = NULL; |
| 483 | 494 | ||
| 484 | /* concat all arguments */ | 495 | /* concat all arguments */ |
| 485 | char* tmp = NULL; | ||
| 486 | char* newtmp = NULL; | ||
| 487 | for (i = 0; i < command->argc; i++) { | 496 | for (i = 0; i < command->argc; i++) { |
| 488 | debug_info("argv[%d]: %s", i, command->argv[i]); | 497 | debug_info("argv[%d]: %s", i, command->argv[i]); |
| 489 | if (!tmp) { | 498 | command_arguments = string_append(command_arguments, command->argv[i], NULL); |
| 490 | tmp = strdup(command->argv[i]); | ||
| 491 | } else { | ||
| 492 | newtmp = string_concat(tmp, command->argv[i], NULL); | ||
| 493 | free(tmp); | ||
| 494 | tmp = newtmp; | ||
| 495 | } | ||
| 496 | } | 499 | } |
| 497 | command_arguments = tmp; | ||
| 498 | tmp = NULL; | ||
| 499 | 500 | ||
| 500 | debug_info("command_arguments(%d): %s", command->argc, command_arguments); | 501 | debug_info("command_arguments(%d): %s", command->argc, command_arguments); |
| 501 | 502 | ||
| 502 | /* encode command arguments, add checksum if required and assemble entire command */ | 503 | /* encode command arguments, add checksum if required and assemble entire command */ |
| 503 | debugserver_format_command("$", command->name, command_arguments, !client->noack_mode, &send_buffer, &send_buffer_size); | 504 | debugserver_format_command("$", command->name, command_arguments, 1, &send_buffer, &send_buffer_size); |
| 504 | 505 | ||
| 505 | debug_info("sending encoded command: %s", send_buffer); | 506 | debug_info("sending encoded command: %s", send_buffer); |
| 506 | 507 | ||
