]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdlft55xx.c
Merge remote-tracking branch 'upstream/master' into pm3+reveng
[proxmark3-svn] / client / cmdlft55xx.c
index 348cb229d062501ef269c9946faea68095bdfa7a..dfee9aa6dc46abc80889193c0e334143b5b224db 100644 (file)
@@ -10,7 +10,6 @@
 #include <stdio.h>\r
 #include <string.h>\r
 #include <inttypes.h>\r
 #include <stdio.h>\r
 #include <string.h>\r
 #include <inttypes.h>\r
-//#include <time.h>  //not used - marshmellow\r
 #include "proxmark3.h"\r
 #include "ui.h"\r
 #include "graph.h"\r
 #include "proxmark3.h"\r
 #include "ui.h"\r
 #include "graph.h"\r
@@ -22,8 +21,6 @@
 #include "util.h"\r
 #include "data.h"\r
 #include "lfdemod.h"\r
 #include "util.h"\r
 #include "data.h"\r
 #include "lfdemod.h"\r
-//#include "../common/crc.h"  //not used - marshmellow\r
-//#include "../common/iso14443crc.h" //not used - marshmellow\r
 #include "cmdhf14a.h" //for getTagInfo\r
 \r
 #define T55x7_CONFIGURATION_BLOCK 0x00\r
 #include "cmdhf14a.h" //for getTagInfo\r
 \r
 #define T55x7_CONFIGURATION_BLOCK 0x00\r
