From 9db8bb69f6b106bb70036941384d703461fc7927 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Sun, 12 May 2019 23:06:39 +0100 Subject: [PATCH] restore_session: remove yet one more indent layer --- src/session.c | 215 +++++++++++++++++++++++++------------------------- 1 file changed, 106 insertions(+), 109 deletions(-) diff --git a/src/session.c b/src/session.c index e867789..cd3ad8e 100644 --- a/src/session.c +++ b/src/session.c @@ -118,139 +118,136 @@ int restore_session() /* Get the key1 index value */ if(fgets(line, MAX_LINE_SIZE, fp) == NULL) goto fout; set_p1_index(atoi(line)); - memset(line, 0, MAX_LINE_SIZE); /* Get the key2 index value */ + if(fgets(line, MAX_LINE_SIZE, fp) == NULL) goto fout; + set_p2_index(atoi(line)); + memset(line, 0, MAX_LINE_SIZE); + + /* Get the key status value */ if(fgets(line, MAX_LINE_SIZE, fp) != NULL) { - set_p2_index(atoi(line)); - memset(line, 0, MAX_LINE_SIZE); + set_key_status(atoi(line)); - /* Get the key status value */ - if(fgets(line, MAX_LINE_SIZE, fp) != NULL) + /* Read in all p1 values */ + add = p1_tried = 0; + for(i=0; i= KEY2_WIP */ - if (get_key_status() >= KEY2_WIP && strcmp(get_static_p1(), get_p1(get_p1_index())) != 0) - { - cprintf(INFO, "[!] First half PIN ignored, it was cracked\n"); - } - /* Print message what second half pin ignored if former key status == KEY_DONE */ - if (get_key_status() == KEY_DONE && strcmp(get_static_p2(), get_p2(get_p2_index())) != 0) - { - cprintf(INFO, "[!] Second half PIN ignored, it was cracked\n"); + if (i < get_p2_index()) + { + /* Check the second half has been already tried */ + if (strcmp(get_static_p2(), temp) == 0) + { + p2_tried = 1; + } + } + else if (i == get_p2_index()) + { + /* Check current index of second half is the specified pin + * Yes: do nothing + * No: insert into current index and set add to 1 + */ + if (!p2_tried && strcmp(get_static_p2(), temp) != 0) + { + set_p2(i, get_static_p2()); + add = 1; + } + } + else + { + /* Check former index of second half + * Yes: set add to 0 and continue to next loop; + * No: do nothing + */ + if (strcmp(get_static_p2(), temp) == 0) + { + add = 0; + continue; + } + } } + set_p2(i+add, temp); + } + } + + ret_val = 1; + + /* Print warning message if the specified first or second half PIN was ignored */ + if (get_static_p1()) + { + /* Check the specified 4/8 digit WPS PIN has been already tried */ + if (p1_tried || p2_tried) + { + ret_val = -1; + } + /* Print message what first half pin ignored if former key status >= KEY2_WIP */ + if (get_key_status() >= KEY2_WIP && strcmp(get_static_p1(), get_p1(get_p1_index())) != 0) + { + cprintf(INFO, "[!] First half PIN ignored, it was cracked\n"); + } + /* Print message what second half pin ignored if former key status == KEY_DONE */ + if (get_key_status() == KEY_DONE && strcmp(get_static_p2(), get_p2(get_p2_index())) != 0) + { + cprintf(INFO, "[!] Second half PIN ignored, it was cracked\n"); } } }