Skip to content

Commit

Permalink
Added initial cmake build support
Browse files Browse the repository at this point in the history
Fixed according to the latest WinDivert
  • Loading branch information
KOLANICH committed May 22, 2018
1 parent 50e70ac commit 49a2a24
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/src/config.h
/src/goodbyedpi-rc.rc
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "WinDivert"]
path = WinDivert
url = https://github.com/basil00/Divert
branch = master
187 changes: 187 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.11)
PROJECT(GoodbyeDPI)

set(CMAKE_USE_RELATIVE_PATHS TRUE)

set(PACKAGE_NAME "GoodbyeDPI" CACHE STRING "Program name")
set(PACKAGE_VERSION ${VERSION})
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")

FIND_PACKAGE(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --long
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_FROM_GIT
RESULT_VARIABLE GIT_RESULT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_RESULT EQUAL 0)
message(WARNING "git returned error ${VERSION_FROM_GIT}")
set(VERSION_FROM_GIT "unknown")
endif()
else(GIT_FOUND)
set(VERSION_FROM_GIT "v0.1.5")
endif(GIT_FOUND)


string(REGEX MATCH "^v?[0-9]+(\\.[0-9]+)+" VERSION ${VERSION_FROM_GIT})
string(REGEX MATCHALL "[0-9]+" PARSED_VER ${VERSION})

list(LENGTH PARSED_VER PARSED_VER_LEN)
if(PARSED_VER_LEN GREATER 0)
list(GET PARSED_VER 0 VERSION_MAJOR)
else()
set(VERSION_MAJOR 0)
endif()
if(PARSED_VER_LEN GREATER 1)
list(GET PARSED_VER 1 VERSION_MINOR)
else()
set(VERSION_MINOR 0)
endif()
if(PARSED_VER_LEN GREATER 2)
list(GET PARSED_VER 2 VERSION_PATCH)
else()
set(VERSION_PATCH 0)
endif()
if(PARSED_VER_LEN GREATER 3)
list(GET PARSED_VER 3 VERSION_TWEAK)
else()
set(VERSION_TWEAK 0)
endif()

set(VERSION_BIN "${VERSION_MAJOR}${VERSION_MINOR}${VERSION_PATCH}")
message(STATUS "GoodbyeDPI version: ${VERSION}")
message(STATUS "GoodbyeDPI bin version: ${VERSION_BIN}")

if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%ct
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE COMPTIME
RESULT_VARIABLE GIT_RESULT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_RESULT EQUAL 0)
set(COMPTIME "0000000000")
endif()

execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%D
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_EXPORT
RESULT_VARIABLE GIT_RESULT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_RESULT EQUAL 0)
set(VERSION_EXPORT "HEAD -> master")
endif()
else(GIT_FOUND)
set(COMPTIME "0000000000")
set(VERSION_EXPORT "HEAD -> master")
endif(GIT_FOUND)
set(GoodbyeDPI_VERSION "${VERSION_EXPORT} ${VERSION_FROM_GIT}")
message(STATUS "version tag: ${GoodbyeDPI_VERSION}")

if(${CMAKE_SYSTEM_NAME} MATCHES "Darvin")
set(MACOS TRUE)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX TRUE)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(FREEBSD TRUE)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS TRUE)
endif()

