style
This commit is contained in:
1 parent
c6d01e6e72
commit
8590fab1b5
2 files changed
+102
-68
No files matched your search
+54
-28
@@ -7389,8 +7389,9 @@ int CmdHFMFNDEFFormat(const char *Cmd) {
|
||||
}
|
||||
|
||||
|
||||
if (g_session.pm3_present == false)
|
||||
if (g_session.pm3_present == false) {
|
||||
return PM3_ENOTTY;
|
||||
}
|
||||
|
||||
// Select card to get UID/UIDLEN/ATQA/SAK information
|
||||
clearCommandBuffer();
|
||||
@@ -7482,17 +7483,19 @@ skipfile:
|
||||
uint8_t block[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
switch (b) {
|
||||
case 0:
|
||||
case 0: {
|
||||
continue;
|
||||
}
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 7: {
|
||||
memcpy(block, firstblocks[b], MFBLOCK_SIZE);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (mfIsSectorTrailerBasedOnBlocks(i, j)) {
|
||||
// ST NDEF
|
||||
@@ -7631,8 +7634,9 @@ int CmdHFMFNDEFWrite(const char *Cmd) {
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
case 0xFD:
|
||||
case 0xFE:
|
||||
case 0xFE: {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (fix_msg == false) {
|
||||
PrintAndLogEx(WARNING, "raw NDEF message doesn't have a proper header, continuing...");
|
||||
@@ -7832,6 +7836,7 @@ static int CmdHFMFPersonalize(const char *Cmd) {
|
||||
PrintAndLogEx(WARNING, "select only one key type");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (tmp == 0) {
|
||||
PrintAndLogEx(WARNING, "select one key type");
|
||||
return PM3_EINVARG;
|
||||
@@ -7945,7 +7950,7 @@ static int CmdHf14AGen3Block(const char *Cmd) {
|
||||
|
||||
uint8_t new_block[MFBLOCK_SIZE] = {0x00};
|
||||
int res = mf_chinese_gen_3_block(data, datalen, new_block);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Can't change manufacturer block data. error %d", res);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
@@ -7970,6 +7975,7 @@ static int CmdHf14AGen3Freeze(const char *Cmd) {
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
bool confirm = arg_get_lit(ctx, 1);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (confirm == false) {
|
||||
PrintAndLogEx(INFO, "please confirm that you want to perma lock the card");
|
||||
return PM3_SUCCESS;
|
||||
@@ -8432,10 +8438,11 @@ static int CmdHF14AMfWipe(const char *Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
if (gen2)
|
||||
if (gen2) {
|
||||
PrintAndLogEx(INFO, "Forcing overwrite of sector 0 / block 0 ");
|
||||
else
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "Skipping sector 0 / block 0");
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
@@ -8476,10 +8483,11 @@ static int CmdHF14AMfWipe(const char *Cmd) {
|
||||
// try both A/B keys, start with B key first
|
||||
for (int8_t kt = MF_KEY_B; kt > -1; kt--) {
|
||||
|
||||
if (kt == MF_KEY_A)
|
||||
if (kt == MF_KEY_A) {
|
||||
memcpy(data, keyA + (s * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
|
||||
else
|
||||
} else {
|
||||
memcpy(data, keyB + (s * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, " %3d | %s" NOLF, mfFirstBlockOfSector(s) + b, sprint_hex(data + 10, MFBLOCK_SIZE));
|
||||
clearCommandBuffer();
|
||||
@@ -8539,14 +8547,15 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
}
|
||||
|
||||
uint16_t block_cnt = MIN(MIFARE_1K_MAXBLOCK, (bytes_read / MFBLOCK_SIZE));
|
||||
if (bytes_read == MIFARE_MINI_MAX_BYTES)
|
||||
if (bytes_read == MIFARE_MINI_MAX_BYTES) {
|
||||
block_cnt = MIFARE_MINI_MAXBLOCK;
|
||||
else if (bytes_read == MIFARE_1K_EV1_MAX_BYTES)
|
||||
} else if (bytes_read == MIFARE_1K_EV1_MAX_BYTES) {
|
||||
block_cnt = MIFARE_1K_EV1_MAXBLOCK;
|
||||
else if (bytes_read == MIFARE_2K_MAX_BYTES)
|
||||
} else if (bytes_read == MIFARE_2K_MAX_BYTES) {
|
||||
block_cnt = MIFARE_2K_MAXBLOCK;
|
||||
else if (bytes_read == MIFARE_4K_MAX_BYTES)
|
||||
} else if (bytes_read == MIFARE_4K_MAX_BYTES) {
|
||||
block_cnt = MIFARE_4K_MAXBLOCK;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
PrintAndLogEx(INFO, "File size %zu bytes, file blocks %d (0x%x)", bytes_read, block_cnt, block_cnt);
|
||||
@@ -8563,8 +8572,7 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
mf_save_keys_from_arr(block_cnt, dump);
|
||||
}
|
||||
|
||||
const mad1_sector_t *vigik_s0 = (bytes_read >= sizeof(mad1_sector_t))
|
||||
? (const mad1_sector_t *)dump : NULL;
|
||||
const mad1_sector_t *vigik_s0 = (bytes_read >= sizeof(mad1_sector_t)) ? (const mad1_sector_t *)dump : NULL;
|
||||
|
||||
int sector = vigik_s0 ? DetectHID(vigik_s0, 0x4910) : -1;
|
||||
if (sector > -1) {
|
||||
@@ -8632,15 +8640,18 @@ static int parse_gtu_cfg(uint8_t *d, size_t n) {
|
||||
PrintAndLogEx(INFO, "%02X.............. " NOLF, d[0]);
|
||||
bool is_ul_enabled = (d[0] == 1);
|
||||
switch (d[0]) {
|
||||
case 0x00:
|
||||
case 0x00: {
|
||||
PrintAndLogEx(NORMAL, "MIFARE Classic mode");
|
||||
break;
|
||||
case 0x01:
|
||||
}
|
||||
case 0x01: {
|
||||
PrintAndLogEx(NORMAL, "MIFARE Ultralight/NTAG mode");
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
PrintAndLogEx(NORMAL, _RED_("unknown"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "..%02X............ UID " NOLF, d[1]);
|
||||
@@ -8786,18 +8797,22 @@ static int CmdHF14AGen4Info(const char *cmd) {
|
||||
|
||||
if (dlen == 0) {
|
||||
if (IfPm3Iso14443a()) {
|
||||
|
||||
res = mfG4GetConfig(pwd, resp, &resplen, verbose);
|
||||
if (res != PM3_SUCCESS || resplen == 0) {
|
||||
if (res == PM3_ETIMEOUT)
|
||||
if (res == PM3_ETIMEOUT) {
|
||||
PrintAndLogEx(ERR, "No card in the field or card command timeout.");
|
||||
else
|
||||
} else {
|
||||
PrintAndLogEx(ERR, "Error get config. Maybe not a Gen4 card?. error=%d rlen=%zu", res, resplen);
|
||||
}
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
} else {
|
||||
PrintAndLogEx(ERR, "Offline mode, please provide data");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
} else if (dlen != 32) {
|
||||
PrintAndLogEx(FAILED, "Data must be 32 bytes length, got " _YELLOW_("%u"), dlen);
|
||||
return PM3_EINVARG;
|
||||
@@ -8807,7 +8822,7 @@ static int CmdHF14AGen4Info(const char *cmd) {
|
||||
}
|
||||
|
||||
parse_gtu_cfg(resp, resplen);
|
||||
if (! IfPm3Iso14443a()) {
|
||||
if (IfPm3Iso14443a() == false) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -8815,6 +8830,7 @@ static int CmdHF14AGen4Info(const char *cmd) {
|
||||
|
||||
res = mfG4GetFactoryTest(pwd, resp, &resplen, false);
|
||||
if (res == PM3_SUCCESS && resplen > 2) {
|
||||
|
||||
PrintAndLogEx(INFO, "");
|
||||
PrintAndLogEx(INFO, _CYAN_("Factory test"));
|
||||
if (verbose) {
|
||||
@@ -9177,7 +9193,7 @@ static int CmdHF14AGen4SetBlk(const char *cmd) {
|
||||
|
||||
uint8_t blockno = (uint8_t)b;
|
||||
int res = mfG4SetBlock(pwd, blockno, data, MAGIC_INIT | MAGIC_OFF);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Can't write block. error=%d", res);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
@@ -9261,8 +9277,13 @@ static int CmdHF14AGen4View(const char *Cmd) {
|
||||
for (uint16_t i = 0; i < block_cnt; i++) {
|
||||
|
||||
uint8_t flags = 0 ;
|
||||
if (i == 0) flags |= MAGIC_INIT ;
|
||||
if (i + 1 == block_cnt) flags |= MAGIC_OFF ;
|
||||
if (i == 0) {
|
||||
flags |= MAGIC_INIT;
|
||||
}
|
||||
|
||||
if (i + 1 == block_cnt) {
|
||||
flags |= MAGIC_OFF;
|
||||
}
|
||||
|
||||
int res = mfG4GetBlock(pwd, i, dump + (i * MFBLOCK_SIZE), flags);
|
||||
if (res != PM3_SUCCESS) {
|
||||
@@ -9426,7 +9447,7 @@ static int CmdHF14AGen4Save(const char *Cmd) {
|
||||
PrintAndLogEx(NORMAL, "." NOLF);
|
||||
fflush(stdout);
|
||||
// 4k READs can be long, so we split status each 64 blocks.
|
||||
if (i % 64 == 0 && i != 0) {
|
||||
if (((i % 64) == 0) && (i != 0)) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "" NOLF) ;
|
||||
}
|
||||
@@ -9700,9 +9721,11 @@ static int CmdHF14AGen4_GDM_SetCfg(const char *Cmd) {
|
||||
uint8_t block[MFBLOCK_SIZE] = {0x00};
|
||||
int blen = 0;
|
||||
CLIGetHexWithReturn(ctx, 1, block, &blen);
|
||||
|
||||
int keylen = 0;
|
||||
uint8_t key[6] = {0};
|
||||
CLIGetHexWithReturn(ctx, 2, key, &keylen);
|
||||
|
||||
bool gen1a = arg_get_lit(ctx, 3);
|
||||
bool gdm = arg_get_lit(ctx, 4);
|
||||
CLIParserFree(ctx);
|
||||
@@ -10019,8 +10042,9 @@ static int CmdHF14AMfValue(const char *Cmd) {
|
||||
if (action < 4) {
|
||||
|
||||
uint8_t isok = true;
|
||||
if (g_session.pm3_present == false)
|
||||
if (g_session.pm3_present == false) {
|
||||
return PM3_ENOTTY;
|
||||
}
|
||||
|
||||
// 0 Increment, 1 - Decrement, 2 - Restore, 3 - Set, 4 - Get, 5 - Decode from data
|
||||
if (action <= 2) {
|
||||
@@ -10122,10 +10146,11 @@ static int CmdHF14AMfValue(const char *Cmd) {
|
||||
if (trnval == -1) {
|
||||
res = mf_read_block(blockno, keytype, key, data);
|
||||
} else {
|
||||
if (mfSectorNum(trnval) != mfSectorNum(blockno))
|
||||
if (mfSectorNum(trnval) != mfSectorNum(blockno)) {
|
||||
res = mf_read_block(trnval, transferkeytype, transferkey, data);
|
||||
else
|
||||
} else {
|
||||
res = mf_read_block(trnval, keytype, key, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10280,6 +10305,7 @@ static int CmdHFMFHidEncode(const char *Cmd) {
|
||||
}
|
||||
res = wiegand_pack_from_formatted(format_idx, &card, false, &input);
|
||||
}
|
||||
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Failed to encode HID input");
|
||||
return res;
|
||||
|
||||
+48
-40
@@ -227,13 +227,13 @@ static int mfp_load_keys(uint8_t **pkeyBlock, uint32_t *pkeycnt, uint8_t *userke
|
||||
|
||||
int len = hex_to_bytes(g_mifare_plus_default_keys[cnt], (uint8_t *)(*pkeyBlock + (*pkeycnt + cnt) * AES_KEY_LEN), AES_KEY_LEN);
|
||||
|
||||
PrintAndLogEx(DEBUG, _YELLOW_("%2u") " - %s", *pkeycnt + cnt, sprint_hex_inrow(*pkeyBlock + (*pkeycnt + cnt) * AES_KEY_LEN, AES_KEY_LEN));
|
||||
PrintAndLogEx(DEBUG, _YELLOW_("%2u") " - %s", (*pkeycnt + cnt), sprint_hex_inrow(*pkeyBlock + (*pkeycnt + cnt) * AES_KEY_LEN, AES_KEY_LEN));
|
||||
if (len != AES_KEY_LEN) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*pkeycnt += cnt;
|
||||
PrintAndLogEx(SUCCESS, "loaded " _GREEN_("%zu") " hardcoded keys", cnt);
|
||||
PrintAndLogEx(SUCCESS, "Loaded " _GREEN_("%zu") " hardcoded keys", cnt);
|
||||
}
|
||||
|
||||
// Handle user supplied dictionary file
|
||||
@@ -310,6 +310,7 @@ static int CmdHFMFPInfo(const char *Cmd) {
|
||||
uint8_t uid4b[4] = {0};
|
||||
uint8_t uid7b[7] = {0};
|
||||
int version_len = sizeof(version);
|
||||
|
||||
if (get_plus_version(version, &version_len) == PM3_SUCCESS) {
|
||||
plus_print_version(version);
|
||||
supportVersion = true;
|
||||
@@ -526,27 +527,27 @@ static int CmdHFMFPWritePerso(const char *Cmd) {
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("v", "verbose", "Verbose output"),
|
||||
arg_str1("a", "adr", "<hex>", "Address, 2 hex bytes"),
|
||||
arg_str0("d", "data", "<hex>", "Data, 16 hex bytes"),
|
||||
arg_lit0("v", "verbose", "Verbose output"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
bool verbose = arg_get_lit(ctx, 1);
|
||||
|
||||
uint8_t addr[64] = {0};
|
||||
int addrLen = 0;
|
||||
CLIGetHexWithReturn(ctx, 2, addr, &addrLen);
|
||||
CLIGetHexWithReturn(ctx, 1, addr, &addrLen);
|
||||
|
||||
uint8_t datain[64] = {0};
|
||||
int datainLen = 0;
|
||||
CLIGetHexWithReturn(ctx, 3, datain, &datainLen);
|
||||
CLIGetHexWithReturn(ctx, 2, datain, &datainLen);
|
||||
|
||||
bool verbose = arg_get_lit(ctx, 3);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
mfpSetVerboseMode(verbose);
|
||||
|
||||
if (!datainLen) {
|
||||
if (datainLen == 0) {
|
||||
memmove(datain, mfp_default_key, 16);
|
||||
datainLen = 16;
|
||||
}
|
||||
@@ -555,6 +556,7 @@ static int CmdHFMFPWritePerso(const char *Cmd) {
|
||||
PrintAndLogEx(ERR, "Address length must be 2 bytes. Got %d", addrLen);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (datainLen != 16) {
|
||||
PrintAndLogEx(ERR, "Data length must be 16 bytes. Got %d", datainLen);
|
||||
return PM3_EINVARG;
|
||||
@@ -564,7 +566,7 @@ static int CmdHFMFPWritePerso(const char *Cmd) {
|
||||
int datalen = 0;
|
||||
|
||||
int res = MFPWritePerso(addr, datain, true, false, data, sizeof(data), &datalen);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Exchange error: %d", res);
|
||||
return res;
|
||||
}
|
||||
@@ -626,11 +628,11 @@ static int CmdHFMFPInitPerso(const char *Cmd) {
|
||||
keyNum[0] = sn >> 8;
|
||||
keyNum[1] = sn & 0xff;
|
||||
res = MFPWritePerso(keyNum, key, (sn == 0x4000), true, data, sizeof(data), &datalen);
|
||||
if (!res && (datalen == 3) && data[0] == 0x09) {
|
||||
if ((res == PM3_SUCCESS) && (datalen == 3) && data[0] == 0x09) {
|
||||
PrintAndLogEx(INFO, "2K card detected.");
|
||||
break;
|
||||
}
|
||||
if (res || (datalen != 3) || data[0] != 0x90) {
|
||||
if ((res != PM3_SUCCESS) || (datalen != 3) || data[0] != 0x90) {
|
||||
PrintAndLogEx(ERR, "Write error on address %04x", sn);
|
||||
break;
|
||||
}
|
||||
@@ -641,10 +643,10 @@ static int CmdHFMFPInitPerso(const char *Cmd) {
|
||||
keyNum[0] = mfp_card_adresses[i] >> 8;
|
||||
keyNum[1] = mfp_card_adresses[i] & 0xff;
|
||||
res = MFPWritePerso(keyNum, key, false, true, data, sizeof(data), &datalen);
|
||||
if (!res && (datalen == 3) && data[0] == 0x09) {
|
||||
if ((res == PM3_SUCCESS) && (datalen == 3) && data[0] == 0x09) {
|
||||
PrintAndLogEx(WARNING, "Skipped[%04x]...", mfp_card_adresses[i]);
|
||||
} else {
|
||||
if (res || (datalen != 3) || data[0] != 0x90) {
|
||||
if ((res != PM3_SUCCESS) || (datalen != 3) || data[0] != 0x90) {
|
||||
PrintAndLogEx(ERR, "Write error on address %04x", mfp_card_adresses[i]);
|
||||
break;
|
||||
}
|
||||
@@ -652,8 +654,9 @@ static int CmdHFMFPInitPerso(const char *Cmd) {
|
||||
}
|
||||
DropField();
|
||||
|
||||
if (res)
|
||||
if (res != PM3_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Done!");
|
||||
return PM3_SUCCESS;
|
||||
@@ -686,7 +689,7 @@ static int CmdHFMFPCommitPerso(const char *Cmd) {
|
||||
int datalen = 0;
|
||||
|
||||
int res = MFPCommitPerso(true, false, data, sizeof(data), &datalen);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Exchange error: %d", res);
|
||||
return res;
|
||||
}
|
||||
@@ -745,6 +748,7 @@ static int CmdHFMFPAcl(const char *Cmd) {
|
||||
if (mfValidateAccessConditions(acl + 1) == false || ((acl[0] >> 4) != ((~acl[0]) & 0xF))) {
|
||||
PrintAndLogEx(ERR, _RED_("Invalid Access Conditions, NEVER write these on a card!"));
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, " # | Access rights");
|
||||
PrintAndLogEx(INFO, "----+-----------------------------------------------------------------");
|
||||
@@ -761,10 +765,11 @@ static int CmdHFMFPAcl(const char *Cmd) {
|
||||
// So if you set bit B3, you will ONLY be able to read/write the ACL block encrypted.
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// This line could have used a ? _YELLOW_ : _GREEN_, but CC doesn't like it that way.
|
||||
if ((acl[0] >> (4 + i)) & 1)
|
||||
if ((acl[0] >> (4 + i)) & 1) {
|
||||
PrintAndLogEx(INFO, "%3d | " _YELLOW_("encrypted only"), i);
|
||||
else
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "%3d | " _GREEN_("encrypted or plaintext"), i);
|
||||
}
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
@@ -808,8 +813,9 @@ static int CmdHFMFPAuth(const char *Cmd) {
|
||||
}
|
||||
|
||||
int resBuffer = MifareAuth4(NULL, keyn, key, false, true, false, true, verbose, false);
|
||||
if (resBuffer == PM3_SUCCESS && keyn[0] == 0x90 && (keyn[1] == 0x02 || keyn[1] == 0x03))
|
||||
if (resBuffer == PM3_SUCCESS && keyn[0] == 0x90 && (keyn[1] == 0x02 || keyn[1] == 0x03)) {
|
||||
PrintAndLogEx(INFO, "Switched security level ( " _GREEN_("ok") " )");
|
||||
}
|
||||
return resBuffer;
|
||||
}
|
||||
|
||||
@@ -926,7 +932,7 @@ static int CmdHFMFPRdbl(const char *Cmd) {
|
||||
|
||||
mf4Session_t mf4session;
|
||||
int res = MifareAuth4(&mf4session, keyn, key, false, true, true, true, verbose, false);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Authentication error: %d", res);
|
||||
return res;
|
||||
}
|
||||
@@ -935,7 +941,7 @@ static int CmdHFMFPRdbl(const char *Cmd) {
|
||||
int datalen = 0;
|
||||
uint8_t mac[8] = {0};
|
||||
res = MFPReadBlock(&mf4session, plain, nomaccmd, nomacres, blockn & 0xff, blocksCount, false, false, data, sizeof(data), &datalen, mac);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Read error: %d", res);
|
||||
return res;
|
||||
}
|
||||
@@ -963,11 +969,11 @@ static int CmdHFMFPRdbl(const char *Cmd) {
|
||||
indx++;
|
||||
}
|
||||
|
||||
if (memcmp(&data[(blocksCount * 16) + 1], mac, 8) && !nomacres) {
|
||||
if (memcmp(&data[(blocksCount * 16) + 1], mac, 8) && nomacres == false) {
|
||||
PrintAndLogEx(WARNING, "WARNING: mac not equal...");
|
||||
PrintAndLogEx(WARNING, "MAC card... " _YELLOW_("%s"), sprint_hex_inrow(&data[1 + (blocksCount * MFBLOCK_SIZE)], 8));
|
||||
PrintAndLogEx(WARNING, "MAC reader... " _YELLOW_("%s"), sprint_hex_inrow(mac, sizeof(mac)));
|
||||
} else if (!nomacres) {
|
||||
} else if (nomacres == false) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(INFO, "MAC... " _YELLOW_("%s"), sprint_hex_inrow(&data[1 + (blocksCount * MFBLOCK_SIZE)], 8));
|
||||
}
|
||||
@@ -1035,7 +1041,7 @@ static int CmdHFMFPRdsc(const char *Cmd) {
|
||||
|
||||
mf4Session_t mf4session;
|
||||
int res = MifareAuth4(&mf4session, keyn, key, false, true, true, true, verbose, false);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Authentication error: %d", res);
|
||||
return res;
|
||||
}
|
||||
@@ -1049,7 +1055,7 @@ static int CmdHFMFPRdsc(const char *Cmd) {
|
||||
for (int blockno = mfFirstBlockOfSector(sectorNum); blockno < mfFirstBlockOfSector(sectorNum) + mfNumBlocksPerSector(sectorNum); blockno++) {
|
||||
|
||||
res = MFPReadBlock(&mf4session, plain, nomaccmd, nomacres, blockno & 0xff, 1, false, true, data, sizeof(data), &datalen, mac);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Read error: %d", res);
|
||||
DropField();
|
||||
return res;
|
||||
@@ -1073,11 +1079,11 @@ static int CmdHFMFPRdsc(const char *Cmd) {
|
||||
|
||||
mf_print_block_one(blockno, data + 1, verbose);
|
||||
|
||||
if (memcmp(&data[1 + 16], mac, 8) && !nomacres) {
|
||||
if (memcmp(&data[1 + 16], mac, 8) && nomacres == false) {
|
||||
PrintAndLogEx(WARNING, "WARNING: mac on block %d not equal...", blockno);
|
||||
PrintAndLogEx(WARNING, "MAC card... " _YELLOW_("%s"), sprint_hex_inrow(&data[1 + MFBLOCK_SIZE], 8));
|
||||
PrintAndLogEx(WARNING, "MAC reader... " _YELLOW_("%s"), sprint_hex_inrow(mac, sizeof(mac)));
|
||||
} else if (!nomacres) {
|
||||
} else if (nomacres == false) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(INFO, "MAC... " _YELLOW_("%s"), sprint_hex_inrow(&data[1 + MFBLOCK_SIZE], 8));
|
||||
}
|
||||
@@ -1109,10 +1115,11 @@ static int mfp_analyse_st_block(uint8_t blockno, uint8_t *block, bool force) {
|
||||
if (mfReadOnlyAccessConditions(foo, &block[6])) {
|
||||
// WARNING: Sectors 33+ assume ACLs apply to groups of 4 blocks, not 1 block.
|
||||
// The code as-is is bugged and actually wastes iterations. If you have 16 blocks, it'll run all 16 but only error out like it's a 4-block sector.
|
||||
if (blockno < 128)
|
||||
if (blockno < 128) {
|
||||
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on block " _YELLOW_("%u") " detected", blockno - bar + 1 + foo);
|
||||
else
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "Strict ReadOnly Access Conditions on blocks " _YELLOW_("%u-%u") " detected", blockno - bar * 4 + 1 + foo * 5, blockno - bar * 4 + 1 + foo * 5 + 4);
|
||||
}
|
||||
ro_detected = true;
|
||||
}
|
||||
}
|
||||
@@ -1174,7 +1181,7 @@ static int CmdHFMFPWrbl(const char *Cmd) {
|
||||
|
||||
mfpSetVerboseMode(verbose);
|
||||
|
||||
if (!keylen) {
|
||||
if (keylen == 0) {
|
||||
memmove(key, mfp_default_key, 16);
|
||||
keylen = 16;
|
||||
}
|
||||
@@ -1214,7 +1221,7 @@ static int CmdHFMFPWrbl(const char *Cmd) {
|
||||
|
||||
mf4Session_t mf4session;
|
||||
int res = MifareAuth4(&mf4session, keyn, key, false, true, true, true, verbose, false);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Authentication error: %d", res);
|
||||
return res;
|
||||
}
|
||||
@@ -1227,7 +1234,7 @@ static int CmdHFMFPWrbl(const char *Cmd) {
|
||||
int datalen = 0;
|
||||
uint8_t mac[8] = {0};
|
||||
res = MFPWriteBlock(&mf4session, plain, nomacres, blockNum & 0xff, 0x00, datain, false, false, data, sizeof(data), &datalen, mac);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Write error: %d", res);
|
||||
DropField();
|
||||
return res;
|
||||
@@ -1245,13 +1252,14 @@ static int CmdHFMFPWrbl(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (memcmp(&data[1], mac, 8) && !nomacres) {
|
||||
if (memcmp(&data[1], mac, 8) && nomacres == false) {
|
||||
PrintAndLogEx(WARNING, "WARNING: mac not equal...");
|
||||
PrintAndLogEx(WARNING, "MAC card: %s", sprint_hex(&data[1], 8));
|
||||
PrintAndLogEx(WARNING, "MAC reader: %s", sprint_hex(mac, 8));
|
||||
} else if (!nomacres) {
|
||||
if (verbose)
|
||||
} else if (nomacres == false) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(INFO, "MAC: %s", sprint_hex(&data[1], 8));
|
||||
}
|
||||
}
|
||||
|
||||
DropField();
|
||||
@@ -1302,7 +1310,7 @@ static int CmdHFMFPChKey(const char *Cmd) {
|
||||
|
||||
mfpSetVerboseMode(verbose);
|
||||
|
||||
if (!keylen) {
|
||||
if (keylen == 0) {
|
||||
memmove(key, mfp_default_key, 16);
|
||||
keylen = 16;
|
||||
}
|
||||
@@ -1367,11 +1375,11 @@ static int CmdHFMFPChKey(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (memcmp(&data[1], mac, 8) && !nomacres) {
|
||||
if (memcmp(&data[1], mac, 8) && nomacres == false) {
|
||||
PrintAndLogEx(WARNING, "WARNING: mac not equal...");
|
||||
PrintAndLogEx(WARNING, "MAC card: %s", sprint_hex(&data[1], 8));
|
||||
PrintAndLogEx(WARNING, "MAC reader: %s", sprint_hex(mac, 8));
|
||||
} else if (!nomacres) {
|
||||
} else if (nomacres == false) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(INFO, "MAC: %s", sprint_hex(&data[1], 8));
|
||||
}
|
||||
@@ -1456,7 +1464,7 @@ static int CmdHFMFPChConf(const char *Cmd) {
|
||||
}
|
||||
|
||||
int res = MifareAuth4(&mf4session, keyn, key, false, true, true, true, verbose, false);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Authentication error: %d", res);
|
||||
return res;
|
||||
}
|
||||
@@ -1467,7 +1475,7 @@ static int CmdHFMFPChConf(const char *Cmd) {
|
||||
int datalen = 0;
|
||||
uint8_t mac[8] = {0};
|
||||
res = MFPWriteBlock(&mf4session, false, nomacres, blockNum & 0xff, 0xb0, datain, false, false, data, sizeof(data), &datalen, mac);
|
||||
if (res) {
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Write error: %d", res);
|
||||
DropField();
|
||||
return res;
|
||||
@@ -1485,7 +1493,7 @@ static int CmdHFMFPChConf(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (memcmp(&data[1], mac, 8) && !nomacres) {
|
||||
if (memcmp(&data[1], mac, 8) && nomacres == false) {
|
||||
PrintAndLogEx(WARNING, "WARNING: mac not equal...");
|
||||
PrintAndLogEx(WARNING, "MAC card: %s", sprint_hex(&data[1], 8));
|
||||
PrintAndLogEx(WARNING, "MAC reader: %s", sprint_hex(mac, 8));
|
||||
|
||||
Reference in new issue
Block a user