Sfoglia il codice sorgente

bug fix, colorise out, reorganize dumps

Pi3rrot 8 anni fa
parent
commit
772ad8e782
10 ha cambiato i file con 46 aggiunte e 29 eliminazioni
  1. 9 2
      Makefile
  2. 7 0
      color.h
  3. BIN
      dump/blank_card.mfd
  4. BIN
      dump/dom_me.mfd
  5. BIN
      dump/lim_09.mfd
  6. BIN
      dump/lim_10.mfd
  7. BIN
      dump/lim_10_yseult.mfd
  8. BIN
      dump/lim_kash.mfd
  9. BIN
      poolset
  10. 30 27
      poolset.c

+ 9 - 2
Makefile

@@ -1,6 +1,13 @@
 restore_tag:
-	nfc-mfclassic f A orig_10.mfd orig_10.mdf f
-	nfc-mfclassic w a orig_10.mfd
+	nfc-mfclassic f A dump/lim_10.mfd dump/lim_10.mfd f
+	nfc-mfclassic w a dump/lim_10.mfd f
+
+selecta_change_from_orig:
+	mfoc -O temp.mfd
+	nfc-mfclassic f B dump/lim_10.mfd temp.mfd f
+	nfc-mfclassic w A dump/lim_10.mfd
+	rm temp.mfd
+	./poolset --write 10 25/11/16 25/11/19
 
 all:
 	gcc -o poolset -lusb -lnfc -lfreefare poolset.c

+ 7 - 0
color.h

@@ -0,0 +1,7 @@
+#define ANSI_COLOR_RED     "\x1b[31m"
+#define ANSI_COLOR_GREEN   "\x1b[32m"
+#define ANSI_COLOR_YELLOW  "\x1b[33m"
+#define ANSI_COLOR_BLUE    "\x1b[34m"
+#define ANSI_COLOR_MAGENTA "\x1b[35m"
+#define ANSI_COLOR_CYAN    "\x1b[36m"
+#define ANSI_COLOR_RESET   "\x1b[0m"

BIN
dump/blank_card.mfd


BIN
dump/dom_me.mfd


BIN
dump/lim_09.mfd


BIN
dump/lim_10.mfd


BIN
dump/lim_10_yseult.mfd


BIN
dump/lim_kash.mfd


BIN
poolset


+ 30 - 27
poolset.c

@@ -4,6 +4,7 @@
 
 #include <nfc/nfc.h>
 #include <freefare.h>
+#include "color.h"
 
 MifareClassicKey SecretKey[] = { 0x00, 0x01, 0x31, 0xB9, 0x3F, 0x28 };
 MifareClassicBlock data_read4;
@@ -26,52 +27,55 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
 
 	nfc_init(&context);			
 	if(context == NULL) {
-		printf("[x] Unable to init libnf\n");
+		printf("[x] Unable to init libnfc !\n");
 		exit(EXIT_FAILURE);
 	}
 
 	pnd = nfc_open(context, NULL);
 	if (pnd == NULL) {
-		printf("[x] Unable to open NFC device\n");
+		printf("[x] Unable to open NFC device !\n");
 		exit(EXIT_FAILURE);
 	}
