Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jclehner/nmrpflash
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.16
Choose a base ref
...
head repository: jclehner/nmrpflash
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 1,027 additions and 274 deletions.
  1. +1 −0 .gitattributes
  2. +3 −0 .gitignore
  3. +57 −0 CMakeLists.txt
  4. +32 −0 Dockerfile
  5. +76 −15 Makefile
  6. +81 −59 README.md
  7. +315 −66 ethsock.c
  8. +50 −24 main.c
  9. +141 −60 nmrp.c
  10. +46 −25 nmrpd.h
  11. +1 −1 nmrpflash.cbp
  12. BIN nmrpflash.ico
  13. +6 −1 nmrpflash.manifest
  14. +2 −1 nmrpflash.rc
  15. +175 −0 nmrpflash.svg
  16. +32 −8 tftp.c
  17. +9 −14 util.c
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -2,3 +2,4 @@
nmrpflash.cbp text eol=crlf
nmrpflash.manifest text eol=crlf
nmrpflash.rc text eol=crlf
nmrpflash.ico -text
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -3,10 +3,13 @@
*.img
*.pcap
*.dni
*.AppImage
Makefile.win
nmrpflash.depend
nmrpflash.exe
nmrpflash.layout
nmrpflash*.zip
nmrpflash
Npcap/
Obj/
build/
57 changes: 57 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Still WIP! Use the regular Makefile for now!

cmake_minimum_required(VERSION 3.6)
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)

project(nmrpflash)

if (NOT DEFINED NMRPFLASH_VERSION)
find_package(Git)

if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(SUBSTRING ${GIT_VERSION} 1 -1 GIT_VERSION)
string(REGEX REPLACE "-g.*$" "" GIT_VERSION_CMAKE ${GIT_VERSION})
string(REPLACE "-" "." GIT_VERSION_CMAKE ${GIT_VERSION_CMAKE})
project(${CMAKE_PROJECT_NAME} VERSION ${GIT_VERSION_CMAKE})
set(NMRPFLASH_VERSION ${GIT_VERSION})

else()
message(FATAL_ERROR "Git not found, and no NMRPFLASH_VERSION defined")
endif()
else()
project(${CMAKE_PROJECT_NAME} VERSION ${NMRPFLASH_VERSION})
endif()

set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR})
add_executable(nmrpflash main.c nmrp.c tftp.c util.c ethsock.c)
target_compile_definitions(nmrpflash PUBLIC -DNMRPFLASH_VERSION=\"${NMRPFLASH_VERSION}\")
target_compile_options(nmrpflash PUBLIC -Wall)

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_libraries(nmrpflash -lpcap "-framework CoreFoundation")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(nmrpflash PRIVATE nmrpflash.rc)
target_compile_definitions(nmrpflash PUBLIC -D_WIN32_WINNT=0x0600 -DWIN32_LEAN_AND_MEAN -D__USE_MINGW_ANSI_STDIO)
target_link_libraries(nmrpflash -lwpcap -lPacket -liphlpapi -lws2_32 -ladvapi32)
target_include_directories(nmrpflash PUBLIC ./Npcap/Include)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
target_link_directories(nmrpflash PUBLIC ./Npcap/Lib/x64)
else()
target_link_directories(nmrpflash PUBLIC ./Npcap/Lib)
endif()
else()
find_package(PkgConfig)
pkg_check_modules(PCAP REQUIRED IMPORTED_TARGET libpcap)
target_link_libraries(nmrpflash PkgConfig::PCAP)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
pkg_check_modules(NLROUTE REQUIRED IMPORTED_TARGET libnl-route-3.0)
target_link_libraries(nmrpflash PkgConfig::NLROUTE)
endif()
endif()
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ubuntu:jammy

ENV TZ=Etc/UTC
ENV TERM=xterm
ENV APPIMAGE_EXTRACT_AND_RUN=1
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y build-essential pkg-config git zip wget file
RUN apt-get install -y g++-mingw-w64-i686
RUN apt-get install -y imagemagick
RUN apt-get install -y libpcap-dev libnl-3-dev libnl-route-3-dev

RUN mkdir -p /usr/src
WORKDIR /usr/src

ADD "https://api.github.com/repos/jclehner/nmrpflash/commits?per_page=1" latest_commit
RUN git clone https://github.com/jclehner/nmrpflash

WORKDIR /usr/src/nmrpflash

ARG NPCAP_SDK

RUN wget -q -O npcap-sdk.zip https://npcap.com/dist/npcap-sdk-${NPCAP_SDK}.zip
RUN unzip npcap-sdk.zip -d Npcap

ARG CACHEBUST=1

RUN make clean
RUN make release/linux-appimage
RUN make MINGW=i686-w64-mingw32- release release/win32

91 changes: 76 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
CC ?= gcc
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)\"
LDFLAGS += -lpcap
SUFFIX ?=
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

ifeq ($(shell uname -s),Linux)
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)
endif

LDFLAGS += $(shell $(PKG_CONFIG) libpcap --libs)
AFL = afl-gcc
else
LDFLAGS += -lpcap
ifeq ($(shell uname -s),Darwin)
AFL=afl-clang
else
AFL=afl-gcc
SYSROOT ?= $(shell xcrun --sdk $(MACOS_SDK) --show-sdk-path)
LDFLAGS += -framework CoreFoundation
endif
endif

nmrpflash_OBJ = nmrp.o tftp.o ethsock.o main.o util.o

.PHONY: clean install release release/macos release/linux release/win32

@@ -30,6 +59,9 @@ tftptest:
%.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 $@

@@ -43,23 +75,52 @@ dofuzz_tftp: fuzz_tftp
echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

clean:
rm -f $(nmrpflash_OBJ) nmrpflash fuzz_nmrp fuzz_tftp
rm -f $(nmrpflash_OBJ) nmrpflash*.AppImage nmrpflash nmrpflash.exe fuzz_nmrp fuzz_tftp

install: nmrpflash
install -m 755 nmrpflash $(PREFIX)/bin
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="-target arm64-apple-macos11" SUFFIX=".arm64" make release
CFLAGS="-target x86_64-apple-macos10.8" SUFFIX=".x86_64" make release
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)
$(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)
Loading