set(Source_dir "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(Utils_dir "${CMAKE_CURRENT_SOURCE_DIR}/src/utils")
set(WinDivert_dir "${CMAKE_CURRENT_SOURCE_DIR}/WinDivert")
set(CMake_Misc_Dir "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

file(GLOB_RECURSE SRCFILES "${Source_dir}/*.c" "${Source_dir}/*.cpp")

include_directories(GoodbyeDPI "${WinDivert_dir}/include")
if(MSVC)
set(divertCompilerName "WDDK")
elseif(MINGW)
set(divertCompilerName "MINGW")
endif()
set(divertLibraryPath "${WinDivert_dir}/install/${divertCompilerName}/${CMAKE_SYSTEM_PROCESSOR}/")
message(STATUS ${divertLibraryPath})

#making resource file
set(rc_script "${Source_dir}/goodbyedpi-rc.rc")
set(rc_script_proto "${CMake_Misc_Dir}/goodbyedpi-rc.rc.in")
set(license_file "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
file(READ ${license_file} LICENSE_TEXT)
string(REPLACE "\"" "\"\"" LICENSE_TEXT ${LICENSE_TEXT})
string(REPLACE "\r\n" "\n" LICENSE_TEXT ${LICENSE_TEXT})
string(REPLACE "\n" "\\r\\n" LICENSE_TEXT ${LICENSE_TEXT})
message(STATUS "generating resources: ${rc_script_proto} -> ${rc_script}")
configure_file(${rc_script_proto} ${rc_script})
file(GLOB_RECURSE resource_files "${Source_dir}/*.rc" "${Source_dir}/*.ico")


if(MSVC_IDE)
file(GLOB_RECURSE HDRFILES "${Source_dir}/*.h")
endif()

# config.h
set(CONFIG_FILENAME "config.h")
set(CONFIG_FILE "${Source_dir}/${CONFIG_FILENAME}")
mark_as_advanced(CONFIG_FILE)
set(CONFIG_FILE_PROTO "${CMake_Misc_Dir}/${CONFIG_FILENAME}.in")

set(GoodbyeDPI_SERVICE_NAME "${PACKAGE_NAME}" CACHE STRING "Service name")

set(GoodbyeDPI_HOST_MAXLEN 253 CACHE INTEGER "Max length of a host")
set(GoodbyeDPI_MAX_FILTERS 4 CACHE INTEGER "Max length of a host")
set(GoodbyeDPI_MAX_PACKET_SIZE 9016 CACHE INTEGER "Max length of a host")
set(GoodbyeDPI_DEBUG ${GoodbyeDPI_DEBUG} CACHE BOOL "Enable debug output")

mark_as_advanced(GoodbyeDPI_SERVICE_NAME, GoodbyeDPI_HOST_MAXLEN)

message(STATUS "generating config: ${CONFIG_FILE_PROTO} -> ${CONFIG_FILE}")
configure_file(${CONFIG_FILE_PROTO} ${CONFIG_FILE})

add_executable(GoodbyeDPI "${SRCFILES}" "${HDRFILES}" "${resource_files}")
target_link_libraries(GoodbyeDPI "${divertLibraryPath}/WinDivert.dll")

if(MINGW)
target_link_libraries(GoodbyeDPI "wsock32" "ws2_32" "ssp")
set_target_properties(GoodbyeDPI PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Wconversion -pie -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -flto -mmitigate-rop -fstack-protector-strong -fno-common -fstack-check")
#-mcet
#-fsanitize=cfi
set_target_properties(GoodbyeDPI PROPERTIES LINK_FLAGS "-Wl,-O1,--sort-common,--as-needed,--dynamicbase,--nxcompat,--export-all-symbols,-flto")

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set_target_properties(GoodbyeDPI PROPERTIES LINK_FLAGS "-Wl,--image-base,0x140000000")
endif()
elseif(MSVC)
set_target_properties(GoodbyeDPI PROPERTIES COMPILE_FLAGS "/sdl /GS /SafeSEH /NXCOMPAT /dynamicbase /guard:cf /HIGHENTROPYVA")
set_target_properties(GoodbyeDPI PROPERTIES LINK_FLAGS "/guard:cf")
else()
message(FATAL_ERROR "The compiler is not supported")
endif()


set(RESOURCE_FILES
resourcefile.txt
appresourcedir/appres.txt
)


if(MSVC_IDE)
source_group("res" FILES ${resource_files})
endif()

if(MSVC)
set_source_files_properties(${SRCFILES} PROPERTIES LANGUAGE CXX)
else(MSVC)
#set_source_files_properties(${SRCFILES} PROPERTIES LANGUAGE CXX)
endif(MSVC)

#target_compile_features(GoodbyeDPI PUBLIC cxx_decltype_auto)
11 changes: 11 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
static const char SERVICE_NAME[] = "@GoodbyeDPI_SERVICE_NAME@";
static const char VERSION[] = "@GoodbyeDPI_VERSION@";

enum{
HOST_MAXLEN=@GoodbyeDPI_HOST_MAXLEN@u,
MAX_FILTERS=@GoodbyeDPI_MAX_FILTERS@u,
MAX_PACKET_SIZE=@GoodbyeDPI_MAX_PACKET_SIZE@u
};

#cmakedefine GoodbyeDPI_DEBUG
33 changes: 33 additions & 0 deletions cmake/goodbyedpi-rc.rc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "winver.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,@VERSION_TWEAK@
PRODUCTVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,@VERSION_TWEAK@
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040004b0"
BEGIN
VALUE "FileDescription", "GoodbyeDPI—Passive Deep Packet Inspection blocker and Active DPI circumvention utility (for Windows)."
VALUE "FileVersion", "@GoodbyeDPI_VERSION@"
VALUE "InternalName", "@PACKAGE_NAME@"
VALUE "LegalCopyright", "@LICENSE_TEXT@"
VALUE "ProductName", "@PACKAGE_NAME@"
VALUE "ProductVersion", "@GoodbyeDPI_VERSION@"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x400, 1200
END
END
1 24 "goodbyedpi.exe.manifest"
id ICON "icon.ico"
37 changes: 0 additions & 37 deletions src/Makefile

This file was deleted.

2 changes: 0 additions & 2 deletions src/goodbyedpi-rc.rc

This file was deleted.

13 changes: 2 additions & 11 deletions src/goodbyedpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ WINSOCK_API_LINKAGE INT WSAAPI inet_pton(INT Family, LPCSTR pStringBuf, PVOID pA

#define die() do { sleep(20); exit(EXIT_FAILURE); } while (0)

#define MAX_FILTERS 4
#define MAX_PACKET_SIZE 9016

#define DIVERT_NO_LOCALNETSv4_DST "(" \
"(ip.DstAddr < 127.0.0.1 or ip.DstAddr > 127.255.255.255) and " \
"(ip.DstAddr < 10.0.0.0 or ip.DstAddr > 10.255.255.255) and " \
Expand Down Expand Up @@ -764,7 +761,7 @@ int main(int argc, char *argv[]) {
);

WinDivertHelperCalcChecksums(
packet, packetLen - packet_dataLen + http_fragment_size, 0
packet, packetLen - packet_dataLen + http_fragment_size, &addr, 0
);
WinDivertSend(
w_filter, packet,
Expand Down Expand Up @@ -968,13 +965,7 @@ int main(int argc, char *argv[]) {

if (should_reinject) {
//printf("Re-injecting!\n");
if (should_recalc_checksum) {
WinDivertHelperCalcChecksums(packet, packetLen, 0);
}
else {
WinDivertHelperCalcChecksums(packet, packetLen,
WINDIVERT_HELPER_NO_REPLACE);
}
WinDivertHelperCalcChecksums(packet, packetLen, &addr, 0);
WinDivertSend(w_filter, packet, packetLen, &addr, NULL);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/goodbyedpi.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define HOST_MAXLEN 253
#include "config.h"

#ifndef DEBUG
#ifndef GoodbyeDPI_DEBUG
#define debug(...) do {} while (0)
#else
#define debug(...) printf(__VA_ARGS__)
Expand Down
3 changes: 1 addition & 2 deletions src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include <stdio.h>
#include "goodbyedpi.h"
#include "service.h"

#define SERVICE_NAME "GoodbyeDPI"
#include "config.h"

static SERVICE_STATUS ServiceStatus;
static SERVICE_STATUS_HANDLE hStatus;
Expand Down

0 comments on commit 49a2a24

Please sign in to comment.