Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
remove CLI publishing, updated logging
AnoF-Cyber05bfd253b34a
diff --git a/Windows/compile.ps1 b/Windows/compile.ps1index 6bab012..5a0fb00 100644--- a/Windows/compile.ps1+++ b/Windows/compile.ps1@@ -228,35 +228,6 @@ if ($success) {Write-Host $publishResult}- Write-Host "`nPublishing CLI..." -ForegroundColor Green- $publishResult = dotnet publish cli/ProxyBridge.CLI.csproj -c Release -r win-x64 --self-contained `- /p:PublishTrimmed=true `- /p:PublishSingleFile=true `- /p:EnableCompressionInSingleFile=true `- /p:DebugType=None `- /p:DebugSymbols=false `- /p:Optimize=true `- /p:TieredCompilation=true `- /p:TieredCompilationQuickJit=false `- /p:ReadyToRun=true `- -o cli/bin/Release/net10.0-windows/win-x64/publish 2>&1- if ($LASTEXITCODE -eq 0) {- Write-Host " CLI published successfully" -ForegroundColor Gray-- Write-Host "`nCopying CLI files to output..." -ForegroundColor Green- $cliPublishPath = "cli\bin\Release\net10.0-windows\win-x64\publish"-- Copy-Item "$cliPublishPath\ProxyBridge_CLI.exe" -Destination $OutputDir -Force- Write-Host " Copied: ProxyBridge_CLI.exe" -ForegroundColor Gray-- Write-Host "`nCleaning up CLI build artifacts..." -ForegroundColor Yellow- Remove-Item "cli\bin" -Recurse -Force -ErrorAction SilentlyContinue- Remove-Item "cli\obj" -Recurse -Force -ErrorAction SilentlyContinue- } else {- Write-Host " CLI publish failed!" -ForegroundColor Red- Write-Host $publishResult- }-if (-not $NoSign) {Write-Host "`nSigning binaries..." -ForegroundColor Green$filesToSign = Get-ChildItem $OutputDir -Include *.exe,*.dll -Recursediff --git a/Windows/gui/ViewModels/MainWindowViewModel.cs b/Windows/gui/ViewModels/MainWindowViewModel.csindex 0fa3f9b..e3f0315 100644--- a/Windows/gui/ViewModels/MainWindowViewModel.cs+++ b/Windows/gui/ViewModels/MainWindowViewModel.cs@@ -49,6 +49,8 @@ public class MainWindowViewModel : ViewModelBaseprivate readonly object _activityLogLock = new();private DispatcherTimer? _connectionLogTimer;private DispatcherTimer? _activityLogTimer;+ private int _connectionLogLineCount = 0;+ private int _activityLogLineCount = 0;public void SetMainWindow(Window window){@@ -77,9 +79,6 @@ public class MainWindowViewModel : ViewModelBaseif (_hideDirectConnections && proxyInfo.StartsWith("Direct"))return;- if (_connectionLogTimer?.IsEnabled == false)- _connectionLogTimer.Start();-lock (_connectionLogLock)_pendingConnectionLogs.Add($"[{DateTime.Now:HH:mm:ss}] {processName} (PID:{pid}) -> {destIp}:{destPort} via {proxyInfo}\n");};@@ -95,12 +94,13 @@ public class MainWindowViewModel : ViewModelBase_pendingConnectionLogs.Clear();}- ConnectionsLog += string.Join("", logsToAdd);-- var lines = ConnectionsLog.Split('\n');- if (lines.Length > MAX_CONNECTION_LOG_LINES)- ConnectionsLog = string.Join("\n", lines.Skip(lines.Length - MAX_CONNECTION_LOG_LINES));+ var newConnLog = _connectionsLog + string.Concat(logsToAdd);+ _connectionLogLineCount += logsToAdd.Count;+ if (_connectionLogLineCount > MAX_CONNECTION_LOG_LINES)+ newConnLog = TrimToLastNLines(newConnLog, MAX_CONNECTION_LOG_LINES, out _connectionLogLineCount);+ ConnectionsLog = newConnLog;};+ _connectionLogTimer.Start();_activityLogTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) };_activityLogTimer.Tick += (s, e) =>@@ -112,7 +112,11 @@ public class MainWindowViewModel : ViewModelBaselogsToAdd = new List<string>(_pendingActivityLogs);_pendingActivityLogs.Clear();}- ActivityLog += string.Join("", logsToAdd);+ var newActLog = _activityLog + string.Concat(logsToAdd);+ _activityLogLineCount += logsToAdd.Count;+ if (_activityLogLineCount > MAX_ACTIVITY_LOG_LINES)+ newActLog = TrimToLastNLines(newActLog, MAX_ACTIVITY_LOG_LINES, out _activityLogLineCount);+ ActivityLog = newActLog;};_activityLogTimer.Start();@@ -212,18 +216,6 @@ public class MainWindowViewModel : ViewModelBase{if (SetProperty(ref _activityLog, value)){- if (!string.IsNullOrEmpty(_activityLog))- {- var lines = _activityLog.Split('\n');- if (lines.Length > MAX_ACTIVITY_LOG_LINES)- {- var oldLog = _activityLog;- var linesToKeep = lines.Skip(lines.Length - MAX_ACTIVITY_LOG_LINES).ToArray();- _activityLog = string.Join("\n", linesToKeep);- oldLog = null!;- }- }-if (string.IsNullOrWhiteSpace(_activitySearchText))FilteredActivityLog = _activityLog;}@@ -324,7 +316,7 @@ public class MainWindowViewModel : ViewModelBaseif (value){_connectionsLog = StripDirectLines(_connectionsLog);- FilteredConnectionsLog = null!;+ _connectionLogLineCount = CountNewlines(_connectionsLog);FilteredConnectionsLog = string.IsNullOrWhiteSpace(_connectionsSearchText)? _connectionsLog: FilterLog(_connectionsLog, _connectionsSearchText);@@ -357,14 +349,9 @@ public class MainWindowViewModel : ViewModelBaseProxyBridgeService.SetTrafficLoggingEnabled(false);- ConnectionsLog = null!;- FilteredConnectionsLog = null!;+ _connectionLogLineCount = 0;ConnectionsLog = "";FilteredConnectionsLog = "";-- GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);- GC.WaitForPendingFinalizers();- GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);}SaveCurrentProfileAsync();}@@ -553,15 +540,9 @@ public class MainWindowViewModel : ViewModelBase_pendingConnectionLogs.Clear();}- ConnectionsLog = null!;- FilteredConnectionsLog = null!;-+ _connectionLogLineCount = 0;ConnectionsLog = "";FilteredConnectionsLog = "";-- GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);- GC.WaitForPendingFinalizers();- GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);});ClearActivityLogCommand = new RelayCommand(() =>@@ -571,12 +552,9 @@ public class MainWindowViewModel : ViewModelBase_pendingActivityLogs.Clear();}+ _activityLogLineCount = 0;ActivityLog = "";FilteredActivityLog = "";-- GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);- GC.WaitForPendingFinalizers();- GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);});SearchConnectionsCommand = new RelayCommand(() =>@@ -905,6 +883,33 @@ public class MainWindowViewModel : ViewModelBasereturn sb.ToString();}+ private static string TrimToLastNLines(string log, int maxLines, out int actualLines)+ {+ int newlines = 0;+ for (int i = log.Length - 1; i >= 0; i--)+ {+ if (log[i] == '\n')+ {+ newlines++;+ if (newlines > maxLines)+ {+ actualLines = maxLines;+ return log.Substring(i + 1);+ }+ }+ }+ actualLines = newlines;+ return log;+ }++ private static int CountNewlines(string log)+ {+ int count = 0;+ foreach (char c in log)+ if (c == '\n') count++;+ return count;+ }+private void LoadConfiguration(){trydiff --git a/Windows/installer/ProxyBridge.nsi b/Windows/installer/ProxyBridge.nsiindex e257d0b..26f9860 100644--- a/Windows/installer/ProxyBridge.nsi+++ b/Windows/installer/ProxyBridge.nsi@@ -47,8 +47,6 @@ Section "MainSection" SEC01; Kill any running ProxyBridge instance before overwriting files.; This prevents "file in use" errors on update/reinstall.nsExec::ExecToLog 'taskkill /F /IM ProxyBridge.exe'- nsExec::ExecToLog 'taskkill /F /IM ProxyBridge_CLI.exe'-; Stop and unload the WinDivert driver so WinDivert64.sys can be replaced.nsExec::ExecToLog 'sc stop WinDivert'nsExec::ExecToLog 'sc delete WinDivert'@@ -61,7 +59,6 @@ Section "MainSection" SEC01SetOverwrite onFile "..\output\ProxyBridge.exe"- File "..\output\ProxyBridge_CLI.exe"File "..\output\ProxyBridgeCore.dll"File "..\output\WinDivert.dll"File "..\output\WinDivert64.sys"@@ -95,7 +92,6 @@ SectionEndSection UninstallDelete "$INSTDIR\ProxyBridge.exe"- Delete "$INSTDIR\ProxyBridge_CLI.exe"Delete "$INSTDIR\ProxyBridgeCore.dll"Delete "$INSTDIR\WinDivert.dll"Delete "$INSTDIR\WinDivert64.sys"