diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 847f553..ceb54cd 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -69,7 +69,7 @@ static bool bUseKeyFile; static bool bForceKeyFile; static bool bTolerateFailures; static bool bFormatCard; -static bool magic2 = false; +static bool magic_type2a = false; static bool unlocked = false; static uint8_t uiBlocks; static uint8_t keys[] = { @@ -315,9 +315,9 @@ read_card(int read_unlocked) if (read_unlocked) { //If the user is attempting an unlocked read, but has a direct-write type magic card, they don't //need to use the R mode. We'll trigger a warning and let them proceed. - if (magic2) { + if (magic_type2a) { printf("Note: This card does not require an unlocked read (R) \n"); - read_unlocked = 0; + read_unlocked = false; } else { //If User has requested an unlocked read, but we're unable to unlock the card, we'll error out. if (!unlock_card()) { @@ -386,18 +386,18 @@ read_card(int read_unlocked) } static bool -write_card(int write_block_zero) +write_card(bool write_unlocked) { uint32_t uiBlock; bool bFailure = false; uint32_t uiWriteBlocks = 0; - if (write_block_zero) { + if (write_unlocked) { //If the user is attempting an unlocked write, but has a direct-write type magic card, they don't //need to use the W mode. We'll trigger a warning and let them proceed. - if (magic2) { + if (magic_type2a) { printf("Note: This card does not require an unlocked write (W) \n"); - write_block_zero = 0; + write_unlocked = false; } else { //If User has requested an unlocked write, but we're unable to unlock the card, we'll error out. if (!unlock_card()) { @@ -423,7 +423,7 @@ write_card(int write_block_zero) fflush(stdout); // Try to authenticate for the current sector - if (!write_block_zero && !authenticate(uiBlock) && !bTolerateFailures) { + if (!write_unlocked && !authenticate(uiBlock) && !bTolerateFailures) { printf("!\nError: authentication failed for block %02x\n", uiBlock); return false; } @@ -449,7 +449,7 @@ write_card(int write_block_zero) } } else { // The first block 0x00 is read only, skip this - if (uiBlock == 0 && !write_block_zero && !magic2) + if (uiBlock == 0 && !write_unlocked && !magic_type2a) continue; @@ -462,7 +462,7 @@ write_card(int write_block_zero) memcpy(mp.mpd.abtData, mtDump.amb[uiBlock].mbd.abtData, sizeof(mp.mpd.abtData)); // do not write a block 0 with incorrect BCC - card will be made invalid! if (uiBlock == 0) { - if ((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00 && !magic2) { + if ((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00 && !magic_type2a) { printf("!\nError: incorrect BCC in MFD file!\n"); printf("Expecting BCC=%02X\n", mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3]); return false; @@ -527,7 +527,7 @@ main(int argc, const char *argv[]) uint8_t _tag_uid[4]; uint8_t *tag_uid = _tag_uid; - int unlock = 0; + bool unlock = false; if (argc < 2) { print_usage(argv[0]); @@ -542,7 +542,7 @@ main(int argc, const char *argv[]) if (strcmp(command, "r") == 0 || strcmp(command, "R") == 0) { atAction = ACTION_READ; if (strcmp(command, "R") == 0) - unlock = 1; + unlock = true; bUseKeyA = tolower((int)((unsigned char) * (argv[2]))) == 'a'; bTolerateFailures = tolower((int)((unsigned char) * (argv[2]))) != (int)((unsigned char) * (argv[2])); bUseKeyFile = (argc > 5); @@ -550,7 +550,7 @@ main(int argc, const char *argv[]) } else if (strcmp(command, "w") == 0 || strcmp(command, "W") == 0 || strcmp(command, "f") == 0) { atAction = ACTION_WRITE; if (strcmp(command, "W") == 0) - unlock = 1; + unlock = true; bFormatCard = (strcmp(command, "f") == 0); bUseKeyA = tolower((int)((unsigned char) * (argv[2]))) == 'a'; bTolerateFailures = tolower((int)((unsigned char) * (argv[2]))) != (int)((unsigned char) * (argv[2])); @@ -693,7 +693,7 @@ main(int argc, const char *argv[]) // Chinese magic emulation card, ATS=0978009102:dabc1910 if ((res == 9) && (abtRx[5] == 0xda) && (abtRx[6] == 0xbc) && (abtRx[7] == 0x19) && (abtRx[8] == 0x10)) { - magic2 = true; + magic_type2a = true; } } else printf("RATS support: no\n");