-
Notifications
You must be signed in to change notification settings - Fork 120
/
Makefile
126 lines (104 loc) · 4.09 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
CC = $(CROSS)gcc
STRIP = $(CROSS)strip
PKG_CONFIG ?= pkg-config
PREFIX ?= /usr/local
VERSION := $(shell if [ -d .git ] && which git 2>&1 > /dev/null; then git describe --always | tail -c +2; else echo $$STANDALONE_VERSION; fi)
CFLAGS += -Wall -g -DNMRPFLASH_VERSION=\"$(VERSION)\"
SUFFIX ?=
MACOS_SDK ?= macosx15.0
NPCAP_SDK = 1.13
ARCH := $(shell uname -m)
LINUXDEPLOY = ./linuxdeploy-$(ARCH).AppImage
TMP := $(shell mktemp -d)
APPDIR = $(TMP)/AppDir
AFL = afl-gcc
DOCKER_BUILD_NAME=nmrpflash
DOCKER_CONTAINER_NAME=$(DOCKER_BUILD_NAME)-container
nmrpflash_OBJ = nmrp.o tftp.o ethsock.o main.o util.o
ifdef MINGW
SUFFIX = .exe
CC = $(MINGW)gcc
STRIP = $(MINGW)strip
WINDRES = $(MINGW)windres
CFLAGS += -DWIN32_LEAN_AND_MEAN
CFLAGS += -D_WIN32_WINNT=0x0600
CFLAGS += -D__USE_MINGW_ANSI_STDIO
CFLAGS += "-I./Npcap/Include"
LDFLAGS += -lwpcap
LDFLAGS += -lPacket
LDFLAGS += -liphlpapi
LDFLAGS += -lws2_32
LDFLAGS += -ladvapi32
LDFLAGS += "-L./Npcap/Lib"
nmrpflash_OBJ += windres.o
else ifeq ($(shell uname -s),Linux)
CFLAGS += $(shell $(PKG_CONFIG) libnl-route-3.0 --cflags)
CFLAGS += $(shell $(PKG_CONFIG) libpcap --cflags)
LDFLAGS += $(shell $(PKG_CONFIG) libnl-route-3.0 --libs)
LDFLAGS += $(shell $(PKG_CONFIG) libpcap --libs)
AFL = afl-gcc
else
LDFLAGS += -lpcap
ifeq ($(shell uname -s),Darwin)
AFL=afl-clang
SYSROOT ?= $(shell xcrun --sdk $(MACOS_SDK) --show-sdk-path)
LDFLAGS += -framework CoreFoundation
endif
endif
.PHONY: clean install release release/macos release/linux release/win32
nmrpflash$(SUFFIX): $(nmrpflash_OBJ)
$(CC) $(CFLAGS) -o nmrpflash$(SUFFIX) $(nmrpflash_OBJ) $(LDFLAGS)
tftptest:
CFLAGS=-DNMRPFLASH_TFTP_TEST make clean nmrpflash
%.o: %.c nmrpd.h
$(CC) -c $(CFLAGS) $< -o $@
windres.o: nmrpflash.rc nmrpflash.manifest nmrpflash.ico
$(WINDRES) $< -o $@
fuzz_nmrp: tftp.c util.c nmrp.c fuzz.c
$(AFL) $(CFLAGS) -DNMRPFLASH_FUZZ $^ -o $@
fuzz_tftp: tftp.c util.c nmrp.c fuzz.c
$(AFL) $(CFLAGS) -DNMRPFLASH_FUZZ -DNMRPFLASH_FUZZ_TFTP $^ -o $@
dofuzz_tftp: fuzz_tftp
echo core | sudo tee /proc/sys/kernel/core_pattern
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
afl-fuzz -i fuzzin/tftp -o fuzzout/tftp -- ./fuzz_tftp fuzzin/tftp.bin
echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
clean:
rm -f $(nmrpflash_OBJ) nmrpflash*.AppImage nmrpflash nmrpflash.exe fuzz_nmrp fuzz_tftp
install: nmrpflash
install -d $(PREFIX)/bin
install -s -m 755 nmrpflash $(PREFIX)/bin/
uninstall:
rm -f $(PREFIX)/bin/nmrpflash
$(LINUXDEPLOY):
wget -q -O $@ https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/$(shell basename $@)
chmod +x $@
nmrpflash-$(ARCH).AppImage: $(LINUXDEPLOY) release
rm -rf $(APPDIR)
mkdir -p $(APPDIR)
$(LINUXDEPLOY) --appdir $(APPDIR) -e nmrpflash -i nmrpflash.svg -o appimage --create-desktop-file
release/macos:
CFLAGS="-isysroot $(SYSROOT) -target arm64-apple-macos11" SUFFIX=".arm64" make release
CFLAGS="-isysroot $(SYSROOT) -target x86_64-apple-macos10.8" SUFFIX=".x86_64" make release
lipo -create -output nmrpflash nmrpflash.x86_64 nmrpflash.arm64
zip nmrpflash-$(VERSION)-macos.zip nmrpflash
rm -f nmrpflash.x86_64 nmrpflash.arm64
release/linux: release
zip nmrpflash-$(VERSION)-linux.zip nmrpflash
release/linux-appimage: nmrpflash-$(ARCH).AppImage
mv $< $(TMP)/nmrpflash
cd $(TMP); zip release.zip nmrpflash
mv $(TMP)/release.zip nmrpflash-$(VERSION)-linux-$(ARCH).zip
release/win32:
zip nmrpflash-$(VERSION)-win32.zip nmrpflash.exe
release: clean nmrpflash$(SUFFIX)
$(STRIP) nmrpflash$(SUFFIX)
nmrpflash.ico: nmrpflash.svg
convert -background transparent -define icon:auto-resize=256,64,48,32,16 $< $@
build-release-with-docker:
docker build --build-arg CACHEBUST=$(shell date +%s) --build-arg NPCAP_SDK=$(NPCAP_SDK) --progress=plain -t $(DOCKER_BUILD_NAME) .
-docker rm $(DOCKER_CONTAINER_NAME) &> /dev/null
docker create --name $(DOCKER_CONTAINER_NAME) nmrpflash
docker cp $(DOCKER_CONTAINER_NAME):/usr/src/nmrpflash/nmrpflash-$(VERSION)-linux-$(ARCH).zip .
docker cp $(DOCKER_CONTAINER_NAME):/usr/src/nmrpflash/nmrpflash-$(VERSION)-win32.zip .
docker rm $(DOCKER_CONTAINER_NAME)