Added automatic mode to nfc-mfultralight
This commit is contained in:
parent
48c271e49d
commit
3aa2d46588
1 changed files with 67 additions and 26 deletions
|
@ -101,14 +101,14 @@ read_card(void)
|
||||||
print_success_or_failure(bFailure, &uiReadedPages);
|
print_success_or_failure(bFailure, &uiReadedPages);
|
||||||
}
|
}
|
||||||
printf("|\n");
|
printf("|\n");
|
||||||
printf("Done, %d of %d pages readed.\n", uiReadedPages, uiBlocks + 1);
|
printf("Done, %d of %d pages read.\n", uiReadedPages, uiBlocks + 1);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
return (!bFailure);
|
return (!bFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
write_card(void)
|
write_card(bool write_otp, bool write_lock, bool write_uid)
|
||||||
{
|
{
|
||||||
uint32_t uiBlock = 0;
|
uint32_t uiBlock = 0;
|
||||||
bool bFailure = false;
|
bool bFailure = false;
|
||||||
|
@ -116,25 +116,30 @@ write_card(void)
|
||||||
uint32_t uiSkippedPages = 0;
|
uint32_t uiSkippedPages = 0;
|
||||||
|
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
bool write_otp;
|
|
||||||
bool write_lock;
|
|
||||||
bool write_uid;
|
|
||||||
|
|
||||||
printf("Write OTP bytes ? [yN] ");
|
if (!write_otp) {
|
||||||
if (!fgets(buffer, BUFSIZ, stdin)) {
|
printf("Write OTP bytes ? [yN] ");
|
||||||
ERR("Unable to read standard input.");
|
if (!fgets(buffer, BUFSIZ, stdin)) {
|
||||||
|
ERR("Unable to read standard input.");
|
||||||
|
}
|
||||||
|
write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||||
}
|
}
|
||||||
write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
|
||||||
printf("Write Lock bytes ? [yN] ");
|
if (!write_lock) {
|
||||||
if (!fgets(buffer, BUFSIZ, stdin)) {
|
printf("Write Lock bytes ? [yN] ");
|
||||||
ERR("Unable to read standard input.");
|
if (!fgets(buffer, BUFSIZ, stdin)) {
|
||||||
|
ERR("Unable to read standard input.");
|
||||||
|
}
|
||||||
|
write_lock = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||||
}
|
}
|
||||||
write_lock = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
|
||||||
printf("Write UID bytes (only for special writeable UID cards) ? [yN] ");
|
if (!write_uid) {
|
||||||
if (!fgets(buffer, BUFSIZ, stdin)) {
|
printf("Write UID bytes (only for special writeable UID cards) ? [yN] ");
|
||||||
ERR("Unable to read standard input.");
|
if (!fgets(buffer, BUFSIZ, stdin)) {
|
||||||
|
ERR("Unable to read standard input.");
|
||||||
|
}
|
||||||
|
write_uid = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||||
}
|
}
|
||||||
write_uid = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
|
||||||
|
|
||||||
printf("Writing %d pages |", uiBlocks + 1);
|
printf("Writing %d pages |", uiBlocks + 1);
|
||||||
/* We may need to skip 2 first pages. */
|
/* We may need to skip 2 first pages. */
|
||||||
|
@ -181,25 +186,61 @@ write_card(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_usage(const char *argv[])
|
||||||
|
{
|
||||||
|
printf("Usage: %s r|w <dump.mfd> [OPTIONS]\n", argv[0]);
|
||||||
|
printf("Options:\n");
|
||||||
|
printf("\tr|w\t\t - Perform read or write\n");
|
||||||
|
printf("\t<dump.mfd>\t - MiFare Dump (MFD) used to write (card to MFD) or (MFD to card)\n");
|
||||||
|
printf("\t--otp\t\t - Don't prompt for OTP writing (Assume yes)\n");
|
||||||
|
printf("\t--lock\t\t - Don't prompt for Lockbit writing (Assume yes)\n");
|
||||||
|
printf("\t--uid\t\t - Don't prompt for UID writing (Assume yes)\n");
|
||||||
|
printf("\t--full\t\t - Assume full card write (UID + OTP + Lockbit)\n");
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
bool bReadAction;
|
bool bReadAction;
|
||||||
|
bool bOTP;
|
||||||
|
bool bLock;
|
||||||
|
bool bUID;
|
||||||
FILE *pfDump;
|
FILE *pfDump;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
printf("\n");
|
print_usage(argv);
|
||||||
printf("%s r|w <dump.mfd>\n", argv[0]);
|
exit(EXIT_FAILURE);
|
||||||
printf("\n");
|
|
||||||
printf("r|w - Perform read from or write to card\n");
|
|
||||||
printf("<dump.mfd> - MiFare Dump (MFD) used to write (card to MFD) or (MFD to card)\n");
|
|
||||||
printf("\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DBG("\nChecking arguments and settings\n");
|
DBG("\nChecking arguments and settings\n");
|
||||||
|
|
||||||
bReadAction = tolower((int)((unsigned char) * (argv[1])) == 'r');
|
// Get commandline options
|
||||||
|
for (int arg = 1; arg < argc; arg++) {
|
||||||
|
if (0 == strcmp(argv[arg], "r")) {
|
||||||
|
bReadAction = true;
|
||||||
|
} else if (0 == strcmp(argv[arg], "w")) {
|
||||||
|
bReadAction = false;
|
||||||
|
} else if (0 == strcmp(argv[arg], "--full")) {
|
||||||
|
bOTP = true;
|
||||||
|
bLock = true;
|
||||||
|
bUID = true;
|
||||||
|
} else if (0 == strcmp(argv[arg], "--otp")) {
|
||||||
|
bOTP = true;
|
||||||
|
} else if (0 == strcmp(argv[arg], "--lock")) {
|
||||||
|
bLock = true;
|
||||||
|
} else if (0 == strcmp(argv[arg], "--uid")) {
|
||||||
|
bUID = true;
|
||||||
|
} else {
|
||||||
|
//Skip validation of the filename
|
||||||
|
if (arg != 2) {
|
||||||
|
ERR("%s is not supported option.", argv[arg]);
|
||||||
|
print_usage(argv);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (bReadAction) {
|
if (bReadAction) {
|
||||||
memset(&mtDump, 0x00, sizeof(mtDump));
|
memset(&mtDump, 0x00, sizeof(mtDump));
|
||||||
|
@ -297,7 +338,7 @@ main(int argc, const char *argv[])
|
||||||
printf("Done.\n");
|
printf("Done.\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
write_card();
|
write_card(bOTP, bLock, bUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
nfc_close(pnd);
|
nfc_close(pnd);
|
||||||
|
|
Loading…
Add table
Reference in a new issue