From ab8b654efa9524b494014efd35ac426aaa42884b Mon Sep 17 00:00:00 2001 From: "Merlokbr@gmail.com" Date: Wed, 22 Jun 2011 01:25:16 +0000 Subject: [PATCH] added functionality: dump card memory, save|load card memory. 50% fixed problem with readline lib --- armsrc/mifarecmd.c | 15 +++++- client/cmdhfmf.c | 118 +++++++++++++++++++++++++++++++++++++++++++-- client/cmdmain.c | 6 +-- client/proxmark3.c | 7 +-- 4 files changed, 135 insertions(+), 11 deletions(-) diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index fca4f69b..d2795b1a 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -636,6 +636,7 @@ void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai // variables byte_t dataoutbuf[16]; + byte_t dataoutbuf2[16]; uint8_t uid[8]; // clear trace @@ -687,6 +688,15 @@ void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai break; }; emlSetMem(dataoutbuf, sectorNo * 4 + 2, 1); + + // get block 3 bytes 6-9 + if(mifare_classic_readblock(pcs, cuid, sectorNo * 4 + 3, dataoutbuf)) { + if (MF_DBGLEVEL >= 1) Dbprintf("Read block 3 error"); + break; + }; + emlGetMem(dataoutbuf2, sectorNo * 4 + 3, 1); + memcpy(&dataoutbuf2[6], &dataoutbuf[6], 4); + emlSetMem(dataoutbuf2, sectorNo * 4 + 3, 1); } if(mifare_classic_halt(pcs, cuid)) { @@ -699,14 +709,15 @@ void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai // ----------------------------- crypto1 destroy crypto1_destroy(pcs); + + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + LEDsoff(); if (MF_DBGLEVEL >= 2) DbpString("EMUL FILL SECTORS FINISHED"); // add trace trailer memset(uid, 0x44, 4); LogTrace(uid, 4, 0, 0, TRUE); - - Dbprintf("Loaded."); } //----------------------------------------------------------------------------- diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index d771c645..b46c33b0 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -427,7 +427,7 @@ int CmdHF14AMfNested(const char *Cmd) for (i = 0; i < SectorsCnt; i++) { mfEmlGetMem(keyBlock, i * 4 + 3, 1); if (e_sector[i].foundKey[0]) - num_to_bytes(e_sector[i].Key[1], 6, keyBlock); + num_to_bytes(e_sector[i].Key[0], 6, keyBlock); if (e_sector[i].foundKey[1]) num_to_bytes(e_sector[i].Key[1], 6, &keyBlock[10]); mfEmlSetMem(keyBlock, i * 4 + 3, 1); @@ -617,13 +617,125 @@ int CmdHF14AMfESet(const char *Cmd) int CmdHF14AMfELoad(const char *Cmd) { - PrintAndLog("No code here ("); + FILE * f; + char filename[20]; + char * fnameptr = filename; + char buf[64]; + uint8_t buf8[64]; + int i, len, blockNum; + + memset(filename, 0, sizeof(filename)); + memset(buf, 0, sizeof(buf)); + + if (param_getchar(Cmd, 0) == 'h') { + PrintAndLog("It loads emul dump from the file `filename.eml`"); + PrintAndLog("Usage: hf mf eload "); + PrintAndLog(" sample: hf mf eload filename"); + return 0; + } + + len = strlen(Cmd); + if (len > 14) len = 14; + + if (len < 1) { + } + + memcpy(filename, Cmd, len); + fnameptr += len; + + sprintf(fnameptr, ".eml"); + + // open file + f = fopen(filename, "r"); + if (f == NULL) { + PrintAndLog("File not found or locked."); + return 1; + } + + blockNum = 0; + while(!feof(f)){ + memset(buf, 0, sizeof(buf)); + fgets(buf, sizeof(buf), f); + if (strlen(buf) < 32){ + PrintAndLog("File content error. Block data must include 32 HEX symbols"); + return 2; + } + for (i = 0; i < 32; i += 2) + sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]); +// PrintAndLog("data[%02d]:%s", blockNum, sprint_hex(buf8, 16)); + + if (mfEmlSetMem(buf8, blockNum, 1)) { + PrintAndLog("Cant set emul block: %d", blockNum); + return 3; + } + blockNum++; + + if (blockNum >= 16 * 4) break; + } + fclose(f); + + if (blockNum != 16 * 4){ + PrintAndLog("File content error. There must be 64 blocks"); + return 4; + } + PrintAndLog("Loaded from file: %s", filename); return 0; } int CmdHF14AMfESave(const char *Cmd) { - PrintAndLog("No code here ("); + FILE * f; + char filename[20]; + char * fnameptr = filename; + uint8_t buf[64]; + int i, j, len; + + memset(filename, 0, sizeof(filename)); + memset(buf, 0, sizeof(buf)); + + if (param_getchar(Cmd, 0) == 'h') { + PrintAndLog("It saves emul dump into the file `filename.eml` or `cardID.eml`"); + PrintAndLog("Usage: hf mf esave [file name w/o `.eml`]"); + PrintAndLog(" sample: hf mf esave "); + PrintAndLog(" hf mf esave filename"); + return 0; + } + + len = strlen(Cmd); + if (len > 14) len = 14; + + if (len < 1) { + // get filename + if (mfEmlGetMem(buf, 0, 1)) { + PrintAndLog("Cant get block: %d", 0); + return 1; + } + for (j = 0; j < 7; j++, fnameptr += 2) + sprintf(fnameptr, "%02x", buf[j]); + } else { + memcpy(filename, Cmd, len); + fnameptr += len; + } + + sprintf(fnameptr, ".eml"); + + // open file + f = fopen(filename, "w+"); + + // put hex + for (i = 0; i < 16 * 4; i++) { + if (mfEmlGetMem(buf, i, 1)) { + PrintAndLog("Cant get block: %d", i); + break; + } + for (j = 0; j < 16; j++) + fprintf(f, "%02x", buf[j]); + fprintf(f,"\n"); + } + fclose(f); + + PrintAndLog("Saved to file: %s", filename); + return 0; } diff --git a/client/cmdmain.c b/client/cmdmain.c index 8f4618c9..ff58e0a4 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -105,12 +105,12 @@ void UsbCommandReceived(UsbCommand *UC) } 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: - 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: { @@ -158,7 +158,7 @@ void UsbCommandReceived(UsbCommand *UC) unexpected_response: if(UC->cmd != CMD_ACK) - PrintAndLog("unrecognized command %08x\n", UC->cmd); + PrintAndLog("unrecognized command %08x \n", UC->cmd); else memcpy(¤t_response, UC, sizeof(UsbCommand)); received_command = UC->cmd; diff --git a/client/proxmark3.c b/client/proxmark3.c index fe3ba7c5..209e132c 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -42,9 +42,10 @@ static void *usb_receiver(void *targ) 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); } -- 2.39.2