X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/69e312afe78573297567a4cbb9638e15618276e9..a70fcfb65597ff22e4b2b8735d1afa550386603c:/client/cmdlft55xx.c diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 2f8e2e2f..d104d7d7 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -10,7 +10,7 @@ #include #include #include -#include +//#include #include "proxmark3.h" #include "ui.h" #include "graph.h" @@ -22,8 +22,6 @@ #include "util.h" #include "data.h" #include "lfdemod.h" -#include "../common/crc.h" -#include "../common/iso14443crc.h" #include "cmdhf14a.h" #define T55x7_CONFIGURATION_BLOCK 0x00 @@ -1379,8 +1377,9 @@ int CmdT55xxBruteForce(const char *Cmd) { char buf[9]; char filename[FILE_PATH_SIZE]={0}; int keycnt = 0; + int c; uint8_t stKeyBlock = 20; - uint8_t *keyBlock = NULL, *p; + uint8_t *keyBlock = NULL, *p = NULL; keyBlock = calloc(stKeyBlock, 6); if (keyBlock == NULL) return 1; @@ -1389,7 +1388,10 @@ int CmdT55xxBruteForce(const char *Cmd) { bool found = false; char cmdp = param_getchar(Cmd, 0); - if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_bruteforce(); + if (cmdp == 'h' || cmdp == 'H') { + free(keyBlock); + return usage_t55xx_bruteforce(); + } if (cmdp == 'i' || cmdp == 'I') { @@ -1425,6 +1427,7 @@ int CmdT55xxBruteForce(const char *Cmd) { if (!p) { PrintAndLog("Cannot allocate memory for defaultKeys"); free(keyBlock); + fclose(f); return 2; } keyBlock = p; @@ -1439,6 +1442,7 @@ int CmdT55xxBruteForce(const char *Cmd) { if (keycnt == 0) { PrintAndLog("No keys found in file"); + free(keyBlock); return 1; } PrintAndLog("Loaded %d keys", keycnt); @@ -1448,8 +1452,10 @@ int CmdT55xxBruteForce(const char *Cmd) { for (uint16_t c = 0; c < keycnt; ++c ) { if (ukbhit()) { - getchar(); + c = getchar(); + (void)c; printf("\naborted via keyboard!\n"); + free(keyBlock); return 0; } @@ -1460,6 +1466,7 @@ int CmdT55xxBruteForce(const char *Cmd) { if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) { PrintAndLog("Aquireing data from device failed. Quitting"); + free(keyBlock); return 0; } @@ -1467,10 +1474,12 @@ int CmdT55xxBruteForce(const char *Cmd) { if ( found ) { PrintAndLog("Found valid password: [%08X]", testpwd); + free(keyBlock); return 0; } } PrintAndLog("Password NOT found."); + free(keyBlock); return 0; } @@ -1480,7 +1489,10 @@ int CmdT55xxBruteForce(const char *Cmd) { start_password = param_get32ex(Cmd, 0, 0, 16); end_password = param_get32ex(Cmd, 1, 0, 16); - if ( start_password >= end_password ) return usage_t55xx_bruteforce(); + if ( start_password >= end_password ) { + free(keyBlock); + return usage_t55xx_bruteforce(); + } PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password); @@ -1491,13 +1503,16 @@ int CmdT55xxBruteForce(const char *Cmd) { printf("."); fflush(stdout); if (ukbhit()) { - getchar(); + c = getchar(); + (void)c; printf("\naborted via keyboard!\n"); + free(keyBlock); return 0; } if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) { PrintAndLog("Aquireing data from device failed. Quitting"); + free(keyBlock); return 0; } found = tryDetectModulation(); @@ -1512,6 +1527,8 @@ int CmdT55xxBruteForce(const char *Cmd) { PrintAndLog("Found valid password: [%08x]", i); else PrintAndLog("Password NOT found. Last tried: [%08x]", --i); + + free(keyBlock); return 0; } @@ -1533,11 +1550,12 @@ static command_t CommandTable[] = { }; int CmdLFT55XX(const char *Cmd) { - CmdsParse(CommandTable, Cmd); - return 0; + clearCommandBuffer(); + CmdsParse(CommandTable, Cmd); + return 0; } int CmdHelp(const char *Cmd) { - CmdsHelp(CommandTable); - return 0; + CmdsHelp(CommandTable); + return 0; }