Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

#80 added UTF-8 support for process name

AnoF-Cyberd470973bbd4c
diff --git a/Windows/gui/Interop/ProxyBridgeNative.cs b/Windows/gui/Interop/ProxyBridgeNative.cs
index aace1fd..cd31a7a 100644
--- a/Windows/gui/Interop/ProxyBridgeNative.cs
+++ b/Windows/gui/Interop/ProxyBridgeNative.cs
@@ -47,7 +47,7 @@ public static class ProxyBridgeNative
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ConnectionCallback(
- [MarshalAs(UnmanagedType.LPStr)] string processName,
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string processName,
uint pid,
[MarshalAs(UnmanagedType.LPStr)] string destIp,
ushort destPort,
@@ -55,7 +55,7 @@ public static class ProxyBridgeNative
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern uint ProxyBridge_AddRule(
- [MarshalAs(UnmanagedType.LPStr)] string processName,
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string processName,
[MarshalAs(UnmanagedType.LPStr)] string targetHosts,
[MarshalAs(UnmanagedType.LPStr)] string targetPorts,
RuleProtocol protocol,
@@ -78,7 +78,7 @@ public static class ProxyBridgeNative
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ProxyBridge_EditRule(
uint ruleId,
- [MarshalAs(UnmanagedType.LPStr)] string processName,
+ [MarshalAs(UnmanagedType.LPUTF8Str)] string processName,
[MarshalAs(UnmanagedType.LPStr)] string targetHosts,
[MarshalAs(UnmanagedType.LPStr)] string targetPorts,
RuleProtocol protocol,
diff --git a/Windows/gui/ViewModels/ProxyRulesViewModel.cs b/Windows/gui/ViewModels/ProxyRulesViewModel.cs
index ab4500a..8f017f0 100644
--- a/Windows/gui/ViewModels/ProxyRulesViewModel.cs
+++ b/Windows/gui/ViewModels/ProxyRulesViewModel.cs
@@ -145,7 +145,7 @@ public class ProxyRulesViewModel : ViewModelBase
NewTargetHosts = ValidationHelper.DefaultIfEmpty(NewTargetHosts);
NewTargetPorts = ValidationHelper.DefaultIfEmpty(NewTargetPorts);
- if (!System.Text.RegularExpressions.Regex.IsMatch(NewProcessName, @"^[a-zA-Z0-9\s._\-*;""\\:()]+$"))
+ if (!System.Text.RegularExpressions.Regex.IsMatch(NewProcessName, @"^[\w\s._\-*;""\\:()\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF]+$"))
{
ProcessNameError = "Invalid characters in process name. Only letters, numbers, spaces, dots, dashes, underscores, semicolons, quotes, parentheses, and * are allowed";
return;
diff --git a/Windows/src/ProxyBridge.c b/Windows/src/ProxyBridge.c
index ae6262b..aae2aa3 100644
--- a/Windows/src/ProxyBridge.c
+++ b/Windows/src/ProxyBridge.c
@@ -15,7 +15,7 @@
#define MAXBUF 0xFFFF
#define LOCAL_PROXY_PORT 34010
#define LOCAL_UDP_RELAY_PORT 34011 // its running UDP port still make sure to not run on same port as TCP, opening same port and tcp and udp cause issue and handling port at relay server response injection
-#define MAX_PROCESS_NAME 256
+#define MAX_PROCESS_NAME 1024
#define VERSION "3.2.0"
#define PID_CACHE_SIZE 1024
#define PID_CACHE_TTL_MS 1000
@@ -835,7 +835,7 @@ static DWORD get_process_id_from_udp_connection(UINT32 src_ip, UINT16 src_port)
static BOOL get_process_name_from_pid(DWORD pid, char *name, DWORD name_size)
{
HANDLE hProcess;
- char full_path[MAX_PATH];
+ WCHAR full_path_w[MAX_PATH];
DWORD path_len = MAX_PATH;
if (pid == 0)
@@ -857,13 +857,12 @@ static BOOL get_process_name_from_pid(DWORD pid, char *name, DWORD name_size)
return FALSE;
}
- if (QueryFullProcessImageNameA(hProcess, 0, full_path, &path_len))
+ if (QueryFullProcessImageNameW(hProcess, 0, full_path_w, &path_len))
{
-
-
- strncpy_s(name, name_size, full_path, _TRUNCATE);
+ // Convert wide string to UTF-8 so Chinese/non-ASCII paths are preserved
+ int converted = WideCharToMultiByte(CP_UTF8, 0, full_path_w, -1, name, (int)name_size, NULL, NULL);
CloseHandle(hProcess);
- return TRUE;
+ return converted > 0;
}
CloseHandle(hProcess);