]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
added functionality: dump card memory, save|load card memory.
authorMerlokbr@gmail.com <Merlokbr@gmail.com@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Wed, 22 Jun 2011 01:25:16 +0000 (01:25 +0000)
committerMerlokbr@gmail.com <Merlokbr@gmail.com@ef4ab9da-24cd-11de-8aaa-f3a34680c41f>
Wed, 22 Jun 2011 01:25:16 +0000 (01:25 +0000)
50% fixed problem with readline lib

armsrc/mifarecmd.c
client/cmdhfmf.c
client/cmdmain.c
client/proxmark3.c

index fca4f69b6dac9bc5afb58a4c3c94ccb213ab8d7b..d2795b1a2c2ca2e5a810c4ea90629a1d51b254a9 100644 (file)
@@ -636,6 +636,7 @@ void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
 \r
        // variables\r
        byte_t dataoutbuf[16];\r
 \r
        // variables\r
        byte_t dataoutbuf[16];\r
+       byte_t dataoutbuf2[16];\r
        uint8_t uid[8];\r
 \r
        // clear trace\r
        uint8_t uid[8];\r
 \r
        // clear trace\r
@@ -687,6 +688,15 @@ void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
                                break;\r
                        };\r
                        emlSetMem(dataoutbuf, sectorNo * 4 + 2, 1);\r
                                break;\r
                        };\r
                        emlSetMem(dataoutbuf, sectorNo * 4 + 2, 1);\r
+\r
+                       // get block 3 bytes 6-9\r
+                       if(mifare_classic_readblock(pcs, cuid, sectorNo * 4 + 3, dataoutbuf)) {\r
+                               if (MF_DBGLEVEL >= 1)   Dbprintf("Read block 3 error");\r
+                               break;\r
+                       };\r
+                       emlGetMem(dataoutbuf2, sectorNo * 4 + 3, 1);\r
+                       memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4);\r
+                       emlSetMem(dataoutbuf2,  sectorNo * 4 + 3, 1);\r
                }\r
 \r
                if(mifare_classic_halt(pcs, cuid)) {\r
                }\r
 \r
                if(mifare_classic_halt(pcs, cuid)) {\r
@@ -699,14 +709,15 @@ void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
 \r
        //  ----------------------------- crypto1 destroy\r
        crypto1_destroy(pcs);\r
 \r
        //  ----------------------------- crypto1 destroy\r
        crypto1_destroy(pcs);\r
+\r
+       FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+       LEDsoff();\r
        \r
        if (MF_DBGLEVEL >= 2) DbpString("EMUL FILL SECTORS FINISHED");\r
 \r
        // add trace trailer\r
        memset(uid, 0x44, 4);\r
        LogTrace(uid, 4, 0, 0, TRUE);\r
        \r
        if (MF_DBGLEVEL >= 2) DbpString("EMUL FILL SECTORS FINISHED");\r
 \r
        // add trace trailer\r
        memset(uid, 0x44, 4);\r
        LogTrace(uid, 4, 0, 0, TRUE);\r
-       \r
-       Dbprintf("Loaded.");\r
 }\r
 \r
 //-----------------------------------------------------------------------------\r
 }\r
 \r
 //-----------------------------------------------------------------------------\r
