From c850b5376d1f68528f76b42710d6c4e21dac4e0c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 9 Apr 2021 15:41:00 +0200 Subject: [PATCH] crack5opencl - textual --- tools/hitag2crack/common/ht2crackutils.h | 2 +- tools/hitag2crack/crack5opencl/threads.c | 37 +++++++++--------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/tools/hitag2crack/common/ht2crackutils.h b/tools/hitag2crack/common/ht2crackutils.h index b2c50beaf..1ce71af1d 100644 --- a/tools/hitag2crack/common/ht2crackutils.h +++ b/tools/hitag2crack/common/ht2crackutils.h @@ -6,7 +6,7 @@ #include #include #include -#ifndef (__MINGW64__) +#ifndef __MINGW64__ # include #endif #include diff --git a/tools/hitag2crack/crack5opencl/threads.c b/tools/hitag2crack/crack5opencl/threads.c index 963425cff..f44861cc4 100644 --- a/tools/hitag2crack/crack5opencl/threads.c +++ b/tools/hitag2crack/crack5opencl/threads.c @@ -427,20 +427,6 @@ int thread_stop(thread_ctx_t *ctx) { return 0; } -__attribute__((format(printf, 1, 2))) -void tprintf(const char *restrict format, ...) { - flockfile(stdout); - - va_list va_args; - va_start(va_args, format); - vprintf(format, va_args); - va_end(va_args); - - funlockfile(stdout); - - fflush(stdout); -} - const char *thread_status_strdesc(thread_status_t s) { switch (s) { case TH_START: @@ -470,13 +456,13 @@ bool thread_setEnd(thread_ctx_t *ctx, thread_args_t *t_arg) { for (z = 0; z < ctx->thread_count; z++) { int m_ret = pthread_mutex_lock(&ctx->thread_mutexs[z]); if (m_ret != 0) { - tprintf("[%zu] [%s] Error: pthread_mutex_lock() failed (%d): %s\n", z, __func__, m_ret, strerror(m_ret)); + printf("[%zu] [%s] Error: pthread_mutex_lock() failed (%d): %s\n", z, __func__, m_ret, strerror(m_ret)); } thread_status_t tmp = t_arg[z].status; #if DEBUGME > 0 - tprintf("[%zu] [%s] Thread status: %s\n", z, __func__, thread_status_strdesc(t_arg[z].status)); + printf("[%zu] [%s] Thread status: %s\n", z, __func__, thread_status_strdesc(t_arg[z].status)); #endif if (tmp == TH_FOUND_KEY || tmp == TH_END || tmp == TH_ERROR) { @@ -486,19 +472,19 @@ bool thread_setEnd(thread_ctx_t *ctx, thread_args_t *t_arg) { } #if DEBUGME > 0 - tprintf("[%zu] [%s] Set thread status to TH_END\n", z, __func__); + printf("[%zu] [%s] Set thread status to TH_END\n", z, __func__); #endif t_arg[z].status = TH_END; if (tmp == TH_WAIT) { #if DEBUGME > 0 - tprintf("[%zu] [%s] Send cond_signal to thread\n", z, __func__); + printf("[%zu] [%s] Send cond_signal to thread\n", z, __func__); #endif c_ret = pthread_cond_signal(&ctx->thread_conds[z]); if (c_ret != 0) { - tprintf("[%zu] [%s] Error: pthread_cond_signal() failed (%d): %s\n", z, __func__, c_ret, strerror(c_ret)); + printf("[%zu] [%s] Error: pthread_cond_signal() failed (%d): %s\n", z, __func__, c_ret, strerror(c_ret)); } } @@ -529,17 +515,19 @@ void *computing_process(void *arg) { off = wu.off; a->slice = wu.id + 1; + float progress = (((wu.id + 1) * 100.0) / wu.max); if (ctx->queue_ctx.queue_type == QUEUE_TYPE_RANDOM) { + #if DEBUGME > 0 printf("[%zu] Slice %zu (off %zu), max %zu, remain %zu slice(s)\n", z, wu.id + 1, wu.off, wu.max, wu.rem); #else - printf("[%zu] Slice %zu/%zu (%zu remain)\n", z, wu.id + 1, wu.max, wu.rem); + printf("\r[%zu] Slice %zu/%zu (%zu remain) ( %2.1f%% )", z, wu.id + 1, wu.max, wu.rem, progress); #endif // DEBUGME } else { #if DEBUGME > 0 printf("[%zu] Slice %zu/%zu, off %zu\n", z, wu.id + 1, wu.max, wu.off); #else - printf("[%zu] Slice %zu/%zu\n", z, wu.id + 1, wu.max); + printf("\r[%zu] Slice %zu/%zu ( %2.1f%% )", z, wu.id + 1, wu.max, progress); #endif // DEBUGME } fflush(stdout); @@ -577,6 +565,7 @@ void *computing_process(void *arg) { } pthread_exit(NULL); + return NULL; } void *computing_process_async(void *arg) { @@ -684,17 +673,18 @@ void *computing_process_async(void *arg) { off = wu.off; a->slice = wu.id + 1; + float progress = (((wu.id + 1) * 100.0) / wu.max); if (ctx->queue_ctx.queue_type == QUEUE_TYPE_RANDOM) { #if DEBUGME > 0 printf("[%zu] Slice %zu (off %zu), max %zu, remain %zu slice(s)\n", z, wu.id + 1, wu.off, wu.max, wu.rem); #else - printf("[%zu] Slice %zu/%zu (%zu remain)\n", z, wu.id + 1, wu.max, wu.rem); + printf("[%zu] Slice %zu/%zu (%zu remain) ( %2.1f%% )", z, wu.id + 1, wu.max, wu.rem, progress); #endif // DEBUGME } else { #if DEBUGME > 0 printf("[%zu] Slice %zu/%zu, off %zu\n", z, wu.id + 1, wu.max, wu.off); #else - printf("[%zu] Slice %zu/%zu\n", z, wu.id + 1, wu.max); + printf("\r[%zu] Slice %zu/%zu ( %2.1f%% )", z, wu.id + 1, wu.max, progress); #endif // DEBUGME } @@ -874,4 +864,5 @@ void *computing_process_async(void *arg) { } while (status < TH_FOUND_KEY); pthread_exit(NULL); + return NULL; }