Adds --check-magic flag to nfc-mfultralight
This commit is contained in:
parent
3aa2d46588
commit
0cece94778
1 changed files with 64 additions and 14 deletions
|
@ -107,6 +107,43 @@ read_card(void)
|
||||||
return (!bFailure);
|
return (!bFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool check_magic() {
|
||||||
|
bool bFailure = false;
|
||||||
|
int uid_data;
|
||||||
|
|
||||||
|
for (uint32_t page = 0; page <= 1; page++) {
|
||||||
|
// Show if the readout went well
|
||||||
|
if (bFailure) {
|
||||||
|
// When a failure occured we need to redo the anti-collision
|
||||||
|
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) {
|
||||||
|
ERR("tag was removed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bFailure = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uid_data = 0x00000000;
|
||||||
|
|
||||||
|
memcpy(mp.mpd.abtData, &uid_data, sizeof uid_data);
|
||||||
|
memset(mp.mpd.abtData + 4, 0, 12);
|
||||||
|
|
||||||
|
//Force the write without checking for errors - otherwise the writes to the sector 0 seem to complain
|
||||||
|
nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check that the ID is now set to 0x000000000000
|
||||||
|
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
||||||
|
//printf("%u", mp.mpd.abtData);
|
||||||
|
for(int i = 0; i <= 7; i++) {
|
||||||
|
if (mp.mpd.abtData[i] != 0x00) return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
write_card(bool write_otp, bool write_lock, bool write_uid)
|
write_card(bool write_otp, bool write_lock, bool write_uid)
|
||||||
{
|
{
|
||||||
|
@ -202,13 +239,13 @@ print_usage(const char *argv[])
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
bool bReadAction;
|
int iAction = 0;
|
||||||
bool bOTP;
|
bool bOTP = false;
|
||||||
bool bLock;
|
bool bLock = false;
|
||||||
bool bUID;
|
bool bUID = false;
|
||||||
FILE *pfDump;
|
FILE *pfDump;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc == 0) {
|
||||||
print_usage(argv);
|
print_usage(argv);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -218,9 +255,9 @@ main(int argc, const char *argv[])
|
||||||
// Get commandline options
|
// Get commandline options
|
||||||
for (int arg = 1; arg < argc; arg++) {
|
for (int arg = 1; arg < argc; arg++) {
|
||||||
if (0 == strcmp(argv[arg], "r")) {
|
if (0 == strcmp(argv[arg], "r")) {
|
||||||
bReadAction = true;
|
iAction = 1;
|
||||||
} else if (0 == strcmp(argv[arg], "w")) {
|
} else if (0 == strcmp(argv[arg], "w")) {
|
||||||
bReadAction = false;
|
iAction = 2;
|
||||||
} else if (0 == strcmp(argv[arg], "--full")) {
|
} else if (0 == strcmp(argv[arg], "--full")) {
|
||||||
bOTP = true;
|
bOTP = true;
|
||||||
bLock = true;
|
bLock = true;
|
||||||
|
@ -231,6 +268,8 @@ main(int argc, const char *argv[])
|
||||||
bLock = true;
|
bLock = true;
|
||||||
} else if (0 == strcmp(argv[arg], "--uid")) {
|
} else if (0 == strcmp(argv[arg], "--uid")) {
|
||||||
bUID = true;
|
bUID = true;
|
||||||
|
} else if (0 == strcmp(argv[arg], "--check-magic")) {
|
||||||
|
iAction = 3;
|
||||||
} else {
|
} else {
|
||||||
//Skip validation of the filename
|
//Skip validation of the filename
|
||||||
if (arg != 2) {
|
if (arg != 2) {
|
||||||
|
@ -241,10 +280,9 @@ main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (iAction == 1) {
|
||||||
if (bReadAction) {
|
|
||||||
memset(&mtDump, 0x00, sizeof(mtDump));
|
memset(&mtDump, 0x00, sizeof(mtDump));
|
||||||
} else {
|
} else if (iAction == 2) {
|
||||||
pfDump = fopen(argv[2], "rb");
|
pfDump = fopen(argv[2], "rb");
|
||||||
|
|
||||||
if (pfDump == NULL) {
|
if (pfDump == NULL) {
|
||||||
|
@ -258,8 +296,13 @@ main(int argc, const char *argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
fclose(pfDump);
|
fclose(pfDump);
|
||||||
|
DBG("Successfully opened the dump file\n");
|
||||||
|
} else if (iAction == 3) {
|
||||||
|
DBG("Switching to Check Magic Mode\n");
|
||||||
|
} else {
|
||||||
|
ERR("Unable to determine operating mode");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
DBG("Successfully opened the dump file\n");
|
|
||||||
|
|
||||||
nfc_context *context;
|
nfc_context *context;
|
||||||
nfc_init(&context);
|
nfc_init(&context);
|
||||||
|
@ -316,7 +359,7 @@ main(int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
if (bReadAction) {
|
if (iAction == 1) {
|
||||||
if (read_card()) {
|
if (read_card()) {
|
||||||
printf("Writing data to file: %s ... ", argv[2]);
|
printf("Writing data to file: %s ... ", argv[2]);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -337,8 +380,15 @@ main(int argc, const char *argv[])
|
||||||
fclose(pfDump);
|
fclose(pfDump);
|
||||||
printf("Done.\n");
|
printf("Done.\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else if (iAction == 2) {
|
||||||
write_card(bOTP, bLock, bUID);
|
write_card(bOTP, bLock, bUID);
|
||||||
|
} else if (iAction == 3) {
|
||||||
|
if (!check_magic()) {
|
||||||
|
printf("Card is not magic\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else {
|
||||||
|
printf("Card is magic\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nfc_close(pnd);
|
nfc_close(pnd);
|
||||||
|
|
Loading…
Reference in a new issue