\r
// variables\r
byte_t dataoutbuf[16];\r
+ byte_t dataoutbuf2[16];\r
uint8_t uid[8];\r
\r
// clear trace\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
// ----------------------------- 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
- Dbprintf("Loaded.");\r
}\r
\r
//-----------------------------------------------------------------------------\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
\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
- 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
}
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: {
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;