X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/8556b852ed769280d1b63054ab1bd08fa19b746a..0014cb46da1bb7e0dfaa1d2cc8a291c6ab4ac1b3:/client/cmdhfmf.c diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index d771c645..d8bc8f1d 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -276,8 +276,8 @@ int CmdHF14AMfNested(const char *Cmd) if (strlen(Cmd)<3) { PrintAndLog("Usage:"); PrintAndLog(" all sectors: hf mf nested [t]"); - PrintAndLog(" one sector: hf mf nested o [t]"); - PrintAndLog(" "); + PrintAndLog(" one sector: hf mf nested o "); + PrintAndLog(" [t]"); PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, - 1K"); PrintAndLog("t - transfer keys into emulator memory"); PrintAndLog(" "); @@ -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); @@ -454,7 +454,7 @@ int CmdHF14AMfChk(const char *Cmd) if (strlen(Cmd)<3) { PrintAndLog("Usage: hf mf chk []"); - PrintAndLog(" sample: hf mf chk 0 A FFFFFFFFFFFF a0a1a2a3a4a5 b01b2b3b4b5 "); + PrintAndLog(" sample: hf mf chk 0 A FFFFFFFFFFFF a0a1a2a3a4a5 b0b1b2b3b4b5 "); return 0; } @@ -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; } @@ -684,8 +796,8 @@ static command_t CommandTable[] = {"nested", CmdHF14AMfNested, 0, "Test nested authentication"}, {"sim", CmdHF14AMf1kSim, 0, "Simulate MIFARE 1k card"}, {"eclr", CmdHF14AMfEClear, 0, "Clear simulator memory block"}, - {"eget", CmdHF14AMfEGet, 0, "Set simulator memory block"}, - {"eset", CmdHF14AMfESet, 0, "Get simulator memory block"}, + {"eget", CmdHF14AMfEGet, 0, "Get simulator memory block"}, + {"eset", CmdHF14AMfESet, 0, "Set simulator memory block"}, {"eload", CmdHF14AMfELoad, 0, "Load from file emul dump"}, {"esave", CmdHF14AMfESave, 0, "Save to file emul dump"}, {"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},