From 4920f676a731cec395ed901ba16a825512cbd6fc Mon Sep 17 00:00:00 2001 From: raspopov Date: Tue, 6 Aug 2024 22:03:39 +0300 Subject: [PATCH] Added initial CMake support (including ZIP packing, NSIS and DEB setup building). --- .gitignore | 3 +- CMakeLists.txt | 99 ++++++++++++++++++++++++++++++++ dist/windows/byedpi.bat | 2 +- dist/windows/proxy_reset.bat | 13 +++++ dist/windows/proxy_set.bat | 13 +++++ dist/windows/service_delete.bat | 13 +++-- dist/windows/service_install.bat | 17 +++--- dist/windows/service_restart.bat | 13 +++-- 8 files changed, 152 insertions(+), 21 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 dist/windows/proxy_reset.bat create mode 100644 dist/windows/proxy_set.bat diff --git a/.gitignore b/.gitignore index 3a3cff5..339db2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode -ciadpi.exe \ No newline at end of file +ciadpi.exe +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9718cdc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,99 @@ +cmake_minimum_required( VERSION 3.5 ) + +project( ByeDPI + VERSION 12 + DESCRIPTION "Local SOCKS proxy server to bypass DPI (Deep Packet Inspection)." + HOMEPAGE_URL "https://github.com/hufrea/byedpi" + LANGUAGES C +) + +set( PROJECT_VENDOR "GitHub" ) + +set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "$" ) + +add_compile_options( -O3 -flto -D_XOPEN_SOURCE=500 ) +add_link_options( -s ) + +include_directories( . ) + +set( SOURCES + packets.c + main.c + conev.c + proxy.c + desync.c + mpool.c + extend.c +) + +if( WIN32 ) + list( APPEND SOURCES + win_service.c + ) + link_libraries( + ws2_32 + mswsock + ) +endif() + +add_executable( ciadpi ${SOURCES} ) + +# Installer +set( CPACK_VERBATIM_VARIABLES ON ) +set( CPACK_STRIP_FILES ON ) +set( CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF ) +set( CPACK_PACKAGE_NAME ${PROJECT_NAME} ) +set( CPACK_PACKAGE_VENDOR ${PROJECT_VENDOR} ) +set( CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME} ) +set( CPACK_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION} ) +set( CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME} ) +set( CPACK_PACKAGE_CONTACT ${PROJECT_VENDOR} ) +include( GNUInstallDirs ) + +if( WIN32 ) + # NSIS package - https://sourceforge.net/projects/nsis/ + list( APPEND CPACK_GENERATOR NSIS ) + set( CPACK_NSIS_MENU_LINKS + "readme.txt" "Read Me" + "byedpi.bat" "Run standalone" + "proxy_reset.bat" "Proxy reset" + "proxy_set.bat" "Proxy setup" + "service_delete.bat" "Service delete" + "service_install.bat" "Service install and run" + "service_restart.bat" "Service restart" + ) + set( CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS "ExecWait \"sc stop ${PROJECT_NAME}\"" ) + set( CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait \"$INSTDIR\\service_install.bat\"" ) + set( CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "ExecWait \"$INSTDIR\\service_delete.bat\"" ) + set( CMAKE_INSTALL_BINDIR . ) + set( CMAKE_INSTALL_DOCDIR . ) +else() + # Debian package + list( APPEND CPACK_GENERATOR DEB ) +endif() + +# Zip package +list( APPEND CPACK_GENERATOR ZIP ) + +include( CPack ) + +install( TARGETS ciadpi + RUNTIME +) + +install( FILES + readme.txt + TYPE DOC +) + +if( WIN32 ) + install( FILES + dist/windows/byedpi.bat + dist/windows/proxy_reset.bat + dist/windows/proxy_set.bat + dist/windows/service_delete.bat + dist/windows/service_install.bat + dist/windows/service_restart.bat + TYPE BIN + ) +endif() diff --git a/dist/windows/byedpi.bat b/dist/windows/byedpi.bat index 8fb6023..7380bff 100644 --- a/dist/windows/byedpi.bat +++ b/dist/windows/byedpi.bat @@ -1,4 +1,4 @@ @echo off title ByeDPI -ciadpi.exe --split 1+s --disorder 3+s --mod-http=h,d --auto --tlsrec 1+s \ No newline at end of file +"%~dp0ciadpi.exe" --ip 127.0.0.1 --split 1+s --disorder 3+s --mod-http=h,d --auto --tlsrec 1+s \ No newline at end of file diff --git a/dist/windows/proxy_reset.bat b/dist/windows/proxy_reset.bat new file mode 100644 index 0000000..48f7715 --- /dev/null +++ b/dist/windows/proxy_reset.bat @@ -0,0 +1,13 @@ +@echo off + +rem Run as administrator +reg query "HKU\S-1-5-19\Environment" >nul 2>&1 +if not %errorlevel% equ 0 ( +powershell.exe -windowstyle hidden -noprofile "Start-Process '%~dpnx0' -Verb RunAs" +exit /b 0 +) + +reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyEnable" /f +reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyServer" /f +reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "MigrateProxy" /f +reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "AutoDetect" /f \ No newline at end of file diff --git a/dist/windows/proxy_set.bat b/dist/windows/proxy_set.bat new file mode 100644 index 0000000..302e8e4 --- /dev/null +++ b/dist/windows/proxy_set.bat @@ -0,0 +1,13 @@ +@echo off + +rem Run as administrator +reg query "HKU\S-1-5-19\Environment" >nul 2>&1 +if not %errorlevel% equ 0 ( +powershell.exe -windowstyle hidden -noprofile "Start-Process '%~dpnx0' -Verb RunAs" +exit /b 0 +) + +reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyEnable" /t REG_DWORD /d 1 /f +reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyServer" /t REG_SZ /d "socks=127.0.0.1:1080" /f +reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "MigrateProxy" /f +reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "AutoDetect" /f \ No newline at end of file diff --git a/dist/windows/service_delete.bat b/dist/windows/service_delete.bat index 3f12aeb..16ed737 100644 --- a/dist/windows/service_delete.bat +++ b/dist/windows/service_delete.bat @@ -1,13 +1,16 @@ @echo off title ByeDPI - Delete Service -echo This script should be run with administrator privileges. -echo Right click - run as administrator. -echo Press any key if you're running it as administrator. -pause +rem Run as administrator +reg query "HKU\S-1-5-19\Environment" >nul 2>&1 +if not %errorlevel% equ 0 ( +powershell.exe -windowstyle hidden -noprofile "Start-Process '%~dpnx0' -Verb RunAs" +exit /b 0 +) set svc_name="ByeDPI" sc stop %svc_name% sc delete %svc_name% -pause \ No newline at end of file + +call "%~dp0proxy_reset.bat" \ No newline at end of file diff --git a/dist/windows/service_install.bat b/dist/windows/service_install.bat index 03baf61..f81ec71 100644 --- a/dist/windows/service_install.bat +++ b/dist/windows/service_install.bat @@ -1,17 +1,17 @@ @echo off title ByeDPI - Install Service -pushd "%~dp0" -echo This script should be run with administrator privileges. -echo Right click - run as administrator. -echo Press any key if you're running it as administrator. -pause +rem Run as administrator +reg query "HKU\S-1-5-19\Environment" >nul 2>&1 +if not %errorlevel% equ 0 ( +powershell.exe -windowstyle hidden -noprofile "Start-Process '%~dpnx0' -Verb RunAs" +exit /b 0 +) set svc_name="ByeDPI" set svc_desc="Local SOCKS proxy server to bypass DPI (Deep Packet Inspection)." -:: Set up launch args (bypass methods) here. -set svc_bin="\"%cd%\ciadpi.exe\" --split 1+s --disorder 3+s --mod-http=h,d --auto --tlsrec 1+s" +set svc_bin="\"%~dp0ciadpi.exe\" --ip 127.0.0.1 --split 1+s --disorder 3+s --mod-http=h,d --auto --tlsrec 1+s" sc stop %svc_name% sc delete %svc_name% @@ -19,5 +19,4 @@ sc create %svc_name% binPath= %svc_bin% start= "auto" sc description %svc_name% %svc_desc% sc start %svc_name% -popd -pause \ No newline at end of file +call "%~dp0proxy_set.bat" \ No newline at end of file diff --git a/dist/windows/service_restart.bat b/dist/windows/service_restart.bat index 5e6aaaf..869c343 100644 --- a/dist/windows/service_restart.bat +++ b/dist/windows/service_restart.bat @@ -1,13 +1,16 @@ @echo off title ByeDPI - Restart Service -echo This script should be run with administrator privileges. -echo Right click - run as administrator. -echo Press any key if you're running it as administrator. -pause +rem Run as administrator +reg query "HKU\S-1-5-19\Environment" >nul 2>&1 +if not %errorlevel% equ 0 ( +powershell.exe -windowstyle hidden -noprofile "Start-Process '%~dpnx0' -Verb RunAs" +exit /b 0 +) set svc_name="ByeDPI" sc stop %svc_name% sc start %svc_name% -pause \ No newline at end of file + +call "%~dp0proxy_set.bat" \ No newline at end of file