Skip to content

Commit

Permalink
beforechanges
Browse files Browse the repository at this point in the history
  • Loading branch information
nearohen committed Mar 28, 2024
1 parent 5e76045 commit 60f4f45
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ idevicerestore_SOURCES = \
restore.c restore.h \
asr.c asr.h \
fdr.c fdr.h \
ace3.c ace3.h \
limera1n_payload.h \
limera1n.c limera1n.h \
download.c download.h \
Expand Down
21 changes: 8 additions & 13 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,28 @@ static int debug_disabled = 0;

void info(const char* format, ...)
{
if (info_disabled) return;

va_list vargs;
va_start(vargs, format);
vfprintf((info_stream) ? info_stream : stdout, format, vargs);
vfprintf((debug_stream) ? debug_stream : stderr, format, vargs);
va_end(vargs);
fflush(stderr);
}

void error(const char* format, ...)
{
va_list vargs, vargs2;

printf("format format:%s\n",format);
va_list vargs;
va_start(vargs, format);
va_copy(vargs2, vargs);
vsnprintf(idevicerestore_err_buff, idevicerestore_err_buff_size, format, vargs);
vfprintf((debug_stream) ? debug_stream : stderr, format, vargs);
va_end(vargs);
if (!error_disabled) {
vfprintf((error_stream) ? error_stream : stderr, format, vargs2);
}
va_end(vargs2);
fflush(stderr);
}

