Commit ae25085d7ecf0ae117b141181989d78c3cd3e365
1 parent
d3b85bf5
Output function done
README fixed Makefile adapted
Showing
5 changed files
with
76 additions
and
19 deletions
Show diff stats
Makefile
1 | -CC= gcc | |
2 | -CC_FLAGS=-c -Wall -Werror -g | |
3 | -CC_LIBS=$(NFC_PROXMARK_LIB) | |
4 | -INCLUDES=-I../nfc_proxmark3_driver | |
1 | +CC=gcc | |
2 | +CC_FLAGS=-c -Wall -Werror | |
3 | +CC_LIBS= | |
4 | +INCLUDES= | |
5 | 5 | |
6 | -SOURCES=main.c | |
6 | +SOURCES=main.c printx.c | |
7 | 7 | OBJECTS=$(SOURCES:.c=.o) |
8 | -NFC_PROXMARK_LIB=-L../nfc_proxmark3_driver -lnfcproxmark3driver | |
9 | 8 | OUTPUT=tweekd |
10 | 9 | |
11 | 10 | all: $(SOURCES) $(OUTPUT) |
... | ... | @@ -14,7 +13,7 @@ $(OUTPUT): $(OBJECTS) |
14 | 13 | $(CC) $(OBJECTS) $(CC_LIBS) -o $@ |
15 | 14 | |
16 | 15 | %.o: %.c |
17 | - $(CC) -c $(INCLUDES) $(CC_FLAGS) $< -o $@ | |
16 | + $(CC) $(INCLUDES) $(CC_FLAGS) $< -o $@ | |
18 | 17 | |
19 | 18 | clear: |
20 | 19 | rm -f $(OUTPUT) $(OBJECTS) | ... | ... |
README.md
1 | 1 | #include <stdio.h> |
2 | -#include <version.h> | |
3 | -#include <transfer.h> | |
2 | +#include "printx.h" | |
4 | 3 | |
5 | 4 | int main(void) |
6 | 5 | { |
7 | - printf("Tweekd starting\n"); | |
8 | - if(initializeProxmark() != 0) | |
9 | - { | |
10 | - printf("Initialization failed\n"); | |
11 | - return 1; | |
12 | - } | |
13 | - printf("[NFC]\t: HW version\n"); | |
14 | - proxVersion(); | |
15 | - stopProxmark(); | |
6 | + initLog(); | |
7 | + printx(INFO, "Tweekd starting\n"); | |
8 | + closeLog(); | |
16 | 9 | return 0; |
17 | 10 | } | ... | ... |
... | ... | @@ -0,0 +1,50 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +#include <stdarg.h> | |
4 | +#include <stdbool.h> | |
5 | +#include <string.h> | |
6 | +#include <time.h> | |
7 | +#include "printx.h" | |
8 | + | |
9 | +#define FILENAME_LENGTH 24 | |
10 | +#define S_RESET "\33[0m" | |
11 | +#define MAX_BUFFER 128 | |
12 | + | |
13 | +FILE* logfile = NULL; | |
14 | +char s_color[4][12] = {"\x1b[01;31m", "\x1b[01;33m", "\x1b[01;32m", "\x1b[01;36m"}; | |
15 | + | |
16 | +bool initLog() | |
17 | +{ | |
18 | + char filename[FILENAME_LENGTH]; | |
19 | + time_t now = time(NULL); | |
20 | + | |
21 | + strftime(filename, FILENAME_LENGTH, "log/%F-%T:%d", localtime(&now)); | |
22 | + strcat(filename, ".log"); | |
23 | + | |
24 | + logfile = fopen(filename, "w"); | |
25 | + if(logfile == NULL) | |
26 | + { | |
27 | + printf("Unable to open the log file\n"); | |
28 | + return false; | |
29 | + } | |
30 | + | |
31 | + return true; | |
32 | +} | |
33 | + | |
34 | +void closeLog() | |
35 | +{ | |
36 | + fclose(logfile); | |
37 | +} | |
38 | + | |
39 | +void printx(severity s, char* str, ...) | |
40 | +{ | |
41 | + char buffer[MAX_BUFFER]; | |
42 | + va_list arglist; | |
43 | + va_start(arglist, str); | |
44 | + vsprintf(buffer, str, arglist); | |
45 | + fprintf(logfile, buffer); | |
46 | + printf(s_color[s]); | |
47 | + printf(buffer); | |
48 | + printf(S_RESET); | |
49 | + va_end(arglist); | |
50 | +} | ... | ... |