]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
removed redundant Dbprintfs from SnoopIso1443a (issue 25)
[proxmark3-svn] / client / cmdhfmf.c
index ed3394e5034f23545092ebcda432ea491b74189f..1a29f8719442a724c1454456cd5eca99740caada 100644 (file)
@@ -259,15 +259,10 @@ int CmdHF14AMfDump1k(const char *Cmd)
 {\r
        int i, j;\r
        \r
-       uint8_t keyType = 0;\r
-       uint8_t c[3][4];\r
        uint8_t keyA[16][6];\r
        uint8_t keyB[16][6];\r
        uint8_t rights[16][4];\r
        \r
-       uint8_t isOK  = 0;\r
-       uint8_t *data  = NULL;\r
-\r
        FILE *fin;\r
        FILE *fout;\r
        \r
@@ -330,7 +325,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 +352,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
@@ -406,7 +414,7 @@ int CmdHF14AMfRestore1k(const char *Cmd)
                fread(keyB[i], 1, 6, fkeys);\r
        }\r
        \r
-       PrintAndLog("going...");\r
+       PrintAndLog("Restoring dumpdata.bin to card");\r
 \r
        for (i=0 ; i<16 ; i++) {\r
                for( j=0 ; j<4 ; j++) {\r
@@ -430,7 +438,17 @@ int CmdHF14AMfRestore1k(const char *Cmd)
                                bldata[15] = (keyB[i][5]);\r
                        }               \r
                        \r
-                       PrintAndLog("writing to block %2d: %s confirm?", i*4+j, sprint_hex(bldata, 16));\r
+                       PrintAndLog("Writing to block %2d: %s", i*4+j, sprint_hex(bldata, 16));\r
+                       \r
+                       /*\r
+                       PrintAndLog("Writing to block %2d: %s Confirm? [Y,N]", i*4+j, sprint_hex(bldata, 16));\r
+                       \r
+                       scanf("%c",&ch);\r
+                       if ((ch != 'y') && (ch != 'Y')){\r
+                               PrintAndLog("Aborting !");\r
+                               return 1;\r
+                       }\r
+                       */\r
                        \r
                        memcpy(c.d.asBytes + 10, bldata, 16);\r
                        SendCommand(&c);\r
@@ -467,6 +485,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
@@ -519,10 +539,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
@@ -558,8 +580,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
@@ -587,7 +609,6 @@ int CmdHF14AMfNested(const char *Cmd)
                        }\r
                } \r
                \r
-               \r
                // nested sectors\r
                iterations = 0;\r
                PrintAndLog("nested...");\r
@@ -634,17 +655,31 @@ int CmdHF14AMfNested(const char *Cmd)
                        }               \r
                }\r
                \r
+               // Create dump file\r
                if (createDumpFile) {\r
                        if ((fkeys = fopen("dumpkeys.bin","wb")) == NULL) { \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, 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, 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