diff --git a/Makefile b/Makefile index 69b960b..19bc3ee 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-g -Wall +CFLAGS=-g -Wall -Iinclude SRC=src OBJ=obj SRCS=$(wildcard $(SRC)/*.c) diff --git a/blank16sectorcard b/blank16sectorcard index 1ac1d2a..cafae06 100644 Binary files a/blank16sectorcard and b/blank16sectorcard differ diff --git a/include/modifyUID.h b/include/modifyUID.h new file mode 100644 index 0000000..99b5dcd --- /dev/null +++ b/include/modifyUID.h @@ -0,0 +1,4 @@ +#include +#include "colors.h" + +void modifyUID(FILE *file); diff --git a/makefile b/makefile deleted file mode 100644 index 89899d8..0000000 --- a/makefile +++ /dev/null @@ -1,19 +0,0 @@ -CC = gcc -CFLAGS = -Wall -I$(INCLUDE) -INCLUDE = include -SRC_DIR = src -OBJ_DIR = obj -SRC = $(wildcard $(SRC_DIR)/*.c) -OBJ = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC)) -BIN = ./main - -all: $(BIN) - -$(BIN): $(OBJ) - $(CC) -o $@ $^ - -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c MKOBJ - $(CC) $(CFLAGS) -c $< -o $@ - -clean: - rm -f $(OBJ_DIR)/*.o $(BIN) diff --git a/src/getSize.c b/src/getSize.c index cfd274e..795757d 100644 --- a/src/getSize.c +++ b/src/getSize.c @@ -5,7 +5,7 @@ void getSize(FILE *file, int argc, char *argv[]) { fseek(file, 0L, SEEK_END); long bytes = ftell(file); - fseek(file, 0L, SEEK_SET); + rewind(file); // <== Same as `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"); diff --git a/src/main.c b/src/main.c index 676be69..7ec0fdb 100644 --- a/src/main.c +++ b/src/main.c @@ -6,28 +6,35 @@ #include "getSize.h" #include "readFile.h" +#include "modifyUID.h" int main(int argc, char *argv[]) { - if (argv[argc] == 1) { + if (argc <= 1) { + puts("Please, specify a file next to the executable\n"); + printf("Example:\n\t%s [file]\n", argv[0]); + exit(EXIT_SUCCESS); + } + FILE *file; + char *binfile = malloc(64 * sizeof(char)); + if (binfile == NULL) { + puts("Failed to allocate memory"); + exit(EXIT_FAILURE); + } - FILE *file; - char *binfile = malloc(64 * sizeof(char)); - if (binfile == NULL) { - puts("Failed to allocate memory"); - exit(EXIT_FAILURE); - } + file = fopen(argv[argc - 1], "r+b"); + if (file == NULL) { + perror("Error while opening the file"); + exit(EXIT_FAILURE); + } - file = fopen(argv[argc - 1], "rb"); - if (file == NULL) { - perror("Error while opening the file"); - exit(EXIT_FAILURE); - } + // readFile(file); + // getSize(file, argc, argv); + modifyUID(file); + - readFile(file); - - fclose(file); - free(binfile); - exit(EXIT_SUCCESS); + fclose(file); + free(binfile); + exit(EXIT_SUCCESS); } diff --git a/src/modifyUID.c b/src/modifyUID.c new file mode 100644 index 0000000..2138444 --- /dev/null +++ b/src/modifyUID.c @@ -0,0 +1,8 @@ +#include +#include "colors.h" + +void modifyUID(FILE *file) { + fseek(file, 0, SEEK_SET); + unsigned char newByte = 0x67; + fwrite(&newByte, sizeof(newByte), 1, file); +}