From e259b26d60b281ad5d25aaa63b34e4611c5d434b Mon Sep 17 00:00:00 2001 From: Matthias Konrath Date: Wed, 28 Aug 2019 10:45:45 +0200 Subject: [PATCH] Streamlined the naming conventen and types. --- client/cmdhfmf.c | 6 +++++- client/cmdlft55xx.c | 2 +- client/fileutils.c | 14 +++++++------- client/fileutils.h | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 66aca7421..11aded711 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1786,7 +1786,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { // Load the dictionary if (strlen(filename) != 0) { - int res = loadFileDICTIONARY_safe(filename, &keyBlock, 6, &key_cnt); + int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 6, &key_cnt); if (res != PM3_SUCCESS || key_cnt <= 0 || keyBlock == NULL) { PrintAndLogEx(FAILED, "An error occurred while loading the dictionary! (we will use the default keys now)"); if (keyBlock != NULL) free(keyBlock); @@ -1806,6 +1806,10 @@ useDefaultKeys: key_cnt = ARRAYLEN(g_mifare_default_keys); } + for (int k = 0; k < key_cnt; k++) { + PrintAndLogEx(SUCCESS, "ID: %d KEY: %s", k, sprint_hex((keyBlock + (6 * k)), sizeof(key))); + } + // Use the dictionary to find sector keys on the card PrintAndLogEx(INFO, "Enter dictionary run..."); diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index f17c8e192..965a5db0b 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -2128,7 +2128,7 @@ static int CmdT55xxChkPwds(const char *Cmd) { if (use_pwd_file) { uint16_t keycount = 0; - int res = loadFileDICTIONARY_safe(filename, &keyBlock, 4, &keycount); + int res = loadFileDICTIONARY_safe(filename, (void**) &keyBlock, 4, &keycount); if (res != PM3_SUCCESS || keycount <= 0 || keyBlock == NULL) { PrintAndLogEx(WARNING, "No keys found in file"); if (keyBlock != NULL) free(keyBlock); diff --git a/client/fileutils.c b/client/fileutils.c index 787ce0cfb..1b2073ed2 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -649,7 +649,7 @@ out: return retval; } -int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t keylen, uint16_t *keycnt) { +int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt) { int block_size = 512; int allocation_size = block_size; @@ -673,8 +673,8 @@ int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t k char line[255]; // allocate some space for the dictionary - *data = (uint8_t*) calloc(keylen * allocation_size, sizeof(uint8_t)); - if (*data == NULL) return PM3_EFILE; + *pdata = calloc(keylen * allocation_size, sizeof(uint8_t)); + if (*pdata == NULL) return PM3_EFILE; FILE *f = fopen(path, "r"); if (!f) { @@ -687,12 +687,12 @@ int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t k // check if we have enough space (if not allocate more) if ((*keycnt) >= allocation_size) { allocation_size += block_size; - *data = (uint8_t*) realloc((void*) *data, keylen * allocation_size * sizeof(uint8_t)); - if (*data == NULL) { + *pdata = realloc(*pdata, keylen * allocation_size * sizeof(uint8_t)); + if (*pdata == NULL) { return PM3_EFILE; } else { // zero the new memeory (safety first) - memset(*data + counter, 0, block_size); + memset(*pdata + counter, 0, block_size); } } @@ -714,7 +714,7 @@ int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t k uint64_t key = strtoull(line, NULL, 16); - num_to_bytes(key, keylen >> 1, *data + counter); + num_to_bytes(key, keylen >> 1, *pdata + counter); (*keycnt)++; memset(line, 0, sizeof(line)); counter += (keylen >> 1); diff --git a/client/fileutils.h b/client/fileutils.h index 1428c0d8c..d6392c6b1 100644 --- a/client/fileutils.h +++ b/client/fileutils.h @@ -171,7 +171,7 @@ int loadFileDICTIONARY(const char *preferredName, void *data, size_t *datalen, u * @param keylen the number of bytes a key per row is * @return 0 for ok, 1 for failz */ -int loadFileDICTIONARY_safe(const char *preferredName, uint8_t **data, uint8_t keylen, uint16_t *keycnt); +int loadFileDICTIONARY_safe(const char *preferredName, void **pdata, uint8_t keylen, uint16_t *keycnt); /** * @brief Utility function to check and convert old mfu dump format to new