Launch
This commit is contained in:
8
scripts/build_linux.sh
Normal file
8
scripts/build_linux.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
mkdir -p dist
|
||||
export CGO_ENABLED=1
|
||||
go mod tidy
|
||||
go build -trimpath -ldflags "-s -w" -o dist/socksrevivepc ./cmd/socksrevivepc
|
||||
echo "Built dist/socksrevivepc"
|
||||
echo "Run with sudo when using TUN mode."
|
||||
112
scripts/build_windows.ps1
Normal file
112
scripts/build_windows.ps1
Normal file
@@ -0,0 +1,112 @@
|
||||
param(
|
||||
[switch]$NoTidy,
|
||||
[switch]$Debug
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Info($Message) {
|
||||
Write-Host "[SocksRevivePC] $Message"
|
||||
}
|
||||
|
||||
function Add-PathIfExists($PathToAdd) {
|
||||
if ((Test-Path $PathToAdd) -and (($env:PATH -split ';') -notcontains $PathToAdd)) {
|
||||
$env:PATH = "$PathToAdd;$env:PATH"
|
||||
Write-Info "Added to PATH for this build: $PathToAdd"
|
||||
}
|
||||
}
|
||||
|
||||
function Require-Command($Name, $InstallHint) {
|
||||
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
|
||||
throw "$Name was not found in PATH. $InstallHint"
|
||||
}
|
||||
}
|
||||
|
||||
function Run-Native($Exe, $Arguments) {
|
||||
Write-Info "$Exe $($Arguments -join ' ')"
|
||||
& $Exe @Arguments
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "$Exe failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
}
|
||||
|
||||
# Fyne uses CGO on Windows. Try common MSYS2 MinGW locations before failing.
|
||||
Add-PathIfExists "C:\msys64\ucrt64\bin"
|
||||
Add-PathIfExists "C:\msys64\mingw64\bin"
|
||||
Add-PathIfExists "C:\msys64\clang64\bin"
|
||||
|
||||
Require-Command "go" "Install Go 1.22+ and reopen PowerShell."
|
||||
Require-Command "gcc" "Install MSYS2 and run: pacman -S --needed mingw-w64-ucrt-x86_64-gcc"
|
||||
Require-Command "windres" "Install MSYS2 windres/binutils: pacman -S --needed mingw-w64-ucrt-x86_64-binutils"
|
||||
|
||||
$gccVersion = (& gcc --version | Select-Object -First 1)
|
||||
$windresVersion = (& windres --version | Select-Object -First 1)
|
||||
Write-Info "Using compiler: $gccVersion"
|
||||
Write-Info "Using resource compiler: $windresVersion"
|
||||
|
||||
$env:CGO_ENABLED = "1"
|
||||
$env:GOOS = "windows"
|
||||
$env:GOARCH = "amd64"
|
||||
|
||||
New-Item -ItemType Directory -Force -Path "dist" | Out-Null
|
||||
|
||||
$internalWintun = "internal\wintunloader\assets\wintun\windows\amd64\wintun.dll"
|
||||
$toolWintun = "tools\wintun\amd64\wintun.dll"
|
||||
if (Test-Path $internalWintun) {
|
||||
Write-Info "Embedding internal Wintun DLL from $internalWintun"
|
||||
} elseif (Test-Path $toolWintun) {
|
||||
Write-Info "No embedded Wintun asset found; copying $toolWintun beside the EXE as runtime fallback"
|
||||
Copy-Item -Force $toolWintun "dist\wintun.dll"
|
||||
} else {
|
||||
Write-Info "No Wintun DLL found in project. TUN mode will ask for wintun.dll unless you embed it before building."
|
||||
}
|
||||
|
||||
|
||||
$manifest = "cmd\socksrevivepc\socksrevivepc.exe.manifest"
|
||||
$resource = "cmd\socksrevivepc\socksrevivepc_windows.rc"
|
||||
$syso = "cmd\socksrevivepc\admin_windows.syso"
|
||||
if (-not (Test-Path $manifest)) {
|
||||
throw "Missing Windows UAC manifest: $manifest"
|
||||
}
|
||||
if (-not (Test-Path $resource)) {
|
||||
throw "Missing Windows resource script: $resource"
|
||||
}
|
||||
Write-Info "Embedding UAC manifest: requireAdministrator"
|
||||
Run-Native "windres" @("-O", "coff", "-F", "pe-x86-64", "-i", $resource, "-o", $syso)
|
||||
if (-not (Test-Path $syso)) {
|
||||
throw "windres finished but $syso was not created."
|
||||
}
|
||||
|
||||
if (-not $NoTidy) {
|
||||
Run-Native "go" @("mod", "tidy")
|
||||
}
|
||||
|
||||
Run-Native "go" @("build", "-trimpath", "-ldflags", "-s -w -H=windowsgui", "-o", "dist/SocksRevivePC.exe", "./cmd/socksrevivepc")
|
||||
|
||||
if (-not (Test-Path "dist/SocksRevivePC.exe")) {
|
||||
throw "Build finished but dist/SocksRevivePC.exe was not created."
|
||||
}
|
||||
|
||||
Write-Info "Built dist/SocksRevivePC.exe"
|
||||
Write-Info "Normal build is GUI-only: no console window is attached."
|
||||
|
||||
if ($Debug) {
|
||||
Run-Native "go" @("build", "-trimpath", "-o", "dist/SocksRevivePC_debug.exe", "./cmd/socksrevivepc")
|
||||
if (-not (Test-Path "dist/SocksRevivePC_debug.exe")) {
|
||||
throw "Build finished but dist/SocksRevivePC_debug.exe was not created."
|
||||
}
|
||||
Write-Info "Built dist/SocksRevivePC_debug.exe for crash/debug logs. This debug EXE may show a console by design."
|
||||
} else {
|
||||
if (Test-Path "dist/SocksRevivePC_debug.exe") {
|
||||
Remove-Item -Force "dist/SocksRevivePC_debug.exe"
|
||||
}
|
||||
Write-Info "Skipped debug console EXE. Use -Debug only when troubleshooting."
|
||||
}
|
||||
Write-Info "Windows UAC: SocksRevivePC.exe is marked requireAdministrator and should show the admin prompt before starting."
|
||||
if (Test-Path $internalWintun) {
|
||||
Write-Info "Windows TUN: Wintun is embedded into the EXE and will be extracted automatically at runtime."
|
||||
} elseif (Test-Path "dist\wintun.dll") {
|
||||
Write-Info "Windows TUN: copied wintun.dll beside the EXE."
|
||||
} else {
|
||||
Write-Info "Windows TUN: run as Administrator and provide official wintun.dll, or embed it and rebuild."
|
||||
}
|
||||
24
scripts/diagnose_windows_tun.ps1
Normal file
24
scripts/diagnose_windows_tun.ps1
Normal file
@@ -0,0 +1,24 @@
|
||||
$ErrorActionPreference = 'Continue'
|
||||
Write-Host '[SocksRevivePC] Windows TUN diagnostics'
|
||||
Write-Host ''
|
||||
Write-Host '== Wintun / tunnel adapters =='
|
||||
Get-NetAdapter | Where-Object { $_.Name -like '*wintun*' -or $_.InterfaceDescription -like '*Wintun*' -or $_.InterfaceDescription -like '*WireGuard*' } | Format-List Name,InterfaceDescription,InterfaceIndex,Status,MacAddress,LinkSpeed
|
||||
Write-Host ''
|
||||
Write-Host '== Adapter IP addresses =='
|
||||
Get-NetIPAddress | Where-Object { $_.InterfaceAlias -like '*wintun*' -or $_.InterfaceAlias -like '*WireGuard*' } | Format-Table InterfaceAlias,InterfaceIndex,AddressFamily,IPAddress,PrefixLength -AutoSize
|
||||
Write-Host ''
|
||||
Write-Host '== Split default routes =='
|
||||
Get-NetRoute -DestinationPrefix '0.0.0.0/1','128.0.0.0/1','::/1','8000::/1' -ErrorAction SilentlyContinue | Sort-Object AddressFamily,DestinationPrefix,RouteMetric | Format-Table DestinationPrefix,InterfaceAlias,InterfaceIndex,NextHop,RouteMetric,AddressFamily -AutoSize
|
||||
Write-Host ''
|
||||
Write-Host '== Normal default routes =='
|
||||
Get-NetRoute -DestinationPrefix '0.0.0.0/0','::/0' -ErrorAction SilentlyContinue | Sort-Object AddressFamily,RouteMetric,InterfaceMetric | Format-Table DestinationPrefix,InterfaceAlias,InterfaceIndex,NextHop,RouteMetric,InterfaceMetric,AddressFamily -AutoSize
|
||||
Write-Host ''
|
||||
Write-Host '== DNS servers =='
|
||||
Get-DnsClientServerAddress | Where-Object { $_.InterfaceAlias -like '*wintun*' -or $_.InterfaceAlias -like '*WireGuard*' -or $_.AddressFamily -eq 2 } | Format-Table InterfaceAlias,AddressFamily,ServerAddresses -AutoSize
|
||||
Write-Host ''
|
||||
Write-Host 'If 0.0.0.0/1 and 128.0.0.0/1 do not point to the Wintun adapter, the app is not running as Administrator or Windows rejected the route.'
|
||||
Write-Host ''
|
||||
Write-Host '== Quick IPv6 test =='
|
||||
try { Test-NetConnection -ComputerName '2606:4700:4700::1111' -Port 443 -InformationLevel Detailed } catch { Write-Host $_ }
|
||||
Write-Host ''
|
||||
Write-Host 'IPv6 note: if IPv6 support is OFF but leak protection is ON, ::/1 and 8000::/1 should point to Wintun and public IPv6 tests should fail instead of showing your ISP IPv6.'
|
||||
31
scripts/embed_wintun_from_tools.ps1
Normal file
31
scripts/embed_wintun_from_tools.ps1
Normal file
@@ -0,0 +1,31 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$source = "tools\wintun\amd64\wintun.dll"
|
||||
$targetDir = "internal\wintunloader\assets\wintun\windows\amd64"
|
||||
$target = Join-Path $targetDir "wintun.dll"
|
||||
|
||||
function Test-PEAmd64($Path) {
|
||||
$bytes = [System.IO.File]::ReadAllBytes($Path)
|
||||
if ($bytes.Length -lt 1024) { throw "Invalid wintun.dll: file is too small." }
|
||||
if ($bytes[0] -ne 0x4d -or $bytes[1] -ne 0x5a) { throw "Invalid wintun.dll: missing MZ header." }
|
||||
$peOffset = [BitConverter]::ToInt32($bytes, 0x3c)
|
||||
if ($peOffset -le 0 -or $bytes.Length -lt ($peOffset + 6)) { throw "Invalid wintun.dll: bad PE header." }
|
||||
if ($bytes[$peOffset] -ne 0x50 -or $bytes[$peOffset+1] -ne 0x45 -or $bytes[$peOffset+2] -ne 0x00 -or $bytes[$peOffset+3] -ne 0x00) {
|
||||
throw "Invalid wintun.dll: missing PE signature."
|
||||
}
|
||||
$machine = [BitConverter]::ToUInt16($bytes, $peOffset + 4)
|
||||
if ($machine -ne 0x8664) {
|
||||
$hex = "0x{0:x4}" -f $machine
|
||||
throw "Wrong wintun.dll architecture: got $hex, expected amd64/x64 machine 0x8664. Use wintun\bin\amd64\wintun.dll from the official Wintun ZIP."
|
||||
}
|
||||
}
|
||||
|
||||
if (-not (Test-Path $source)) {
|
||||
throw "Missing $source. Put the official signed amd64 wintun.dll there first."
|
||||
}
|
||||
|
||||
Test-PEAmd64 $source
|
||||
New-Item -ItemType Directory -Force -Path $targetDir | Out-Null
|
||||
Copy-Item -Force $source $target
|
||||
Write-Host "Embedded Wintun asset prepared: $target"
|
||||
Write-Host "Now rebuild with: powershell -ExecutionPolicy Bypass -File .\scripts\build_windows.ps1"
|
||||
41
scripts/install_windows_compiler_msys2.ps1
Normal file
41
scripts/install_windows_compiler_msys2.ps1
Normal file
@@ -0,0 +1,41 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Info($Message) {
|
||||
Write-Host "[SocksRevivePC] $Message"
|
||||
}
|
||||
|
||||
$msysRoot = "C:\msys64"
|
||||
$bash = Join-Path $msysRoot "usr\bin\bash.exe"
|
||||
|
||||
if (-not (Test-Path $bash)) {
|
||||
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
|
||||
throw "winget was not found. Install MSYS2 manually from https://www.msys2.org, then run this script again."
|
||||
}
|
||||
|
||||
Write-Info "Installing MSYS2 with winget..."
|
||||
winget install --id MSYS2.MSYS2 -e --accept-source-agreements --accept-package-agreements
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "winget failed to install MSYS2. Install MSYS2 manually from https://www.msys2.org."
|
||||
}
|
||||
}
|
||||
|
||||
if (-not (Test-Path $bash)) {
|
||||
throw "MSYS2 was not found at $msysRoot after installation. Install MSYS2 manually or adjust this script path."
|
||||
}
|
||||
|
||||
Write-Info "Installing UCRT64 GCC and resource compiler toolchain..."
|
||||
& $bash -lc "pacman -Sy --needed --noconfirm mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-binutils"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "pacman failed to install mingw-w64-ucrt-x86_64-gcc/binutils. Open 'MSYS2 UCRT64' and run: pacman -S --needed mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-binutils"
|
||||
}
|
||||
|
||||
$ucrtPath = "C:\msys64\ucrt64\bin"
|
||||
$currentUserPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||
if (($currentUserPath -split ';') -notcontains $ucrtPath) {
|
||||
[Environment]::SetEnvironmentVariable("Path", "$ucrtPath;$currentUserPath", "User")
|
||||
Write-Info "Added $ucrtPath to your user PATH. Open a new PowerShell window before building."
|
||||
} else {
|
||||
Write-Info "$ucrtPath is already in your user PATH."
|
||||
}
|
||||
|
||||
Write-Info "Done. Open a new PowerShell window and run: powershell -ExecutionPolicy Bypass -File .\scripts\build_windows.ps1"
|
||||
29
scripts/run_debug_windows.ps1
Normal file
29
scripts/run_debug_windows.ps1
Normal file
@@ -0,0 +1,29 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Test-IsAdmin {
|
||||
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
|
||||
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
}
|
||||
|
||||
$root = (Get-Location).Path
|
||||
$scriptPath = $MyInvocation.MyCommand.Path
|
||||
|
||||
if (-not (Test-IsAdmin)) {
|
||||
Write-Host "SocksRevivePC debug runner needs Administrator permission for TUN/routes. Showing UAC prompt..."
|
||||
$args = "-NoExit -ExecutionPolicy Bypass -File `"$scriptPath`""
|
||||
Start-Process -FilePath "powershell.exe" -ArgumentList $args -WorkingDirectory $root -Verb RunAs -Wait
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
$exe = Join-Path $root "dist\SocksRevivePC_debug.exe"
|
||||
if (-not (Test-Path $exe)) {
|
||||
throw "dist\SocksRevivePC_debug.exe not found. Build it only when troubleshooting with: powershell -ExecutionPolicy Bypass -File .\scripts\build_windows.ps1 -Debug"
|
||||
}
|
||||
Write-Host "Starting debug build as Administrator. If the GUI closes, check logs\crash.log and logs\runtime.log."
|
||||
& $exe
|
||||
Write-Host "Process exited with code $LASTEXITCODE"
|
||||
if (Test-Path "logs\crash.log") {
|
||||
Write-Host "Last crash log lines:"
|
||||
Get-Content "logs\crash.log" -Tail 80
|
||||
}
|
||||
Reference in New Issue
Block a user