Skip to content

Commit 9590361

Browse files
authored
VERSION 2.0 Merge pull request #2 from InterceptSuite/dev
VERSION 2.0
2 parents 394c99c + 3f1d1ed commit 9590361

38 files changed

+4055
-514
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ gui/bin/**
99
gui/obj/**
1010
cli/bin/**
1111
cli/obj/**
12+
.vscode/**
13+
output/ProxyBridge_CLI.pdb

README.md

Lines changed: 160 additions & 125 deletions
Large diffs are not rendered by default.

cli/Program.cs

Lines changed: 282 additions & 99 deletions
Large diffs are not rendered by default.

cli/ProxyBridge.CLI.csproj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,28 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<AssemblyName>ProxyBridge_CLI</AssemblyName>
9-
<Version>1.1.0</Version>
9+
<Version>2.0.0</Version>
1010
<PublishAot>true</PublishAot>
1111
<InvariantGlobalization>false</InvariantGlobalization>
1212
<SelfContained>true</SelfContained>
13+
14+
<IlcOptimizationPreference>Size</IlcOptimizationPreference>
15+
<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
16+
<IlcTrimMetadata>true</IlcTrimMetadata>
17+
<EventSourceSupport>false</EventSourceSupport>
18+
<UseSystemResourceKeys>true</UseSystemResourceKeys>
19+
<DebuggerSupport>false</DebuggerSupport>
20+
<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
21+
<MetadataUpdaterSupport>false</MetadataUpdaterSupport>
22+
<StackTraceSupport>false</StackTraceSupport>
23+
24+
<PublishTrimmed>true</PublishTrimmed>
25+
<TrimMode>link</TrimMode>
1326
</PropertyGroup>
1427

28+
<ItemGroup>
29+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
30+
<PackageReference Include="System.Text.Json" Version="9.0.0" />
31+
</ItemGroup>
32+
1533
</Project>

cli/ProxyBridgeNative.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public enum RuleAction
3232
BLOCK = 2
3333
}
3434

35+
public enum RuleProtocol
36+
{
37+
TCP = 0,
38+
UDP = 1,
39+
BOTH = 2
40+
}
41+
3542
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
3643
public delegate void LogCallback([MarshalAs(UnmanagedType.LPStr)] string message);
3744

@@ -46,12 +53,11 @@ public delegate void ConnectionCallback(
4653
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
4754
public static extern uint ProxyBridge_AddRule(
4855
[MarshalAs(UnmanagedType.LPStr)] string processName,
56+
[MarshalAs(UnmanagedType.LPStr)] string targetHosts,
57+
[MarshalAs(UnmanagedType.LPStr)] string targetPorts,
58+
RuleProtocol protocol,
4959
RuleAction action);
5060

51-
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
52-
[return: MarshalAs(UnmanagedType.Bool)]
53-
public static extern bool ProxyBridge_ClearRules();
54-
5561
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
5662
[return: MarshalAs(UnmanagedType.Bool)]
5763
public static extern bool ProxyBridge_EnableRule(uint ruleId);
@@ -65,14 +71,19 @@ public static extern uint ProxyBridge_AddRule(
6571
public static extern bool ProxyBridge_SetProxyConfig(
6672
ProxyType type,
6773
[MarshalAs(UnmanagedType.LPStr)] string proxyIp,
68-
ushort proxyPort);
74+
ushort proxyPort,
75+
[MarshalAs(UnmanagedType.LPStr)] string username,
76+
[MarshalAs(UnmanagedType.LPStr)] string password);
6977

7078
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
7179
public static extern void ProxyBridge_SetLogCallback(LogCallback callback);
7280

7381
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
7482
public static extern void ProxyBridge_SetConnectionCallback(ConnectionCallback callback);
7583

84+
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
85+
public static extern void ProxyBridge_SetDnsViaProxy([MarshalAs(UnmanagedType.Bool)] bool enable);
86+
7687
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
7788
[return: MarshalAs(UnmanagedType.Bool)]
7889
public static extern bool ProxyBridge_Start();

compile.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ if ($success) {
245245
Pop-Location
246246
if ($LASTEXITCODE -eq 0) {
247247
Write-Host " Installer created successfully" -ForegroundColor Green
248-
$installerName = "ProxyBridge-Setup-1.1.0.exe"
248+
$installerName = "ProxyBridge-Setup-2.0.0.exe"
249249
if (Test-Path "installer\$installerName") {
250250
Move-Item "installer\$installerName" -Destination $OutputDir -Force
251251
Write-Host " Moved: $installerName -> $OutputDir\" -ForegroundColor Gray

gui/Interop/ProxyBridgeNative.cs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public enum RuleAction
3535
BLOCK = 2
3636
}
3737

38+
public enum RuleProtocol
39+
{
40+
TCP = 0,
41+
UDP = 1,
42+
BOTH = 2
43+
}
44+
3845
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
3946
public delegate void LogCallback([MarshalAs(UnmanagedType.LPStr)] string message);
4047

@@ -49,38 +56,63 @@ public delegate void ConnectionCallback(
4956
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
5057
public static extern uint ProxyBridge_AddRule(
5158
[MarshalAs(UnmanagedType.LPStr)] string processName,
59+
[MarshalAs(UnmanagedType.LPStr)] string targetHosts,
60+
[MarshalAs(UnmanagedType.LPStr)] string targetPorts,
61+
RuleProtocol protocol,
5262
RuleAction action);
5363

5464
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
5565
[return: MarshalAs(UnmanagedType.Bool)]
56-
public static extern bool ProxyBridge_ClearRules();
66+
public static extern bool ProxyBridge_EnableRule(uint ruleId);
5767

5868
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
5969
[return: MarshalAs(UnmanagedType.Bool)]
60-
public static extern bool ProxyBridge_EnableRule(uint ruleId);
70+
public static extern bool ProxyBridge_DisableRule(uint ruleId);
6171

6272
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
6373
[return: MarshalAs(UnmanagedType.Bool)]
64-
public static extern bool ProxyBridge_DisableRule(uint ruleId);
74+
public static extern bool ProxyBridge_DeleteRule(uint ruleId);
75+
76+
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
77+
[return: MarshalAs(UnmanagedType.Bool)]
78+
public static extern bool ProxyBridge_EditRule(
79+
uint ruleId,
80+
[MarshalAs(UnmanagedType.LPStr)] string processName,
81+
[MarshalAs(UnmanagedType.LPStr)] string targetHosts,
82+
[MarshalAs(UnmanagedType.LPStr)] string targetPorts,
83+
RuleProtocol protocol,
84+
RuleAction action);
6585

6686
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
6787
[return: MarshalAs(UnmanagedType.Bool)]
6888
public static extern bool ProxyBridge_SetProxyConfig(
6989
ProxyType type,
7090
[MarshalAs(UnmanagedType.LPStr)] string proxyIp,
71-
ushort proxyPort);
91+
ushort proxyPort,
92+
[MarshalAs(UnmanagedType.LPStr)] string username,
93+
[MarshalAs(UnmanagedType.LPStr)] string password);
7294

7395
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
7496
public static extern void ProxyBridge_SetLogCallback(LogCallback callback);
7597

7698
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
7799
public static extern void ProxyBridge_SetConnectionCallback(ConnectionCallback callback);
78100

101+
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
102+
public static extern void ProxyBridge_SetDnsViaProxy([MarshalAs(UnmanagedType.Bool)] bool enable);
103+
79104
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
80105
[return: MarshalAs(UnmanagedType.Bool)]
81106
public static extern bool ProxyBridge_Start();
82107

83108
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
84109
[return: MarshalAs(UnmanagedType.Bool)]
85110
public static extern bool ProxyBridge_Stop();
111+
112+
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
113+
public static extern int ProxyBridge_TestConnection(
114+
[MarshalAs(UnmanagedType.LPStr)] string targetHost,
115+
ushort targetPort,
116+
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder resultBuffer,
117+
UIntPtr bufferSize);
86118
}

gui/ProxyBridge.GUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<AssemblyName>ProxyBridge</AssemblyName>
99
<RootNamespace>ProxyBridge.GUI</RootNamespace>
10-
<Version>1.1.0</Version>
10+
<Version>2.0.0</Version>
1111
<ApplicationIcon>Assets\logo.ico</ApplicationIcon>
1212
<!-- Native AOT Configuration -->
1313
<PublishAot>true</PublishAot>

gui/Services/ProxyBridgeService.cs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ public bool Stop()
4949
return !_isRunning;
5050
}
5151

52-
public bool SetProxyConfig(string type, string ip, ushort port)
52+
public bool SetProxyConfig(string type, string ip, ushort port, string username, string password)
5353
{
5454
var proxyType = type.ToUpper() == "HTTP"
5555
? ProxyBridgeNative.ProxyType.HTTP
5656
: ProxyBridgeNative.ProxyType.SOCKS5;
5757

58-
return ProxyBridgeNative.ProxyBridge_SetProxyConfig(proxyType, ip, port);
58+
return ProxyBridgeNative.ProxyBridge_SetProxyConfig(proxyType, ip, port, username, password);
5959
}
6060

61-
public uint AddRule(string processName, string action)
61+
public uint AddRule(string processName, string targetHosts, string targetPorts, string protocol, string action)
6262
{
6363
var ruleAction = action.ToUpper() switch
6464
{
@@ -67,7 +67,15 @@ public uint AddRule(string processName, string action)
6767
_ => ProxyBridgeNative.RuleAction.PROXY
6868
};
6969

70-
return ProxyBridgeNative.ProxyBridge_AddRule(processName, ruleAction);
70+
var ruleProtocol = protocol.ToUpper() switch
71+
{
72+
"UDP" => ProxyBridgeNative.RuleProtocol.UDP,
73+
"BOTH" => ProxyBridgeNative.RuleProtocol.BOTH,
74+
"TCP+UDP" => ProxyBridgeNative.RuleProtocol.BOTH,
75+
_ => ProxyBridgeNative.RuleProtocol.TCP
76+
};
77+
78+
return ProxyBridgeNative.ProxyBridge_AddRule(processName, targetHosts, targetPorts, ruleProtocol, ruleAction);
7179
}
7280

7381
public bool EnableRule(uint ruleId)
@@ -80,9 +88,46 @@ public bool DisableRule(uint ruleId)
8088
return ProxyBridgeNative.ProxyBridge_DisableRule(ruleId);
8189
}
8290

83-
public bool ClearRules()
91+
public bool DeleteRule(uint ruleId)
92+
{
93+
return ProxyBridgeNative.ProxyBridge_DeleteRule(ruleId);
94+
}
95+
96+
public bool EditRule(uint ruleId, string processName, string targetHosts, string targetPorts, string protocol, string action)
97+
{
98+
var ruleAction = action.ToUpper() switch
99+
{
100+
"DIRECT" => ProxyBridgeNative.RuleAction.DIRECT,
101+
"BLOCK" => ProxyBridgeNative.RuleAction.BLOCK,
102+
_ => ProxyBridgeNative.RuleAction.PROXY
103+
};
104+
105+
var ruleProtocol = protocol.ToUpper() switch
106+
{
107+
"UDP" => ProxyBridgeNative.RuleProtocol.UDP,
108+
"BOTH" => ProxyBridgeNative.RuleProtocol.BOTH,
109+
"TCP+UDP" => ProxyBridgeNative.RuleProtocol.BOTH,
110+
_ => ProxyBridgeNative.RuleProtocol.TCP
111+
};
112+
113+
return ProxyBridgeNative.ProxyBridge_EditRule(ruleId, processName, targetHosts, targetPorts, ruleProtocol, ruleAction);
114+
}
115+
116+
public void SetDnsViaProxy(bool enable)
117+
{
118+
ProxyBridgeNative.ProxyBridge_SetDnsViaProxy(enable);
119+
}
120+
121+
public string TestConnection(string targetHost, ushort targetPort)
84122
{
85-
return ProxyBridgeNative.ProxyBridge_ClearRules();
123+
var buffer = new System.Text.StringBuilder(4096);
124+
int result = ProxyBridgeNative.ProxyBridge_TestConnection(
125+
targetHost,
126+
targetPort,
127+
buffer,
128+
(UIntPtr)buffer.Capacity);
129+
130+
return buffer.ToString();
86131
}
87132

88133
public void Dispose()

gui/Services/SettingsService.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.IO;
3+
using System.Text.Json;
4+
using System.Text.Json.Serialization;
5+
6+
namespace ProxyBridge.GUI.Services;
7+
8+
[JsonSourceGenerationOptions(WriteIndented = true)]
9+
[JsonSerializable(typeof(AppSettings))]
10+
internal partial class AppSettingsContext : JsonSerializerContext
11+
{
12+
}
13+
14+
public class SettingsService
15+
{
16+
private static readonly string SettingsPath = Path.Combine(
17+
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
18+
"ProxyBridge",
19+
"settings.json");
20+
21+
public AppSettings LoadSettings()
22+
{
23+
try
24+
{
25+
if (File.Exists(SettingsPath))
26+
{
27+
var json = File.ReadAllText(SettingsPath);
28+
var settings = JsonSerializer.Deserialize(json, AppSettingsContext.Default.AppSettings);
29+
return settings ?? new AppSettings();
30+
}
31+
}
32+
catch
33+
{
34+
// If there's any error loading settings, return defaults
35+
}
36+
37+
return new AppSettings();
38+
}
39+
40+
public void SaveSettings(AppSettings settings)
41+
{
42+
try
43+
{
44+
var directory = Path.GetDirectoryName(SettingsPath);
45+
if (directory != null && !Directory.Exists(directory))
46+
{
47+
Directory.CreateDirectory(directory);
48+
}
49+
50+
var json = JsonSerializer.Serialize(settings, AppSettingsContext.Default.AppSettings);
51+
File.WriteAllText(SettingsPath, json);
52+
}
53+
catch
54+
{
55+
// silently fail
56+
}
57+
}
58+
}
59+
60+
public class AppSettings
61+
{
62+
public bool CheckForUpdatesOnStartup { get; set; } = true;
63+
public DateTime LastUpdateCheck { get; set; } = DateTime.MinValue;
64+
}

0 commit comments

Comments
 (0)