index d771c64544424d94a07d8a65eeb83f0fd3a4a48f..b46c33b02831edd5eb671c9e7e852b6f145a5a7f 100644 (file)
@@ -427,7 +427,7 @@ int CmdHF14AMfNested(const char *Cmd)
                        for (i = 0; i < SectorsCnt; i++) {\r
                                mfEmlGetMem(keyBlock, i * 4 + 3, 1);\r
                                if (e_sector[i].foundKey[0])\r
                        for (i = 0; i < SectorsCnt; i++) {\r
                                mfEmlGetMem(keyBlock, i * 4 + 3, 1);\r
                                if (e_sector[i].foundKey[0])\r
-                                       num_to_bytes(e_sector[i].Key[1], 6, keyBlock);\r
+                                       num_to_bytes(e_sector[i].Key[0], 6, keyBlock);\r
                                if (e_sector[i].foundKey[1])\r
                                        num_to_bytes(e_sector[i].Key[1], 6, &keyBlock[10]);\r
                                mfEmlSetMem(keyBlock, i * 4 + 3, 1);\r
                                if (e_sector[i].foundKey[1])\r
                                        num_to_bytes(e_sector[i].Key[1], 6, &keyBlock[10]);\r
                                mfEmlSetMem(keyBlock, i * 4 + 3, 1);\r
@@ -617,13 +617,125 @@ int CmdHF14AMfESet(const char *Cmd)
 \r
 int CmdHF14AMfELoad(const char *Cmd)\r
 {\r
 \r
 int CmdHF14AMfELoad(const char *Cmd)\r
 {\r
-       PrintAndLog("No code here (");\r
+       FILE * f;\r
+       char filename[20];\r
+       char * fnameptr = filename;\r
+       char buf[64];\r
+       uint8_t buf8[64];\r
+       int i, len, blockNum;\r
+       \r
+       memset(filename, 0, sizeof(filename));\r
+       memset(buf, 0, sizeof(buf));\r
+\r
+       if (param_getchar(Cmd, 0) == 'h') {\r
+               PrintAndLog("It loads emul dump from the file `filename.eml`");\r
+               PrintAndLog("Usage:  hf mf eload <file name w/o `.eml`>");\r
+               PrintAndLog(" sample: hf mf eload filename");\r
+               return 0;\r
+       }       \r
+\r
+       len = strlen(Cmd);\r
+       if (len > 14) len = 14;\r
+       \r
+       if (len < 1) {\r
+       }\r
+\r
+       memcpy(filename, Cmd, len);\r
+       fnameptr += len;\r
+\r
+       sprintf(fnameptr, ".eml"); \r
+       \r
+       // open file\r
+       f = fopen(filename, "r");\r
+       if (f == NULL) {\r
+               PrintAndLog("File not found or locked.");\r
+               return 1;\r
+       }\r
+       \r
+       blockNum = 0;\r
+       while(!feof(f)){\r
+               memset(buf, 0, sizeof(buf));\r
+               fgets(buf, sizeof(buf), f);\r
+               if (strlen(buf) < 32){\r
+                       PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
+                       return 2;\r
+               }\r
+               for (i = 0; i < 32; i += 2)\r
+                 sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);\r
+//                     PrintAndLog("data[%02d]:%s", blockNum, sprint_hex(buf8, 16));\r
+\r
+               if (mfEmlSetMem(buf8, blockNum, 1)) {\r
+                       PrintAndLog("Cant set emul block: %d", blockNum);\r
+                       return 3;\r
+               }\r
+               blockNum++;\r
+               \r
+               if (blockNum >= 16 * 4) break;\r
+       }\r
+       fclose(f);\r
+       \r
+       if (blockNum != 16 * 4){\r
+               PrintAndLog("File content error. There must be 64 blocks");\r
+               return 4;\r
+       }\r
+       PrintAndLog("Loaded from file: %s", filename);\r
   return 0;\r
 }\r
 \r
 int CmdHF14AMfESave(const char *Cmd)\r
 {\r
   return 0;\r
 }\r
 \r
 int CmdHF14AMfESave(const char *Cmd)\r
 {\r
-       PrintAndLog("No code here (");\r
+       FILE * f;\r
+       char filename[20];\r
+       char * fnameptr = filename;\r
+       uint8_t buf[64];\r
+       int i, j, len;\r
+       \r
+       memset(filename, 0, sizeof(filename));\r
+       memset(buf, 0, sizeof(buf));\r
+\r
+       if (param_getchar(Cmd, 0) == 'h') {\r
+               PrintAndLog("It saves emul dump into the file `filename.eml` or `cardID.eml`");\r
+               PrintAndLog("Usage:  hf mf esave [file name w/o `.eml`]");\r
+               PrintAndLog(" sample: hf mf esave ");\r
+               PrintAndLog("         hf mf esave filename");\r
+               return 0;\r
+       }       \r
+\r
+       len = strlen(Cmd);\r
+       if (len > 14) len = 14;\r
+       \r
+       if (len < 1) {\r
+               // get filename\r
+               if (mfEmlGetMem(buf, 0, 1)) {\r
+                       PrintAndLog("Cant get block: %d", 0);\r
+                       return 1;\r
+               }\r
+               for (j = 0; j < 7; j++, fnameptr += 2)\r
+                       sprintf(fnameptr, "%02x", buf[j]); \r
+       } else {\r
+               memcpy(filename, Cmd, len);\r
+               fnameptr += len;\r
+       }\r
+\r
+       sprintf(fnameptr, ".eml"); \r
+       \r
+       // open file\r
+       f = fopen(filename, "w+");\r
+\r
+       // put hex\r
+       for (i = 0; i < 16 * 4; i++) {\r
+               if (mfEmlGetMem(buf, i, 1)) {\r
+                       PrintAndLog("Cant get block: %d", i);\r
+                       break;\r
+               }\r
+               for (j = 0; j < 16; j++)\r
+                       fprintf(f, "%02x", buf[j]); \r
+               fprintf(f,"\n");\r
+       }\r
+       fclose(f);\r
+       \r
+       PrintAndLog("Saved to file: %s", filename);\r
+       \r
   return 0;\r
 }\r
 \r
   return 0;\r
 }\r
 \r
index 8f4618c9674d8cfda47299bdc08039a9a4368a94..ff58e0a4b11649d1e6cbe353adc105390d775891 100644 (file)
@@ -105,12 +105,12 @@ void UsbCommandReceived(UsbCommand *UC)
       }
       memcpy(s, UC->d.asBytes, UC->arg[0]);
       s[UC->arg[0]] = '\0';
       }
       memcpy(s, UC->d.asBytes, UC->arg[0]);
       s[UC->arg[0]] = '\0';
