uint8_t isOK = 0;\r
uint8_t * data = NULL;\r
\r
- if (sectorNo > 15) {\r
- PrintAndLog("Sector number must be less than 16");\r
- return 1;\r
- }\r
PrintAndLog("Attempting to Read Ultralight... ");\r
\r
UsbCommand c = {CMD_MIFAREU_READCARD, {sectorNo}};\r
\r
PrintAndLog("isOk:%02x", isOK);\r
if (isOK) \r
- for (i = 0; i < 16; i++) {\r
- switch(i){\r
- case 2:\r
- //process lock bytes\r
- lockbytes_t=data+(i*4);\r
- lockbytes[0]=lockbytes_t[2];\r
- lockbytes[1]=lockbytes_t[3];\r
- for(int j=0; j<16; j++){\r
- bit[j]=lockbytes[j/8] & ( 1 <<(7-j%8));\r
- }\r
- //PrintAndLog("LB %02x %02x", lockbytes[0],lockbytes[1]);\r
- //PrintAndLog("LB2b %02x %02x %02x %02x %02x %02x %02x %02x",bit[8],bit[9],bit[10],bit[11],bit[12],bit[13],bit[14],bit[15]); \r
- PrintAndLog("Block %3d:%s ", i,sprint_hex(data + i * 4, 4));\r
- break;\r
- case 3: \r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[4]);\r
- break;\r
- case 4:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[3]);\r
- break;\r
- case 5:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[2]);\r
- break;\r
- case 6:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[1]);\r
- break;\r
- case 7:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[0]);\r
- break;\r
- case 8:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[15]);\r
- break;\r
- case 9:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[14]);\r
- break;\r
- case 10:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[13]);\r
- break;\r
- case 11:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[12]);\r
- break;\r
- case 12:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[11]);\r
- break;\r
- case 13:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[10]);\r
- break;\r
- case 14:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[9]);\r
- break;\r
- case 15:\r
- PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[8]);\r
- break;\r
- default:\r
- PrintAndLog("Block %3d:%s ", i,sprint_hex(data + i * 4, 4));\r
- break;\r
+ { // bit 0 and 1\r
+ PrintAndLog("Block %3d:%s ", 0,sprint_hex(data + 0 * 4, 4));\r
+ PrintAndLog("Block %3d:%s ", 1,sprint_hex(data + 1 * 4, 4));\r
+ // bit 2\r
+ //process lock bytes\r
+ lockbytes_t=data+(2*4);\r
+ lockbytes[0]=lockbytes_t[2];\r
+ lockbytes[1]=lockbytes_t[3];\r
+ for(int j=0; j<16; j++){\r
+ bit[j]=lockbytes[j/8] & ( 1 <<(7-j%8));\r
}\r
- }\r
+ //remaining\r
+ for (i = 3; i < 16; i++) {\r
+ int bitnum = (23-i) % 16;\r
+ PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[bitnum]);\r
+ }\r
+\r
+ }\r
} else {\r
PrintAndLog("Command execute timeout");\r
}\r
for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {\r
PrintAndLog("File reading error.");\r
+ fclose(fin);\r
return 2;\r
}\r
}\r
for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {\r
PrintAndLog("File reading error.");\r
+ fclose(fin);\r
return 2;\r
}\r
}\r
- \r
+ fclose(fin);\r
// Read access rights to sectors\r
\r
PrintAndLog("|-----------------------------------------|");\r
PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);\r
}\r
\r
- fclose(fin);\r
return 0;\r
}\r
\r
}\r
if ((fkeys = fopen("dumpkeys.bin","rb")) == NULL) {\r
PrintAndLog("Could not find file dumpkeys.bin");\r
+ fclose(fdump);\r
return 1;\r
}\r
\r
for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
if (fread(keyA[sectorNo], 1, 6, fkeys) == 0) {\r
PrintAndLog("File reading error (dumpkeys.bin).");\r
+ fclose(fdump);\r
+ fclose(fkeys);\r
return 2;\r
}\r
}\r
for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
if (fread(keyB[sectorNo], 1, 6, fkeys) == 0) {\r
PrintAndLog("File reading error (dumpkeys.bin).");\r
+ fclose(fdump);\r
+ fclose(fkeys);\r
return 2;\r
}\r
}\r
+ fclose(fkeys);\r
\r
PrintAndLog("Restoring dumpdata.bin to card");\r
\r
\r
if (fread(bldata, 1, 16, fdump) == 0) {\r
PrintAndLog("File reading error (dumpdata.bin).");\r
+ fclose(fdump);\r
return 2;\r
}\r
\r
}\r
\r
fclose(fdump);\r
- fclose(fkeys);\r
return 0;\r
}\r
\r
\r
int CmdHF14AMfChk(const char *Cmd)\r
{\r
+ if (strlen(Cmd)<3) {\r
+ PrintAndLog("Usage: hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t] [<key (12 hex symbols)>] [<dic (*.dic)>]");\r
+ PrintAndLog(" * - all sectors");\r
+ PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r
+ PrintAndLog("d - write keys to binary file\n");\r
+ PrintAndLog(" sample: hf mf chk 0 A 1234567890ab keys.dic");\r
+ PrintAndLog(" hf mf chk *1 ? t");\r
+ return 0;\r
+ } \r
+\r
FILE * f;\r
char filename[256]={0};\r
char buf[13];\r
int transferToEml = 0;\r
int createDumpFile = 0;\r
\r
+\r
keyBlock = calloc(stKeyBlock, 6);\r
if (keyBlock == NULL) return 1;\r
\r
num_to_bytes(defaultKeys[defaultKeyCounter], 6, (uint8_t*)(keyBlock + defaultKeyCounter * 6));\r
}\r
\r
- if (strlen(Cmd)<3) {\r
- PrintAndLog("Usage: hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t] [<key (12 hex symbols)>] [<dic (*.dic)>]");\r
- PrintAndLog(" * - all sectors");\r
- PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r
- PrintAndLog("d - write keys to binary file\n");\r
- PrintAndLog(" sample: hf mf chk 0 A 1234567890ab keys.dic");\r
- PrintAndLog(" hf mf chk *1 ? t");\r
- return 0;\r
- } \r
\r
if (param_getchar(Cmd, 0)=='*') {\r
blockNo = 3;\r
keycnt++;\r
memset(buf, 0, sizeof(buf));\r
}\r
+ fclose(f);\r
} else {\r
PrintAndLog("File: %s: not found or locked.", filename);\r
free(keyBlock);\r
return 1;\r
- fclose(f);\r
}\r
}\r
}\r
break;\r
}\r
PrintAndLog("File reading error.");\r
+ fclose(f);\r
return 2;\r
}\r
if (strlen(buf) < 32){\r
if(strlen(buf) && feof(f))\r
break;\r
PrintAndLog("File content error. Block data must include 32 HEX symbols");\r
+ fclose(f);\r
return 2;\r
}\r
for (i = 0; i < 32; i += 2) {\r
}\r
if (mfEmlSetMem(buf8, blockNum, 1)) {\r
PrintAndLog("Cant set emul block: %3d", blockNum);\r
+ fclose(f);\r
return 3;\r
}\r
blockNum++;\r
int CmdHF14AMfCSetUID(const char *Cmd)\r
{\r
uint8_t wipeCard = 0;\r
- uint8_t uid[8];\r
- uint8_t oldUid[8];\r
+ uint8_t uid[8] = {0};\r
+ uint8_t oldUid[8]= {0};\r
int res;\r
\r
if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r