return 0;\r
}\r
\r
-# define NESTED_KEY_COUNT 15\r
+//----------------------------------------------\r
+// Nested\r
+//----------------------------------------------\r
+\r
+static void parseParamTDS(const char *Cmd, const uint8_t indx, bool *paramT, bool *paramD, uint8_t *timeout) {\r
+ char ctmp3[3] = {0};\r
+ int len = param_getlength(Cmd, indx);\r
+ if (len > 0 && len < 4){\r
+ param_getstr(Cmd, indx, ctmp3, sizeof(ctmp3));\r
+ \r
+ *paramT |= (ctmp3[0] == 't' || ctmp3[0] == 'T');\r
+ *paramD |= (ctmp3[0] == 'd' || ctmp3[0] == 'D');\r
+ bool paramS1 = *paramT || *paramD;\r
+\r
+ // slow and very slow\r
+ if (ctmp3[0] == 's' || ctmp3[0] == 'S' || ctmp3[1] == 's' || ctmp3[1] == 'S') {\r
+ *timeout = 11; // slow\r
+ \r
+ if (!paramS1 && (ctmp3[1] == 's' || ctmp3[1] == 'S')) {\r
+ *timeout = 53; // very slow\r
+ }\r
+ if (paramS1 && (ctmp3[2] == 's' || ctmp3[2] == 'S')) {\r
+ *timeout = 53; // very slow\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
int CmdHF14AMfNested(const char *Cmd)\r
{\r
int i, j, res, iterations;\r
uint8_t trgKeyType = 0;\r
uint8_t SectorsCnt = 0;\r
uint8_t key[6] = {0, 0, 0, 0, 0, 0};\r
- uint8_t keyBlock[NESTED_KEY_COUNT * 6];\r
+ uint8_t keyBlock[MifareDefaultKeysSize * 6];\r
uint64_t key64 = 0;\r
+ // timeout in units. (ms * 106)/10 or us*0.0106\r
+ uint8_t btimeout14a = MF_CHKKEYS_DEFTIMEOUT; // fast by default\r
\r
bool autosearchKey = false;\r
\r
\r
if (strlen(Cmd)<3) {\r
PrintAndLog("Usage:");\r
- PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t,d]");\r
- PrintAndLog(" all sectors autosearch key: hf mf nested <card memory> * [t,d]");\r
+ PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t|d|s|ss]");\r
+ PrintAndLog(" all sectors autosearch key: hf mf nested <card memory> * [t|d|s|ss]");\r
PrintAndLog(" one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>");\r
PrintAndLog(" <target block number> <target key A/B> [t]");\r
PrintAndLog(" ");\r
PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r
PrintAndLog("t - transfer keys to emulator memory");\r
PrintAndLog("d - write keys to binary file dumpkeys.bin");\r
+ PrintAndLog("s - Slow (1ms) check keys (required by some non standard cards)");\r
+ PrintAndLog("ss - Very slow (5ms) check keys");\r
PrintAndLog(" ");\r
PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF ");\r
PrintAndLog(" sample2: hf mf nested 1 0 A FFFFFFFFFFFF t ");\r
PrintAndLog(" sample3: hf mf nested 1 0 A FFFFFFFFFFFF d ");\r
PrintAndLog(" sample4: hf mf nested o 0 A FFFFFFFFFFFF 4 A");\r
PrintAndLog(" sample5: hf mf nested 1 * t");\r
+ PrintAndLog(" sample6: hf mf nested 1 * ss");\r
return 0;\r
}\r
\r
if (param_getchar(Cmd, 1) == '*') {\r
autosearchKey = true;\r
\r
- ctmp = param_getchar(Cmd, 2);\r
- transferToEml |= (ctmp == 't' || ctmp == 'T');\r
- createDumpFile |= (ctmp == 'd' || ctmp == 'D');\r
+ parseParamTDS(Cmd, 2, &transferToEml, &createDumpFile, &btimeout14a);\r
\r
- PrintAndLog("--nested. sectors:%2d, block no:*, eml:%c, dmp=%c ", SectorsCnt, transferToEml?'y':'n', createDumpFile?'y':'n');\r
+ PrintAndLog("--nested. sectors:%2d, block no:*, eml:%c, dmp=%c checktimeout=%d us", \r
+ SectorsCnt, transferToEml?'y':'n', createDumpFile?'y':'n', ((int)btimeout14a * 10000) / 106);\r
} else {\r
blockNo = param_get8(Cmd, 1);\r
\r
if (ctmp != 'A' && ctmp != 'a')\r
trgKeyType = 1;\r
\r
- ctmp = param_getchar(Cmd, 6);\r
- transferToEml |= (ctmp == 't' || ctmp == 'T');\r
- createDumpFile |= (ctmp == 'd' || ctmp == 'D');\r
+ parseParamTDS(Cmd, 6, &transferToEml, &createDumpFile, &btimeout14a);\r
} else {\r
- ctmp = param_getchar(Cmd, 4);\r
- transferToEml |= (ctmp == 't' || ctmp == 'T');\r
- createDumpFile |= (ctmp == 'd' || ctmp == 'D');\r
+ parseParamTDS(Cmd, 4, &transferToEml, &createDumpFile, &btimeout14a);\r
}\r
\r
- PrintAndLog("--nested. sectors:%2d, block no:%3d, key type:%c, eml:%c, dmp=%c ", SectorsCnt, blockNo, keyType?'B':'A', transferToEml?'y':'n', createDumpFile?'y':'n');\r
+ PrintAndLog("--nested. sectors:%2d, block no:%3d, key type:%c, eml:%c, dmp=%c checktimeout=%d us", \r
+ SectorsCnt, blockNo, keyType?'B':'A', transferToEml?'y':'n', createDumpFile?'y':'n', ((int)btimeout14a * 10000) / 106);\r
}\r
\r
// one-sector nested\r
}\r
\r
PrintAndLog("Testing known keys. Sector count=%d", SectorsCnt);\r
- mfCheckKeysSec(SectorsCnt, 2, MF_CHKKEYS_DEFTIMEOUT, true, NESTED_KEY_COUNT, keyBlock, e_sector);\r
+ mfCheckKeysSec(SectorsCnt, 2, btimeout14a, true, MifareDefaultKeysSize, keyBlock, e_sector);\r
\r
// get known key from array\r
bool keyFound = false;\r
e_sector[sectorNo].Key[trgKeyType] = key64;\r
\r
// try to check this key as a key to the other sectors\r
- mfCheckKeysSec(SectorsCnt, 2, MF_CHKKEYS_DEFTIMEOUT, true, 1, keyBlock, e_sector);\r
+ mfCheckKeysSec(SectorsCnt, 2, btimeout14a, true, 1, keyBlock, e_sector);\r
}\r
}\r
}\r
// double parameters - ts, ds\r
int clen = param_getlength(Cmd, 2);\r
if (clen == 2 || clen == 3){\r
- param_getstr(Cmd, 2, ctmp3);\r
+ param_getstr(Cmd, 2, ctmp3, sizeof(ctmp3));\r
ctmp = ctmp3[1];\r
}\r
//parse\r
keycnt++;\r
} else {\r
// May be a dic file\r
- if ( param_getstr(Cmd, 2 + i,filename) >= FILE_PATH_SIZE ) {\r
+ if ( param_getstr(Cmd, 2 + i, filename, sizeof(filename)) >= FILE_PATH_SIZE ) {\r
PrintAndLog("File name too long");\r
free(keyBlock);\r
return 2;\r
break;\r
case 'f':\r
case 'F':\r
- len = param_getstr(Cmd, cmdp+1, filename);\r
+ len = param_getstr(Cmd, cmdp+1, filename, sizeof(filename));\r
if (len < 1) {\r
PrintAndLog("error no filename found");\r
return 0;\r
}\r
}\r
\r
- len = param_getstr(Cmd,nameParamNo,filename);\r
+ len = param_getstr(Cmd,nameParamNo,filename,sizeof(filename));\r
\r
if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
\r
}\r
}\r
\r
- len = param_getstr(Cmd,nameParamNo,filename);\r
+ len = param_getstr(Cmd,nameParamNo,filename,sizeof(filename));\r
\r
if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
\r
}\r
return 0;\r
} else {\r
- param_getstr(Cmd, 0, filename);\r
+ param_getstr(Cmd, 0, filename, sizeof(filename));\r
\r
len = strlen(filename);\r
if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
}\r
return 0;\r
} else {\r
- param_getstr(Cmd, 0, filename);\r
+ param_getstr(Cmd, 0, filename, sizeof(filename));\r
\r
len = strlen(filename);\r
if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r