-      PrintAndLog("#db# %s", s);
+      PrintAndLog("#db# %s       ", s);
       return;
     }
 
     case CMD_DEBUG_PRINT_INTEGERS:
       return;
     }
 
     case CMD_DEBUG_PRINT_INTEGERS:
-      PrintAndLog("#db# %08x, %08x, %08x\r\n", UC->arg[0], UC->arg[1], UC->arg[2]);
+      PrintAndLog("#db# %08x, %08x, %08x       \r\n", UC->arg[0], UC->arg[1], UC->arg[2]);
       return;
 
     case CMD_MEASURED_ANTENNA_TUNING: {
       return;
 
     case CMD_MEASURED_ANTENNA_TUNING: {
@@ -158,7 +158,7 @@ void UsbCommandReceived(UsbCommand *UC)
     unexpected_response:
 
        if(UC->cmd != CMD_ACK)
     unexpected_response:
 
        if(UC->cmd != CMD_ACK)
-               PrintAndLog("unrecognized command %08x\n", UC->cmd);
+               PrintAndLog("unrecognized command %08x       \n", UC->cmd);
        else
                memcpy(&current_response, UC, sizeof(UsbCommand));
        received_command = UC->cmd;
        else
                memcpy(&current_response, UC, sizeof(UsbCommand));
        received_command = UC->cmd;
index fe3ba7c5f316094188c04f896d7134c77523112b..209e132c6f683e08d9291f4a6051e32ef74b24b8 100644 (file)
@@ -42,9 +42,10 @@ static void *usb_receiver(void *targ)
         putchar(0x08);
       UsbCommandReceived(&cmdbuf);
                        // there is a big bug )
         putchar(0x08);
       UsbCommandReceived(&cmdbuf);
                        // there is a big bug )
-                       if (cmdbuf.cmd > 0x0100 && cmdbuf.cmd < 0x0110) { // debug commands
-                               rl_on_new_line_with_prompt();
-                               rl_forced_update_display();
+                       if (cmdbuf.cmd >= 0x0100 && cmdbuf.cmd <= 0x0110) { // debug commands
+                               printf(">");
+//                             rl_on_new_line_with_prompt();
+//                             rl_forced_update_display();
                        }
       fflush(NULL);
     }
                        }
       fflush(NULL);
     }
Impressum, Datenschutz