]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
Dump1k now writes keys to dumpdata.bin even when they are masked with zeroes in a...
[proxmark3-svn] / client / cmdhfmf.c
index 742b7b3b02dbe90f53963c1542b4114c77525e74..9bfa055bcdd4d7781fb71fcd944f8def006827d6 100644 (file)
@@ -330,7 +330,6 @@ int CmdHF14AMfDump1k(const char *Cmd)
        \r
        for (i=0 ; i<16 ; i++) {\r
                for (j=0 ; j<4 ; j++) {\r
-                       \r
                        if (j == 3){\r
                                UsbCommand c = {CMD_MIFARE_READBL, {i*4 + j, 0, 0}};\r
                                memcpy(c.d.asBytes, keyA[i], 6);\r
@@ -358,6 +357,20 @@ int CmdHF14AMfDump1k(const char *Cmd)
                        if (resp != NULL) {\r
                                uint8_t isOK  = resp->arg[0] & 0xff;\r
                                uint8_t *data  = resp->d.asBytes;\r
+                               if (j == 3) {\r
+                                       data[0]  = (keyA[i][0]);\r
+                                       data[1]  = (keyA[i][1]);\r
+                                       data[2]  = (keyA[i][2]);\r
+                                       data[3]  = (keyA[i][3]);\r
+                                       data[4]  = (keyA[i][4]);\r
+                                       data[5]  = (keyA[i][5]);\r
+                                       data[10] = (keyB[i][0]);\r
+                                       data[11] = (keyB[i][1]);\r
+                                       data[12] = (keyB[i][2]);\r
+                                       data[13] = (keyB[i][3]);\r
+                                       data[14] = (keyB[i][4]);\r
+                                       data[15] = (keyB[i][5]);\r
+                               }\r
                                if (isOK) {\r
                                        fwrite ( data, 1, 16, fout );\r
                                }\r
@@ -381,20 +394,15 @@ int CmdHF14AMfRestore1k(const char *Cmd)
 {\r
 \r
        int i,j;\r
-       uint8_t blockNo = 0;\r
        uint8_t keyType = 0;\r
        uint8_t key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\r
        uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\r
        uint8_t keyA[16][6];\r
        uint8_t keyB[16][6];\r
        \r
-       char cmdp = 0x00;\r
-       \r
        FILE *fdump;\r
        FILE *fkeys;\r
        \r
-       FILE *fdebug = fopen("debug.bin","wb");\r
-       \r
        if ((fdump = fopen("dumpdata.bin","rb")) == NULL) {\r
                PrintAndLog("Could not find file dump.bin");\r
                return 1;\r
@@ -472,6 +480,8 @@ int CmdHF14AMfNested(const char *Cmd)
        \r
        int createDumpFile = 0;\r
        FILE *fkeys;\r
+       uint8_t standart[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\r
+       uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};\r
        \r
        char cmdp, ctmp;\r
 \r
@@ -524,10 +534,12 @@ int CmdHF14AMfNested(const char *Cmd)
        }\r
 \r
        ctmp = param_getchar(Cmd, 4);\r
-       if (ctmp == 't' || ctmp == 'T') transferToEml = 1;\r
+       if              (ctmp == 't' || ctmp == 'T') transferToEml = 1;\r
+       else if (ctmp == 'd' || ctmp == 'D') createDumpFile = 1;\r
+       \r
        ctmp = param_getchar(Cmd, 6);\r
        transferToEml |= (ctmp == 't' || ctmp == 'T');\r
-       createDumpFile |= (ctmp == 'd' || ctmp == 'D');\r
+       transferToEml |= (ctmp == 'd' || ctmp == 'D');\r
        \r
        PrintAndLog("--block no:%02x key type:%02x key:%s etrans:%d", blockNo, keyType, sprint_hex(key, 6), transferToEml);\r
        if (cmdp == 'o')\r
@@ -563,8 +575,8 @@ int CmdHF14AMfNested(const char *Cmd)
                } else {\r
                        PrintAndLog("No valid key found");\r
                }\r
-       } else  // ------------------------------------  multiple sectors working\r
-       {\r
+       }\r
+       else { // ------------------------------------  multiple sectors working\r
                blDiff = blockNo % 4;\r
                PrintAndLog("Block shift=%d", blDiff);\r
                e_sector = calloc(SectorsCnt, sizeof(sector));\r
@@ -592,7 +604,6 @@ int CmdHF14AMfNested(const char *Cmd)
                        }\r
                } \r
                \r
-               \r
                // nested sectors\r
                iterations = 0;\r
                PrintAndLog("nested...");\r
@@ -639,17 +650,31 @@ int CmdHF14AMfNested(const char *Cmd)
                        }               \r
                }\r
                \r
+               // Create dump file\r
                if (createDumpFile) {\r
                        if ((fkeys = fopen("dumpkeys.bin","wb")) == NULL) { \r
-                               rintAndLog("Could not create file keys.bin");\r
+                               PrintAndLog("Could not create file keys.bin");\r
                                free(e_sector);\r
                                return 1;\r
                        }\r
+                       PrintAndLog("Printing keys to bynary file dumpkeys.bin...");\r
                        for(i=0; i<16; i++) {\r
-                               fwrite ( e_sector[i].Key[0], sizeof(e_sector[i].Key[0]), 1, fkeys );\r
+                               if (e_sector[i].foundKey[0]){\r
+                                       num_to_bytes(e_sector[i].Key[0], 6, tempkey);\r
+                                       fwrite ( tempkey, 1, 6, fkeys );\r
+                               }\r
+                               else{\r
+                                       fwrite ( &standart, 1, 6, fkeys );\r
+                               }\r
                        }\r
                        for(i=0; i<16; i++) {\r
-                               fwrite ( e_sector[i].Key[1], sizeof(e_sector[i].Key[1]), 1, fkeys );\r
+                               if (e_sector[i].foundKey[1]){\r
+                                       num_to_bytes(e_sector[i].Key[1], 6, tempkey);\r
+                                       fwrite ( tempkey, 1, 6, fkeys );\r
+                               }\r
+                               else{\r
+                                       fwrite ( &standart, 1, 6, fkeys );\r
+                               }\r
                        }\r
                        fclose(fkeys);\r
                }\r
Impressum, Datenschutz