@@ -1371,11 +1368,9 @@ int CmdT55xxBruteForce(const char *Cmd) {
        char buf[9];\r
        char filename[FILE_PATH_SIZE]={0};\r
        int keycnt = 0;\r
        char buf[9];\r
        char filename[FILE_PATH_SIZE]={0};\r
        int keycnt = 0;\r
+       int ch;\r
        uint8_t stKeyBlock = 20;\r
        uint8_t stKeyBlock = 20;\r
-       uint8_t *keyBlock = NULL, *p;\r
-       keyBlock = calloc(stKeyBlock, 6);\r
-       if (keyBlock == NULL) return 1;\r
-\r
+       uint8_t *keyBlock = NULL, *p = NULL;\r
        uint32_t start_password = 0x00000000; //start password\r
        uint32_t end_password   = 0xFFFFFFFF; //end   password\r
        bool found = false;\r
        uint32_t start_password = 0x00000000; //start password\r
        uint32_t end_password   = 0xFFFFFFFF; //end   password\r
        bool found = false;\r
@@ -1383,6 +1378,9 @@ int CmdT55xxBruteForce(const char *Cmd) {
        char cmdp = param_getchar(Cmd, 0);\r
        if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_bruteforce();\r
 \r
        char cmdp = param_getchar(Cmd, 0);\r
        if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_bruteforce();\r
 \r
+       keyBlock = calloc(stKeyBlock, 6);\r
+       if (keyBlock == NULL) return 1;\r
+\r
        if (cmdp == 'i' || cmdp == 'I') {\r
 \r
                int len = strlen(Cmd+2);\r
        if (cmdp == 'i' || cmdp == 'I') {\r
 \r
                int len = strlen(Cmd+2);\r
@@ -1417,6 +1415,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
                                if (!p) {\r
                                        PrintAndLog("Cannot allocate memory for defaultKeys");\r
                                        free(keyBlock);\r
                                if (!p) {\r
                                        PrintAndLog("Cannot allocate memory for defaultKeys");\r
                                        free(keyBlock);\r
+                                       fclose(f);\r
                                        return 2;\r
                                }\r
                                keyBlock = p;\r
                                        return 2;\r
                                }\r
                                keyBlock = p;\r
@@ -1431,6 +1430,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
                \r
                if (keycnt == 0) {\r
                        PrintAndLog("No keys found in file");\r
                \r
                if (keycnt == 0) {\r
                        PrintAndLog("No keys found in file");\r
+                       free(keyBlock);\r
                        return 1;\r
                }\r
                PrintAndLog("Loaded %d keys", keycnt);\r
                        return 1;\r
                }\r
                PrintAndLog("Loaded %d keys", keycnt);\r
@@ -1440,8 +1440,10 @@ int CmdT55xxBruteForce(const char *Cmd) {
                for (uint16_t c = 0; c < keycnt; ++c ) {\r
 \r
                        if (ukbhit()) {\r
                for (uint16_t c = 0; c < keycnt; ++c ) {\r
 \r
                        if (ukbhit()) {\r
-                               getchar();\r
+                               ch = getchar();\r
+                               (void)ch;\r
                                printf("\naborted via keyboard!\n");\r
                                printf("\naborted via keyboard!\n");\r
+                               free(keyBlock);\r
                                return 0;\r
                        }\r
 \r
                                return 0;\r
                        }\r
 \r
@@ -1451,6 +1453,7 @@ int CmdT55xxBruteForce(const char *Cmd) {
 \r
                        if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {\r
                                PrintAndLog("Aquireing data from device failed. Quitting");\r
 \r
                        if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {\r
                                PrintAndLog("Aquireing data from device failed. Quitting");\r
+                               free(keyBlock);\r
                                return 0;\r
                        }\r
 \r
                                return 0;\r
                        }\r
 \r
@@ -1458,10 +1461,12 @@ int CmdT55xxBruteForce(const char *Cmd) {
 \r
                        if ( found ) {\r
                                PrintAndLog("Found valid password: [%08X]", testpwd);\r
 \r
                        if ( found ) {\r
                                PrintAndLog("Found valid password: [%08X]", testpwd);\r
+                               free(keyBlock);\r
                                return 0;\r
                        }\r
                }\r
                PrintAndLog("Password NOT found.");\r
                                return 0;\r
                        }\r
                }\r
                PrintAndLog("Password NOT found.");\r
+               free(keyBlock);\r
                return 0;\r
        }\r
 \r
                return 0;\r
        }\r
 \r
@@ -1471,8 +1476,10 @@ int CmdT55xxBruteForce(const char *Cmd) {
        start_password = param_get32ex(Cmd, 0, 0, 16);\r
        end_password = param_get32ex(Cmd, 1, 0, 16);\r
 \r
        start_password = param_get32ex(Cmd, 0, 0, 16);\r
        end_password = param_get32ex(Cmd, 1, 0, 16);\r
 \r
-       if ( start_password >= end_password ) return usage_t55xx_bruteforce();\r
-\r
+       if ( start_password >= end_password ) {\r
+               free(keyBlock);\r
+               return usage_t55xx_bruteforce();\r
+       }\r
        PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password);\r
 \r
        uint32_t i = start_password;\r
        PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password);\r
 \r
        uint32_t i = start_password;\r
@@ -1482,13 +1489,16 @@ int CmdT55xxBruteForce(const char *Cmd) {
                printf(".");\r
                fflush(stdout);\r
                if (ukbhit()) {\r
                printf(".");\r
                fflush(stdout);\r
                if (ukbhit()) {\r
-                       getchar();\r
+                       ch = getchar();\r
+                       (void)ch;\r
                        printf("\naborted via keyboard!\n");\r
                        printf("\naborted via keyboard!\n");\r
+                       free(keyBlock);\r
                        return 0;\r
                }\r
 \r
                if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {\r
                        PrintAndLog("Aquireing data from device failed. Quitting");\r
                        return 0;\r
                }\r
 \r
                if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {\r
                        PrintAndLog("Aquireing data from device failed. Quitting");\r
+                       free(keyBlock);\r
                        return 0;\r
                }\r
                found = tryDetectModulation();\r
                        return 0;\r
                }\r
                found = tryDetectModulation();\r
@@ -1503,6 +1513,8 @@ int CmdT55xxBruteForce(const char *Cmd) {
                PrintAndLog("Found valid password: [%08x]", i);\r
        else\r
                PrintAndLog("Password NOT found. Last tried: [%08x]", --i);\r
                PrintAndLog("Found valid password: [%08x]", i);\r
        else\r
                PrintAndLog("Password NOT found. Last tried: [%08x]", --i);\r
+\r
+       free(keyBlock);\r
        return 0;\r
 }\r
 \r
        return 0;\r
 }\r
 \r
Impressum, Datenschutz