-	printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));
-	
-	//tags = freefare_get_tags(pnd);
-	while(!tags) {
-		printf("Hey, i'm Waiting for my tag...\n");
+
+	tags = freefare_get_tags(pnd);
+	printf("NFC reader: "ANSI_COLOR_GREEN"%s"ANSI_COLOR_RESET" opened and waiting for a tag\n", nfc_device_get_name(pnd));
+
+	while(*tags == NULL) {
+		printf(".");
+		fflush(stdout);
 		sleep(1);
 		tags = freefare_get_tags(pnd);
 	}
+	printf("\n");
 	
 	for(i=0; tags[i]; i++) {
 		switch(freefare_get_tag_type(tags[i])) {
 			case MIFARE_CLASSIC_1K:
-				printf("=> Tag number %u with UID %s type Mifare 1k (S50) found !\n", i, freefare_get_tag_uid(tags[i]) );
+				printf("=> Tag number "ANSI_COLOR_YELLOW"%u"ANSI_COLOR_RESET" with UID "ANSI_COLOR_YELLOW"%s"ANSI_COLOR_RESET" type Mifare 1k (S50) found !\n", i, freefare_get_tag_uid(tags[i]) );
 				break;
 
 			case MIFARE_MINI:
-				printf("=> Tag number %u with UID %s type Mifare Mini 0.3k (S50) found !\n", i, freefare_get_tag_uid(tags[i]) );
+				printf("=> Tag number "ANSI_COLOR_YELLOW"%u"ANSI_COLOR_RESET" with UID "ANSI_COLOR_YELLOW"%s"ANSI_COLOR_RESET" type Mifare Mini 0.3k (S50) found !\n", i, freefare_get_tag_uid(tags[i]) );
 				break;
 
 			default:
-				printf("[x] Wrong tag Mr Dugland !\n");
+				printf(ANSI_COLOR_RED"[x] Wrong tag Mr Dugland !\n"ANSI_COLOR_RESET);
 				break;
 				exit(EXIT_FAILURE);
 			}
 
 
-			printf("=> Trying to authenticate with SecretKey %.2x %.2x %.2x %.2x %.2x %.2x ...\n", SecretKey[0][0], SecretKey[0][1], SecretKey[0][2], SecretKey[0][3], SecretKey[0][4], SecretKey[0][5]);
+			printf("=> Trying to authenticate with SecretKey "ANSI_COLOR_YELLOW"%.2x %.2x %.2x %.2x %.2x %.2x"ANSI_COLOR_RESET" ...\n", SecretKey[0][0], SecretKey[0][1], SecretKey[0][2], SecretKey[0][3], SecretKey[0][4], SecretKey[0][5]);
 
 			if(mifare_classic_connect(tags[i]) == OPERATION_OK) {
-				printf("=> Mifare tag connected !\n");
+				printf(ANSI_COLOR_GREEN"=> Mifare tag connected !\n"ANSI_COLOR_RESET);
 			}
-			else printf("Non ca chie dans la colle mais grave, ton tag est moisi\n");
+			else printf(ANSI_COLOR_RED"Non ca chie dans la colle mais grave, ton tag est moisi\n"ANSI_COLOR_RESET);
 			
 			if(mifare_classic_authenticate(tags[i], 5, SecretKey[0], MFC_KEY_A) == OPERATION_OK) {
-				printf("=> Tag authenticated !\n");
+				printf(ANSI_COLOR_GREEN"=> Tag authenticated !\n"ANSI_COLOR_RESET);
 			}
-			else printf("Non ca chie dans la colle mais grave, check ta clé\n");
+			else printf(ANSI_COLOR_RED"Non ca chie dans la colle mais grave, check ta clé\n"ANSI_COLOR_RESET);
 
 			if(coins != 0 && buy_date != NULL && expire_date != NULL) {
 
@@ -99,9 +103,10 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
 
 				if(mifare_classic_write(tags[i], 5, &data_read5) == OPERATION_OK) {
 					if(mifare_classic_read(tags[i], 5, &data_read5) == OPERATION_OK) {
-						printf("=> %.2d credits found now !\n", data_read5[7]);
+						printf("=> "ANSI_COLOR_GREEN"%.2d"ANSI_COLOR_RESET" credits found now !\n", data_read5[7]);
 					} 
 				}
+				printf("Reading a second time to check...\n");
 			} 
 
 
@@ -109,12 +114,12 @@ void rw_tag(int coins, char *buy_date, char *expire_date) {
 				&& 
 				(mifare_classic_read(tags[i], 4, &data_read4) == OPERATION_OK) )
 			{
-				printf("  => INFOS\n");
-				printf("  => Company Serial :\t%.2x %.2x %.2x %.2x\n", data_read4[0], data_read4[1], data_read4[2], data_read4[3]);
-				printf("  => Credits :\t\t%.2d\n", data_read5[7]);
-				printf("  => Buy date :\t\t%.2d/%.2d/%.2d\n", data_read5[0], data_read5[1], data_read5[2]);
-				printf("  => Expiration date :\t%.2d/%.2d/%.2d\n", data_read5[3], data_read5[4], data_read5[5]);
-				//printf("  => Card keeped :");
+				printf(ANSI_COLOR_YELLOW"=-=-=-=-=-=-=- INFOS -=-=-=-=-=-=-=-=\n"ANSI_COLOR_RESET);
+				printf("  => Company Serial :\t"ANSI_COLOR_YELLOW"%.2x %.2x %.2x %.2x\n"ANSI_COLOR_RESET, data_read4[0], data_read4[1], data_read4[2], data_read4[3]);
+				printf("  => Credits :\t\t"ANSI_COLOR_YELLOW"%.2d\n"ANSI_COLOR_RESET, data_read5[7]);
+				printf("  => Buy date :\t\t"ANSI_COLOR_YELLOW"%.2d/%.2d/%.2d\n"ANSI_COLOR_RESET, data_read5[0], data_read5[1], data_read5[2]);
+				printf("  => Expiration date :\t"ANSI_COLOR_YELLOW"%.2d/%.2d/%.2d\n"ANSI_COLOR_RESET, data_read5[3], data_read5[4], data_read5[5]);
+				//printf("  => Card keeped :\t");
 			} 
 
 
@@ -137,13 +142,11 @@ int main(int argc, const char **argv) {
 	printf("RFID Poolset Read/Write !\n");
 	printf("=========================\n");
 
-	if(argc == 1)
-		show_menu();
-	//else coins = atoi(argv[1]);
 	if (strcmp(argv[1], "--read") == 0)
 		rw_tag(NULL, NULL, NULL);
 	
-	if (strcmp(argv[1], "--write") == 0)
+	else if (strcmp(argv[1], "--write") == 0)
 		rw_tag(atoi(argv[2]), argv[3], argv[4]);
-
+	else
+		show_menu();
 }