diff options
Diffstat (limited to 'easytool/easytool.c')
-rw-r--r-- | easytool/easytool.c | 81 |
1 files changed, 74 insertions, 7 deletions
diff --git a/easytool/easytool.c b/easytool/easytool.c index 67157c8..c504003 100644 --- a/easytool/easytool.c +++ b/easytool/easytool.c @@ -27,6 +27,7 @@ #include <fcntl.h> #include <string.h> #include <time.h> +#include <getopt.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> @@ -41,16 +42,24 @@ /* Easycard specific includes */ #include "easycard.h" -#define VERSION "0.03" +#define VERSION "0.04" #define COPYRIGHT \ "EasyTool "VERSION" (C) 2010 by Harald Welte <laforge@gnumonks.org>\n" \ "This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n" \ "Use of this software is authorized for RESEARCH PURPOSE ONLY!\n\n" +enum mode { + MODE_DUMP_MFACC, + MODE_DUMP, + MODE_RECHARGE, + MODE_PURCHASE, +}; + struct { int fd; unsigned long size; mifare_tag *mft; + enum mode mode; } global; static void dump_acc_bits(const struct acc_bits_parsed *abp) @@ -128,17 +137,59 @@ static void print_help(void) int main(int argc, char **argv) { struct stat st; + int delta = 0; + int option_index = 0; + int rc; + int prot, flags = O_RDONLY; + + global.mode = MODE_DUMP; printf(COPYRIGHT); - if (argc < 2) { + while (1) { + int c; + static struct option long_options[] = { + { "dump-access-bits", 0, 0, 'a' }, + { "alter-recharge", 1, 0, 'r' }, + { "alter-purchase", 1, 0, 'p' }, + { "help", 0, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "r:p:ha", + long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'a': + global.mode = MODE_DUMP_MFACC; + break; + case 'r': + global.mode = MODE_RECHARGE; + flags = O_RDWR; + delta = atoi(optarg); + break; + case 'p': + global.mode = MODE_PURCHASE; + flags = O_RDWR; + delta = atoi(optarg); + break; + case 'h': + print_help(); + exit(0); + break; + } + }; + + if (argc <= optind) { fprintf(stderr, "ERROR: You must specify the file name of " "a mifare dump file (.mfd)\n"); print_help(); exit(2); } - global.fd = open(argv[1], O_RDONLY); + global.fd = open(argv[optind], flags); if (global.fd < 0) { perror("Error opening the MFD file"); exit(1); @@ -148,15 +199,31 @@ int main(int argc, char **argv) exit(1); } global.size = st.st_size; - global.mft = mmap(NULL, global.size, PROT_READ, MAP_SHARED, - global.fd, 0); + + prot = PROT_READ; + if (flags == O_RDWR) + prot |= PROT_WRITE; + + global.mft = mmap(NULL, global.size, prot, MAP_SHARED, global.fd, 0); if (!global.mft) { perror("Error mmap()ing the MFD file"); exit(1); } - //dump_mfcl(global.mft); - dump_easycard(global.mft); + switch (global.mode) { + case MODE_DUMP_MFACC: + dump_mfcl(global.mft); + break; + case MODE_DUMP: + dump_easycard(global.mft); + break; + case MODE_RECHARGE: + rc = easy_alter_last_recharge(global.mft, delta); + break; + case MODE_PURCHASE: + rc = easy_alter_last_purchase(global.mft, delta); + break; + } munmap(global.mft, global.size); close(global.fd); |