Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
#55 updated CLI to improve memory usage
Sourav Kalal9ee26577f9af
diff --git a/Windows/cli/Program.cs b/Windows/cli/Program.csindex 8489b65..d8aa59d 100644--- a/Windows/cli/Program.cs+++ b/Windows/cli/Program.cs@@ -143,11 +143,27 @@ class ProgramparsedRules.AddRange(fileRules);}- _logCallback = OnLog;- _connectionCallback = OnConnection;+ // Only register callbacks when verbose level needs them+ // -v 0: No callbacks at all -> disable traffic logging+ // -v 1: Only log messages+ // -v 2: Only connection events+ // -v 3: Both logs and connections- ProxyBridgeNative.ProxyBridge_SetLogCallback(_logCallback);- ProxyBridgeNative.ProxyBridge_SetConnectionCallback(_connectionCallback);+ if (_verboseLevel == 1 || _verboseLevel == 3)+ {+ _logCallback = OnLog;+ ProxyBridgeNative.ProxyBridge_SetLogCallback(_logCallback);+ }++ if (_verboseLevel == 2 || _verboseLevel == 3)+ {+ _connectionCallback = OnConnection;+ ProxyBridgeNative.ProxyBridge_SetConnectionCallback(_connectionCallback);+ }++ // Disable traffic logging if no callbacks registered (prevents memory leak)+ bool enableTrafficLogging = _verboseLevel > 0;+ ProxyBridgeNative.ProxyBridge_SetTrafficLoggingEnabled(enableTrafficLogging);Console.WriteLine($"Proxy: {proxyInfo.Type}://{proxyInfo.Host}:{proxyInfo.Port}");if (!string.IsNullOrEmpty(proxyInfo.Username))@@ -215,7 +231,7 @@ class Programwhile (_isRunning){- await Task.Delay(100);+ await Task.Delay(500);}return 0;@@ -230,16 +246,17 @@ class Programprivate static void OnLog(string message){// Verbose 1 = logs only, Verbose 3 = both- if (_verboseLevel == 1 || _verboseLevel == 3)+ if (_verboseLevel is 1 or 3){- Console.WriteLine($"[LOG] {message}");+ Console.Write("[LOG] ");+ Console.WriteLine(message);}}private static void OnConnection(string processName, uint pid, string destIp, ushort destPort, string proxyInfo){// Verbose 2 = connections only, Verbose 3 = both- if (_verboseLevel == 2 || _verboseLevel == 3)+ if (_verboseLevel is 2 or 3){Console.WriteLine($"[CONN] {processName} (PID:{pid}) -> {destIp}:{destPort} via {proxyInfo}");}@@ -341,7 +358,7 @@ class Programprivate static List<(string ProcessName, string TargetHosts, string TargetPorts, ProxyBridgeNative.RuleProtocol Protocol, ProxyBridgeNative.RuleAction Action)> ParseRules(string[] rules){- var parsedRules = new List<(string, string, string, ProxyBridgeNative.RuleProtocol, ProxyBridgeNative.RuleAction)>();+ var parsedRules = new List<(string, string, string, ProxyBridgeNative.RuleProtocol, ProxyBridgeNative.RuleAction)>(rules.Length);foreach (var rule in rules){@@ -409,7 +426,8 @@ class ProgramConsole.WriteLine(" | |_) | '__/ _ \\ \\/ / | | | | _ \\| '__| |/ _` |/ _` |/ _ \\");Console.WriteLine(" | __/| | | (_) > <| |_| | | |_) | | | | (_| | (_| | __/");Console.WriteLine(" |_| |_| \\___/_/\\_\\\\__, | |____/|_| |_|\\__,_|\\__, |\\___|");- Console.WriteLine(" |___/ |___/ V3.0.0");+ var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString(3) ?? "4.0.0";+ Console.WriteLine($" |___/ |___/ V{version}");Console.WriteLine();Console.WriteLine(" Universal proxy client for Windows applications");Console.WriteLine();diff --git a/Windows/cli/ProxyBridgeNative.cs b/Windows/cli/ProxyBridgeNative.csindex 04ce8a6..fc29a02 100644--- a/Windows/cli/ProxyBridgeNative.cs+++ b/Windows/cli/ProxyBridgeNative.cs@@ -81,6 +81,9 @@ public static class ProxyBridgeNative[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]public static extern void ProxyBridge_SetConnectionCallback(ConnectionCallback callback);+ [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]+ public static extern void ProxyBridge_SetTrafficLoggingEnabled([MarshalAs(UnmanagedType.Bool)] bool enable);+[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]public static extern void ProxyBridge_SetDnsViaProxy([MarshalAs(UnmanagedType.Bool)] bool enable);