From 4e922e81942c4f339d5b014c769f4591620add44 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 25 Jun 2020 23:32:03 +0200 Subject: [PATCH] sends lib log to /dev/null in posix and added option (v) to reactivate There in an error handling and messaging inside --- utils/nfc-mfclassic.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index a159990..28444c5 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -54,6 +54,12 @@ #include #include +#ifndef _WIN32 +#include +#include +#include +#endif + #include #include "mifare.h" @@ -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> [ [f] [v]]\n", pcProgramName); + #else printf("%s f|r|R|w|W a|b u|U<01ab23cd> [ [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"); @@ -582,7 +592,9 @@ print_usage(const char *pcProgramName) printf(" - MiFare Dump (MFD) used to write (card to MFD) or (MFD to card)\n"); printf(" - 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); @@ -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);