From eba13925e437fce57107bd751d78004f4bbfb5b6 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 30 Aug 2019 08:53:04 +0200 Subject: [PATCH] move bf_bench_data.bin to resources/hardnested_* --- client/hardnested/hardnested_bruteforce.c | 29 ++++++++++++------ .../hardnested_bf_bench_data.bin} | Bin 2 files changed, 19 insertions(+), 10 deletions(-) rename client/{hardnested/bf_bench_data.bin => resources/hardnested_bf_bench_data.bin} (100%) diff --git a/client/hardnested/hardnested_bruteforce.c b/client/hardnested/hardnested_bruteforce.c index 5f93d4811..96211f47f 100644 --- a/client/hardnested/hardnested_bruteforce.c +++ b/client/hardnested/hardnested_bruteforce.c @@ -65,11 +65,13 @@ THE SOFTWARE. #include "util_posix.h" #include "crapto1/crapto1.h" #include "parity.h" +#include "fileutils.h" +#include "pm3_cmd.h" #define NUM_BRUTE_FORCE_THREADS (num_CPUs()) #define DEFAULT_BRUTE_FORCE_RATE (120000000.0) // if benchmark doesn't succeed #define TEST_BENCH_SIZE (6000) // number of odd and even states for brute force benchmark -#define TEST_BENCH_FILENAME "hardnested/bf_bench_data.bin" +#define TEST_BENCH_FILENAME "hardnested_bf_bench_data.bin" //#define WRITE_BENCH_FILE // debugging options @@ -265,8 +267,12 @@ void prepare_bf_test_nonces(noncelist_t *nonces, uint8_t best_first_byte) { #if defined (WRITE_BENCH_FILE) static void write_benchfile(statelist_t *candidates) { - printf("Writing brute force benchmark data..."); - FILE *benchfile = fopen(TEST_BENCH_FILENAME, "wb"); + PrintAndLogEx(NORMAL, "Writing brute force benchmark data in " RESOURCES_SUBDIR " subdirectory..."); + FILE *benchfile = fopen(RESOURCES_SUBDIR TEST_BENCH_FILENAME, "wb"); + if (benchfile == NULL) { + PrintAndLogEx(ERR, "Can't write " RESOURCES_SUBDIR TEST_BENCH_FILENAME", abort!"); + return; + } fwrite(&nonces_to_bruteforce, 1, sizeof(nonces_to_bruteforce), benchfile); for (uint32_t i = 0; i < nonces_to_bruteforce; i++) { fwrite(&(bf_test_nonce[i]), 1, sizeof(bf_test_nonce[i]), benchfile); @@ -283,7 +289,7 @@ static void write_benchfile(statelist_t *candidates) { fwrite(&(candidates->states[ODD_STATE][i]), 1, sizeof(uint32_t), benchfile); } fclose(benchfile); - printf("done.\n"); + PrintAndLogEx(NORMAL, "Done"); } #endif @@ -360,14 +366,17 @@ static bool read_bench_data(statelist_t *test_candidates) { uint32_t num_states = 0; uint32_t states_read = 0; - char bench_file_path[strlen(get_my_executable_directory()) + strlen(TEST_BENCH_FILENAME) + 1]; - strcpy(bench_file_path, get_my_executable_directory()); - strcat(bench_file_path, TEST_BENCH_FILENAME); - - FILE *benchfile = fopen(bench_file_path, "rb"); - if (benchfile == NULL) { + char *path; + if (searchFile(&path, RESOURCES_SUBDIR, TEST_BENCH_FILENAME, "") != PM3_SUCCESS) { return false; } + + FILE *benchfile = fopen(path, "rb"); + if (benchfile == NULL) { + free(path); + return false; + } + free(path); bytes_read = fread(&nonces_to_bruteforce, 1, sizeof(nonces_to_bruteforce), benchfile); if (bytes_read != sizeof(nonces_to_bruteforce)) { fclose(benchfile); diff --git a/client/hardnested/bf_bench_data.bin b/client/resources/hardnested_bf_bench_data.bin similarity index 100% rename from client/hardnested/bf_bench_data.bin rename to client/resources/hardnested_bf_bench_data.bin