diff --git a/Makefile b/Makefile index 7ae08f5..69b960b 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,19 @@ -INCLUDES = include -SOURCES = src -OUTPUT = main -CFLAGS=-g -o main -Wall -I$(INCLUDES) +CC=gcc +CFLAGS=-g -Wall +SRC=src +OBJ=obj +SRCS=$(wildcard $(SRC)/*.c) +OBJS=$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS)) -CFILES := $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.c)) +BIN=./main -all: - gcc main.c $(CFILES) $(CFLAGS) +all:$(BIN) + +$(BIN): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $@ + +$(OBJ)/%.o: $(SRC)/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + $(RM) -r $(OBJ)/* diff --git a/blank16sectorcard b/blank16sectorcard new file mode 100644 index 0000000..1ac1d2a Binary files /dev/null and b/blank16sectorcard differ diff --git a/main.c b/main.c deleted file mode 100644 index 5c45997..0000000 --- a/main.c +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include -#include -#include - -#include "readFile.h" -#include "getSize.h" - -int main(int argc, char *argv[]) { - short c; -/* 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); - } - */ - - FILE *file; - 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); - } - - static const struct option long_opts[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'V' }, - { NULL, 0, NULL, 0 } - }; - - while ((c = getopt_long(argc, argv, "hVs", - long_opts, NULL)) != -1) { - switch (c) { - case 'h': - case 'V': - case 's': - getSize(file, argc, argv); - exit(EXIT_SUCCESS); - default: - printf("Try '%s --help' for more information.\n", argv[0]); - exit(EXIT_FAILURE); - } - } - - readFile(file); - - fclose(file); - free(binfile); - exit(EXIT_SUCCESS); -} diff --git a/makefile b/makefile new file mode 100644 index 0000000..89899d8 --- /dev/null +++ b/makefile @@ -0,0 +1,19 @@ +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/main.c b/src/main.c new file mode 100644 index 0000000..676be69 --- /dev/null +++ b/src/main.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include + +#include "getSize.h" +#include "readFile.h" + +int main(int argc, char *argv[]) { + + if (argv[argc] == 1) { + + + FILE *file; + 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); + } + + readFile(file); + + fclose(file); + free(binfile); + exit(EXIT_SUCCESS); +}