#include <stdio.h>\r
#include <stdlib.h>\r
#include <ctype.h>\r
-#include "proxmark3.h"\r
+#include "comms.h"\r
#include "cmdmain.h"\r
#include "cmdhfmfhard.h"\r
+#include "parity.h"\r
#include "util.h"\r
#include "util_posix.h"\r
#include "usb_cmd.h"\r
if (transferToEml) {\r
uint8_t sectortrailer;\r
if (trgBlockNo < 32*4) { // 4 block sector\r
- sectortrailer = (trgBlockNo & 0x03) + 3;\r
+ sectortrailer = trgBlockNo | 0x03;\r
} else { // 16 block sector\r
- sectortrailer = (trgBlockNo & 0x0f) + 15;\r
+ sectortrailer = trgBlockNo | 0x0f;\r
}\r
mfEmlGetMem(keyBlock, sectortrailer, 1);\r
\r
blockNo = i * 4;\r
keyType = j;\r
num_to_bytes(e_sector[i].Key[j], 6, key);\r
- \r
keyFound = true;\r
break;\r
}\r
// Can't found a key....\r
if (!keyFound) {\r
PrintAndLog("Can't found any of the known keys.");\r
+ free(e_sector);\r
return 4;\r
}\r
PrintAndLog("--auto key. block no:%3d, key type:%c key:%s", blockNo, keyType?'B':'A', sprint_hex(key, 6));\r
\r
// initialize storage for found keys\r
e_sector = calloc(SectorsCnt, sizeof(sector_t));\r
- if (e_sector == NULL) return 1;\r
+ if (e_sector == NULL) {\r
+ free(keyBlock);\r
+ return 1;\r
+ }\r
for (uint8_t keyAB = 0; keyAB < 2; keyAB++) {\r
for (uint16_t sectorNo = 0; sectorNo < SectorsCnt; sectorNo++) {\r
e_sector[sectorNo].Key[keyAB] = 0xffffffffffff;\r
}\r
\r
// 1 - blocks count\r
- UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNo, 1, 0}};\r
- memcpy(c.d.asBytes, memBlock, 16);\r
- SendCommand(&c);\r
- return 0;\r
+ return mfEmlSetMem(memBlock, blockNo, 1);\r
}\r
\r
\r
//var\r
int res = 0;\r
int len = 0;\r
+ int parlen = 0;\r
int blockLen = 0;\r
int pckNum = 0;\r
int num = 0;\r
uint8_t *buf = NULL;\r
uint16_t bufsize = 0;\r
uint8_t *bufPtr = NULL;\r
+ uint8_t parity[16];\r
\r
char ctmp = param_getchar(Cmd, 0);\r
if ( ctmp == 'h' || ctmp == 'H' ) {\r
} else {\r
isTag = false;\r
}\r
+ parlen = (len - 1) / 8 + 1;\r
bufPtr += 2;\r
if ((len == 14) && (bufPtr[0] == 0xff) && (bufPtr[1] == 0xff) && (bufPtr[12] == 0xff) && (bufPtr[13] == 0xff)) {\r
memcpy(uid, bufPtr + 2, 7);\r
if (wantDecrypt)\r
mfTraceInit(uid, atqa, sak, wantSaveToEmlFile);\r
} else {\r
- PrintAndLog("%s(%d):%s", isTag ? "TAG":"RDR", num, sprint_hex(bufPtr, len));\r
+ oddparitybuf(bufPtr, len, parity);\r
+ PrintAndLog("%s(%d):%s [%s] c[%s]%c", \r
+ isTag ? "TAG":"RDR", \r
+ num, \r
+ sprint_hex(bufPtr, len), \r
+ printBitsPar(bufPtr + len, len), \r
+ printBitsPar(parity, len),\r
+ memcmp(bufPtr + len, parity, len / 8 + 1) ? '!' : ' ');\r
if (wantLogToFile)\r
AddLogHex(logHexFileName, isTag ? "TAG: ":"RDR: ", bufPtr, len);\r
if (wantDecrypt)\r
- mfTraceDecode(bufPtr, len, wantSaveToEmlFile);\r
+ mfTraceDecode(bufPtr, len, bufPtr[len], wantSaveToEmlFile);\r
num++;\r
}\r
bufPtr += len;\r
- bufPtr += ((len-1)/8+1); // ignore parity\r
+ bufPtr += parlen; // ignore parity\r
}\r
pckNum = 0;\r
}\r
\r
int CmdHFMF(const char *Cmd)\r
{\r
- // flush\r
- WaitForResponseTimeout(CMD_ACK,NULL,100);\r
-\r
- CmdsParse(CommandTable, Cmd);\r
- return 0;\r
+ (void)WaitForResponseTimeout(CMD_ACK,NULL,100);\r
+ CmdsParse(CommandTable, Cmd);\r
+ return 0;\r
}\r
\r
int CmdHelp(const char *Cmd)\r