-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathMakefile
76 lines (67 loc) · 2.21 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
# build example, tested in linux 10.0.0-3, gcc 12, wine-9.0
# make winmemdll_shellcode CC=x86_64-w64-mingw32-clang
# make winmemdll winmemdll_test CC=i686-w64-mingw32-gcc BUILD_TYPE=32d
# make winmemdll winmemdll_test CC=x86_64-w64-mingw32-gcc BUILD_TYPE=64d
# general config
CC:=gcc # clang (llvm-mingw), gcc (mingw-w64), tcc (x86 stdcall name has problem)
BUILD_TYPE:=32# 32, 32d, 64, 64d
BUILD_DIR:=build
INCS:=-Idepend/winreverse/src
LIBS:=-luser32 -lgdi32 -lpsapi
CFLAGS:=-fPIC -std=c99 \
-fvisibility=hidden \
-ffunction-sections -fdata-sections
LDFLAGS:=-Wl,--enable-stdcall-fixup \
-Wl,--kill-at \
-Wl,--gc-sections \
-D_WIN32_WINNT=0X0400 \
-Wl,--subsystem,console:4.0 # compatible for xp
# build config
ifneq (,$(findstring 64, $(BUILD_TYPE)))
CFLAGS+=-m64
else
CFLAGS+=-m32
endif
ifneq (,$(findstring d, $(BUILD_TYPE)))
CFLAGS+=-g -D_DEBUG
else
CFLAGS+=-Os
endif
ifneq (,$(findstring tcc, $(CC)))
LDFLAGS= # tcc can not remove at at stdcall in i686
else
endif
all: prepare winmemdll
clean:
@rm -rf $(BUILD_DIR)/*winmemdll*
prepare:
@if ! [ -d $(BUILD_DIR) ]; then mkdir -p $(BUILD_DIR); fi
winmemdll: src/winmemdll.c
@echo "## $@"
$(CC) $< -o $(BUILD_DIR)/$@$(BUILD_TYPE).exe \
$(INCS) $(LIBS) \
$(CFLAGS) $(LDFLAGS)
winmemdll_test: src/winmemdll_test.c
@echo "## $@"
$(CC) $< -o $(BUILD_DIR)/$@$(BUILD_TYPE).exe \
$(INCS) $(LIBS) \
$(CFLAGS) $(LDFLAGS)
# only support llvm-mingw (tested 18.1), for building coff format
# sometimes nested force inline function might cause problems
winmemdll_shellcode: depend/winreverse/project/windll_winpe/src/libwinpe.c
@echo "## $@"
# use -mno-sse for not making string as constant, sse makes array assign with ds:
$(CC) -c -O3 -m32 -mno-sse $< -o $(BUILD_DIR)/[email protected] \
-fPIC -ffunction-sections -fdata-sections \
-Wno-undefined-inline \
$(INCS)
# mingw-w64 in linux, failed for findloadlibrarya, as make rax to fill string at wrong position
$(CC) -c -O3 -m64 -mno-sse $< -o $(BUILD_DIR)/[email protected] \
-fPIC -ffunction-sections -fdata-sections \
-Wno-undefined-inline \
$(INCS)
python src/winmemdll_shellcode.py \
$(BUILD_DIR)/[email protected] \
$(BUILD_DIR)/[email protected] \
src/winmemdll_shellcode.h
.PHONY: all clean prepare winmemdll winmemdll_test winmemdll_shellcode