void debug(const char* format, ...)
{
if (debug_disabled) return;
if (!idevicerestore_debug) {
return;
}

va_list vargs;
va_start(vargs, format);
vfprintf((debug_stream) ? debug_stream : stderr, format, vargs);
Expand Down
2 changes: 1 addition & 1 deletion src/dfu.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int dfu_send_buffer(struct idevicerestore_client_t* client, unsigned char* buffe
int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component)
{
char* path = NULL;

debug("dfu_send_component");
// Use a specific TSS ticket for the Ap,LocalPolicy component
plist_t tss = client->tss;
if (strcmp(component, "Ap,LocalPolicy") == 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/idevicerestore.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define SHA384 sha384
#endif

#include "ace3.h"
#include "dfu.h"
#include "tss.h"
#include "img3.h"
Expand Down Expand Up @@ -1218,7 +1219,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client)

// if the device is in normal mode, place device into recovery mode
if (client->mode == MODE_NORMAL) {
info("Entering recovery mode...\n");
info("Entering recovery mode... WELL\n");
if (normal_enter_recovery(client) < 0) {
error("ERROR: Unable to place device into recovery mode from normal mode\n");
if (client->tss)
Expand Down
21 changes: 13 additions & 8 deletions src/normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,18 @@ irecv_device_t normal_get_irecv_device(struct idevicerestore_client_t* client)

int normal_enter_recovery(struct idevicerestore_client_t* client)
{
printf("0\n");
idevice_t device = NULL;
lockdownd_client_t lockdown = NULL;
idevice_error_t device_error = IDEVICE_E_SUCCESS;
lockdownd_error_t lockdown_error = LOCKDOWN_E_SUCCESS;

error("1");
device_error = idevice_new(&device, client->udid);
if (device_error != IDEVICE_E_SUCCESS) {
error("ERROR: Unable to find device\n");
return -1;
}

error("2");
lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore");
if (lockdown_error != LOCKDOWN_E_SUCCESS) {
error("ERROR: Unable to connect to lockdownd: %s (%d)\n", lockdownd_strerror(lockdown_error), lockdown_error);
Expand All @@ -242,7 +243,7 @@ int normal_enter_recovery(struct idevicerestore_client_t* client)
//if (lockdown_error != LOCKDOWN_E_SUCCESS) {
// error("WARNING: Could not unpair device\n");
//}

error("3");
lockdown_error = lockdownd_enter_recovery(lockdown);
if (lockdown_error == LOCKDOWN_E_SESSION_INACTIVE) {
lockdownd_client_free(lockdown);
Expand All @@ -254,19 +255,23 @@ int normal_enter_recovery(struct idevicerestore_client_t* client)
}
lockdown_error = lockdownd_enter_recovery(lockdown);
}
error("5");
if (lockdown_error != LOCKDOWN_E_SUCCESS) {
error("ERROR: Unable to place device in recovery mode: %s (%d)\n", lockdownd_strerror(lockdown_error), lockdown_error);
lockdownd_client_free(lockdown);
idevice_free(device);
return -1;
}

lockdownd_client_free(lockdown);
idevice_free(device);
error("lockdownd_client_free");
//lockdownd_client_free(lockdown);
error("idevice_free");
//idevice_free(device);
error("7");
lockdown = NULL;
device = NULL;

error("mutex_lock");
mutex_lock(&client->device_event_mutex);
error("Waiting");
debug("DEBUG: Waiting for device to disconnect...4\n");
cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 60000);
int tries = 3 ;
Expand Down Expand Up @@ -301,7 +306,7 @@ int normal_enter_recovery(struct idevicerestore_client_t* client)
error("ERROR: Unable to enter recovery mode\n");
return -1;
}

error("7");
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ int recovery_send_component(struct idevicerestore_client_t* client, plist_t buil
unsigned char* data = NULL;
char* path = NULL;
irecv_error_t err = 0;

debug("recovery_send_component");
if (client->tss) {
if (tss_response_get_path_by_entry(client->tss, component, &path) < 0) {
debug("NOTE: No path for component %s in TSS, will fetch from build_identity\n", component);
Expand Down
15 changes: 9 additions & 6 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ int restore_send_component(restored_client_t restore, struct idevicerestore_clie
plist_t blob = NULL;
plist_t dict = NULL;
restored_error_t restore_error = RESTORE_E_SUCCESS;

debug("recovery_send_component 2");
if (component_name == NULL) {
component_name = component;
}
Expand All @@ -1061,6 +1061,7 @@ int restore_send_component(restored_client_t restore, struct idevicerestore_clie
}
}
if (!path) {
debug("no Path");
if (build_identity_get_component_path(build_identity, component, &path) < 0) {
error("ERROR: Unable to find %s path from build identity\n", component);
return -1;
Expand All @@ -1069,6 +1070,7 @@ int restore_send_component(restored_client_t restore, struct idevicerestore_clie

unsigned char* component_data = NULL;
unsigned int component_size = 0;
debug("extract_component");
int ret = extract_component(client->ipsw, path, &component_data, &component_size);
free(path);
path = NULL;
Expand Down Expand Up @@ -1123,14 +1125,14 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t*
plist_t norimage = NULL;
plist_t firmware_files = NULL;
int flash_version_1 = 0;

debug("restore_send_nor");
info("About to send NORData...\n");

plist_t arguments = plist_dict_get_item(message, "Arguments");
if (arguments && plist_get_node_type(arguments) == PLIST_DICT) {
flash_version_1 = plist_dict_get_item(arguments, "FlashVersion1") ? 1 : 0;
}

if (client->tss) {
if (tss_response_get_path_by_entry(client->tss, "LLB", &llb_path) < 0) {
debug("NOTE: Could not get LLB path from TSS data, will fetch from build identity\n");
Expand Down Expand Up @@ -3533,7 +3535,7 @@ int restore_send_personalized_boot_object_v3(restored_client_t restore, struct i
plist_t dict = NULL;
restored_error_t restore_error = RESTORE_E_SUCCESS;

info("About to send %s...\n", component);
info("boot_object_v3 About to send %s...\n", component);

if (strcmp(image_name, "__GlobalManifest__") == 0) {
int ret = extract_global_manifest(client, build_identity, NULL, &data, &size);
Expand Down Expand Up @@ -3614,6 +3616,7 @@ int restore_send_personalized_boot_object_v3(restored_client_t restore, struct i

int restore_send_source_boot_object_v4(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg, plist_t build_identity)
{
debug("restore_send_source_boot_object_v4");
debug_plist(msg);

char *image_name = NULL;
Expand All @@ -3638,7 +3641,7 @@ int restore_send_source_boot_object_v4(restored_client_t restore, struct idevice
plist_t dict = NULL;
restored_error_t restore_error = RESTORE_E_SUCCESS;

info("About to send %s...\n", component);
info("ource_boot_object_v4 About to send %s...\n", component);

if (strcmp(image_name, "__GlobalManifest__") == 0) {
char *variant = NULL;
Expand Down Expand Up @@ -3679,7 +3682,7 @@ int restore_send_source_boot_object_v4(restored_client_t restore, struct idevice
return -1;
}

info("Sending %s now...\n", component);
info("Sending %s now... path:%s\n", component,path ? path : "null");

if (ipsw_extract_send(client->ipsw, path, 8192, (ipsw_send_cb)_restore_send_file_data, restore) < 0) {
free(path);
Expand Down
1 change: 1 addition & 0 deletions src/tss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,7 @@ int tss_response_get_baseband_ticket(plist_t response, unsigned char** ticket, u

int tss_response_get_path_by_entry(plist_t response, const char* entry, char** path)
{
debug("tss_response_get_path_by_entry %s %s ",entry ? entry : "null",path ? path : "null");
char* path_string = NULL;
plist_t path_node = NULL;
plist_t entry_node = NULL;
Expand Down

0 comments on commit 60f4f45

Please sign in to comment.