Skip to content

Commit

Permalink
sends lib log to /dev/null in posix and added option (v) to reactivate
Browse files Browse the repository at this point in the history
There in an error handling and messaging inside
  • Loading branch information
gelotus committed Jun 25, 2020
1 parent 3f4b7a0 commit 4e922e8
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion utils/nfc-mfclassic.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
#include <string.h>
#include <ctype.h>

#ifndef _WIN32
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#endif

#include <nfc/nfc.h>

#include "mifare.h"
Expand Down Expand Up @@ -571,7 +577,11 @@ static void
print_usage(const char *pcProgramName)
{
printf("Usage: ");
#ifndef _WIN32
printf("%s f|r|R|w|W a|b u|U<01ab23cd> <dump.mfd> [<keys.mfd> [f] [v]]\n", pcProgramName);
#else
printf("%s f|r|R|w|W a|b u|U<01ab23cd> <dump.mfd> [<keys.mfd> [f]]\n", pcProgramName);
#endif
printf(" f|r|R|w|W - Perform format (f) or read from (r) or unlocked read from (R) or write to (w) or unlocked write to (W) card\n");
printf(" *** format will reset all keys to FFFFFFFFFFFF and all data to 00 and all ACLs to default\n");
printf(" *** unlocked read does not require authentication and will reveal A and B keys\n");
Expand All @@ -582,7 +592,9 @@ print_usage(const char *pcProgramName)
printf(" <dump.mfd> - MiFare Dump (MFD) used to write (card to MFD) or (MFD to card)\n");
printf(" <keys.mfd> - MiFare Dump (MFD) that contain the keys (optional)\n");
printf(" f - Force using the keyfile even if UID does not match (optional)\n");

#ifndef _WIN32
printf(" v - Sends libnfc log output to console (optional)\n");
#endif
printf("Examples: \n\n");
printf(" Read card to file, using key A:\n\n");
printf(" %s r a u mycard.mfd\n\n", pcProgramName);
Expand Down Expand Up @@ -706,6 +718,21 @@ main(int argc, const char *argv[])
tag_uid = NULL;
}

#ifndef _WIN32
// Send noise from lib to /dev/null
bool verbose = false;
if (argv[7]) {
if (strcmp(argv[7], "v") == 0) verbose = true;
} else {
if (strcmp(argv[6], "v") == 0) verbose = true;
}
if (!verbose) {
int fd = open("/dev/null", O_WRONLY);
dup2(fd, 2);
close(fd);
}
#endif

if (atAction == ACTION_USAGE) {
print_usage(argv[0]);
exit(EXIT_FAILURE);
Expand Down

0 comments on commit 4e922e8

Please sign in to comment.