-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
135 lines (110 loc) · 3.6 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
NAME := woody_woodpacker
SRCS = main.c \
stored_file.c \
validate.c \
parse.c \
free.c \
convert_headers.c \
exploit.c \
exploit_note.c \
extract_info.c \
unpacker.c
SRCS_ASM = keygen_64.asm \
encrypt_64.asm \
decrypt_64.asm \
decrypt_32.asm
OBJS = $(addprefix ${OBJDIR}/,${SRCS:.c=.o})
OBJS_ASM = $(addprefix ${OBJDIR}/,${SRCS_ASM:.asm=.o})
DEPENDS = $(addprefix ${DEPSDIR}/,${SRCS:.c=.d})
CC = clang
#ASMC = /mnt/nfs/homes/xchalle/nasm-2.16.01/nasm
ASMC = nasm
FLAGS = -g3 #-fsanitize=address -Wall -Wextra -Werror -Wimplicit-function-declaration -Wtrigraphs -m64
INCS = -I ./src -I ./asm
OBJDIR = .objs
DEPSDIR = .deps
SRCDIR = ./src
ASMDIR = ./asm
ifeq ($(DEBUG),on)
FLAGS += -D COMPILATION_DEBUG
endif
KEY_LENGTH = 128
ifeq ($(KEY_LENGTH),$(filter $(KEY_LENGTH),128 192 256 ))
FLAGS += -D KEY_LENGTH=${KEY_LENGTH}
endif
_GREY= $'\033[30m
_RED= $'\033[31m
_GREEN= $'\033[32m
_YELLOW=$'\033[33m
_BLUE= $'\033[34m
_PURPLE=$'\033[35m
_CYAN= $'\033[36m
_WHITE= $'\033[37m
_END= $'\033[37m
all: ${NAME}
-include ${DEPENDS}
$(OBJDIR)/%.o: ${SRCDIR}/%.c
@mkdir -p ${OBJDIR}
@printf "%-15s ${_YELLOW}${_BOLD}$<${_END}...\n" "Compiling"
@${CC} ${FLAGS} -MMD -MP ${INCS} -c $< -o $@
@mv ${OBJDIR}/$*.d ${DEPSDIR}/$*.d
$(OBJDIR)/%.o: ${ASMDIR}/%.asm
@mkdir -p ${OBJDIR}
@printf "%-15s ${_CYAN}${_BOLD}$<${_END}...\n" "Compiling"
@#@if echo $< | grep -q "64"; then \
${ASMC} -f elf64 $< -o $@; \
# @#else \
# @# ${ASMC} -f elf32 $< -o $@; \
# @#fi
${NAME}: init ${OBJS} ${OBJS_ASM}
@printf "%-15s ${_PURPLE}${_BOLD}${NAME}${_END}...\n" "Compiling"
@${CC} ${FLAGS} ${INCS} -o ${NAME} ${OBJS} ${OBJS_ASM} -no-pie
ifeq ($(MAKE_WOODY_WRITABLE), on)
@gcc .dev/make_elf_fully_writable.c -o .dev/make_elf_fully_writable 2>/dev/null
@./.dev/make_elf_fully_writable ${NAME}
endif
@printf "\n${_GREEN}${_BOLD}Compilation done !${_END}\n"
xchalle: init ${OBJS}
@${CC} ${FLAGS} ${INCS} -o ${NAME} ${OBJS} -no-pie
@printf "\n${_GREEN}${_BOLD}Compilation done !${_END}\n"
clean:
@printf "%-15s ${_RED}${_BOLD}${NAME}'s object files${_END}...\n" "Deleting"
@rm -f ${OBJS} ${OBJS_BONUS}
@printf "%-15s ${_RED}${_BOLD}${NAME}'s object directory${_END}...\n" "Deleting"
@rm -rf ${OBJDIR}
@printf "%-15s ${_RED}${_BOLD}${NAME}'s dependency files${_END}...\n" "Deleting"
@rm -rf ${DEPSDIR}
fclean: clean
@printf "%-15s ${_RED}${_BOLD}${NAME}${_END}...\n" "Deleting"
@rm -f ${NAME}
init:
@printf "%-15s ${_GREEN}${_BOLD}${NAME}${_END}...\n" "Initiating"
@mkdir -p ${OBJDIR}
@mkdir -p ${DEPSDIR}
show:
@echo "Project configfuration:"
@echo " name: ${NAME}"
@echo " sources: ${SRCS}"
@echo " objects: ${OBJS}"
@echo " includes: ${INCS}"
@echo " compiler: ${CC}"
@echo " flags: ${FLAGS}"
run: all
@printf "${_GREEN}${_BOLD}Running ${NAME}...${_END}\n"
@./${NAME} || true
rerun: re
@printf "${_GREEN}${_BOLD}Running ${NAME}...${_END}\n"
@./${NAME} || true
re: fclean all
help:
@echo "Available make rules:"
@echo " all: Build the executable ${NAME}."
@echo " clean: Remove object files and object directory."
@echo " fclean: Remove object files, object directory, and the executable ${NAME}."
@echo " init: Initialize directories for object files and dependencies."
@echo " show: Display information about the project configuration."
@echo " run: Build and run the executable ${NAME}."
@echo " rerun: Clean and rebuild, then run the executable ${NAME}."
@echo " re: Rebuild the executable ${NAME}"
@echo " help: Display this help message."
.PHONY: all fclean clean init show re run rerun help