commit f6defc402e191d1a5594bc92748c646c30697616 Author: Fijxu Date: Thu Dec 14 16:17:51 2023 -0300 asdasdasdasdl;kkaspjoyui8d67hbgasd8us7aidsa diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4d7f488 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +all: + gcc -g -o main main.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..a9e998e --- /dev/null +++ b/main.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include + +#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" + +void read_file(FILE *file) { + int count = 0; + unsigned char buffer[1000000]; + size_t bytesRead; + while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) { + for (size_t i = 0; i < bytesRead; i++) { + printf("%02x ", buffer[i]); + if(++count % 16 == 0) { + puts(""); + } + } + } +} + +void get_size(FILE *file, int argc, char *argv[]) { + fseek(file, 0L, SEEK_END); + long bytes = ftell(file); + fseek(file, 0L, SEEK_SET); + if (bytes == 1024) { + printf("Bytes of %s: %ld\n", argv[argc-1], bytes); + puts("This looks like a Mifare Classic 1K dump file"); + } else if (bytes == 4096) { + printf("Bytes of %s: %ld\n", argv[argc-1], bytes); + puts("This lokks like a Mifare Classic 4K dump file"); + } else { + printf("Bytes of %s: %ld\n", argv[argc-1], bytes); + printf(ANSI_COLOR_RED "This doesn't look like a Mifare Classic 1K or 4K at all\n" ANSI_COLOR_RESET); + } +} + +int main (int argc, char *argv[]) { + if (argc <= 1) + { + printf("Usage:\n %s [OPTION]... [FILE]\n\n", argv[0]); + puts("Tool to modify Mifare Classic dump files"); + puts("\nOptions:"); + puts("\t-s display the size of the file in bytes\n"); + exit(EXIT_SUCCESS); + } + + struct option longopts[] = { + {"size", no_argument, NULL, 's'}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'V'}, + {NULL, no_argument, NULL, 0} + }; + + FILE *file; + unsigned char ch; + char *binfile = malloc(64 * sizeof(char)); + if ( binfile == NULL ) { + puts("Failed to allocate memory"); + exit(EXIT_FAILURE); + } + + file = fopen(argv[argc-1], "rb"); + if( file == NULL ) + { + perror("Error while opening the file"); + exit(EXIT_FAILURE); + } + + + int args; + while ((args = getopt_long(argc, argv, "s", longopts, NULL)) != -1) { + switch (args) { + case 's': + { + get_size(file, argc, argv); + } + default: + exit(EXIT_SUCCESS); + } + } + + read_file(file); + + fclose(file); + free(binfile); + exit(EXIT_SUCCESS); + +}