From ee432c793272260cd57ef8218745b36e7b7ae617 Mon Sep 17 00:00:00 2001 From: unkernet Date: Sun, 27 Aug 2017 20:25:54 +0300 Subject: [PATCH] Add progress display to solve_bs and solve_piwi_bs --- solve_bs.c | 19 +++++++++++++++++-- solve_piwi_bs.c | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/solve_bs.c b/solve_bs.c index ccfcd00..04b9fe1 100644 --- a/solve_bs.c +++ b/solve_bs.c @@ -12,6 +12,7 @@ #define lli PRIi64 #define llu PRIu64 #define lu PRIu32 +#define VT100_cleareol "\r\33[2K" uint32_t **space; size_t thread_count = 1; @@ -51,20 +52,27 @@ void* crack_states_thread(void* x){ break; } else if(keys_found){ break; - } else { - printf("Cracking... %6.02f%%\n", (total_states_tested/(total_states/100.0))); } } return NULL; } +void notify_status_offline(int sig){ + printf(VT100_cleareol "Cracking... %6.02f%%", (100.0*total_states_tested/(total_states))); + alarm(1); + fflush(stdout); + signal(SIGALRM, notify_status_offline); +} + int main(int argc, char* argv[]){ if(argc != 3){ printf("Usage: %s \n", argv[0]); return -1; } + printf("Reading nonces...\n"); uint64_t *nonces = readnonces(argv[1]); uint32_t uid = strtoul(argv[2], NULL, 16); + printf("Deriving search space...\n"); space = craptev1_get_space(nonces, 95, uid); total_states = craptev1_sizeof_space(space); @@ -108,12 +116,19 @@ int main(int argc, char* argv[]){ keys_found = 0; printf("Starting %zu threads to test %"llu" states\n", thread_count, total_states); + + signal(SIGALRM, notify_status_offline); + alarm(1); + for(i = 0; i < thread_count; i++){ pthread_create(&threads[i], NULL, crack_states_thread, (void*) i); } for(i = 0; i < thread_count; i++){ pthread_join(threads[i], 0); } + + alarm(0); + printf("Tested %"llu" states\n", total_states_tested); craptev1_destroy_space(space); diff --git a/solve_piwi_bs.c b/solve_piwi_bs.c index f20ef27..9f16ce4 100644 --- a/solve_piwi_bs.c +++ b/solve_piwi_bs.c @@ -12,6 +12,7 @@ #define lli PRIi64 #define llu PRIu64 #define lu PRIu32 +#define VT100_cleareol "\r\33[2K" uint64_t split(uint8_t p){ return (((p & 0x8) >>3 )| ((p & 0x4) >> 2) << 8 | ((p & 0x2) >> 1) << 16 | (p & 0x1) << 24 ); @@ -54,19 +55,26 @@ void* crack_states_thread(void* x){ break; } else if(keys_found){ break; - } else { - printf("Cracking... %6.02f%%\n", (100.0*total_states_tested/(total_states))); } } return NULL; } +void notify_status_offline(int sig){ + printf(VT100_cleareol "Cracking... %6.02f%%", (100.0*total_states_tested/(total_states))); + alarm(1); + fflush(stdout); + signal(SIGALRM, notify_status_offline); +} + int main(int argc, char* argv[]){ if(argc != 2){ printf("Usage: %s \n", argv[0]); return -1; } + printf("Reading nonces...\n"); uint64_t *nonces = readnonces(argv[1]); + printf("Deriving search space...\n"); space = craptev1_get_space(nonces, 95, uid); total_states = craptev1_sizeof_space(space); @@ -111,12 +119,19 @@ int main(int argc, char* argv[]){ keys_found = 0; printf("Starting %u threads to test %"llu" states\n", thread_count, total_states); + + signal(SIGALRM, notify_status_offline); + alarm(1); + for(i = 0; i < thread_count; i++){ pthread_create(&threads[i], NULL, crack_states_thread, (void*) i); } for(i = 0; i < thread_count; i++){ pthread_join(threads[i], 0); } + + alarm(0); + printf("Tested %"llu" states\n", total_states_tested); craptev1_destroy_space(space);