Skip to content

Commit e2f78bf

Browse files
Merge pull request #54 from InvisibleManVPN/develop
InvisibleMan XRay version 0.7.5
2 parents c387ec6 + 2850b61 commit e2f78bf

45 files changed

Lines changed: 1323 additions & 160 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/Files
22
/InvisibleMan-XRay/bin
33
/InvisibleMan-XRay/obj
4-
*.dll
4+
*.dll
5+
*.dat
6+
*.exe

InvisibleMan-XRay/Assets/Icons.xaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</VisualBrush.Visual>
1010
</VisualBrush>
1111

12-
<VisualBrush x:Key="Icon.Disconnect">
12+
<VisualBrush x:Key="Icon.Stop">
1313
<VisualBrush.Visual>
1414
<Canvas>
1515
<Path Data="M656,328c0,181.15-146.85,328-328,328S0,509.15,0,328,146.85,0,328,0,656,146.85,656,328Z" Fill="#2d2d2d"/>
@@ -19,7 +19,7 @@
1919
</VisualBrush.Visual>
2020
</VisualBrush>
2121

22-
<VisualBrush x:Key="Icon.Connect">
22+
<VisualBrush x:Key="Icon.Run">
2323
<VisualBrush.Visual>
2424
<Canvas>
2525
<Path Data="M656,328c0,181.15-146.85,328-328,328S0,509.15,0,328,146.85,0,328,0,656,146.85,656,328Z" Fill="#2d2d2d"/>
@@ -77,6 +77,14 @@
7777
</VisualBrush.Visual>
7878
</VisualBrush>
7979

80+
<VisualBrush x:Key="Icon.Close">
81+
<VisualBrush.Visual>
82+
<Canvas>
83+
<Path Data="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" Fill="White"/>
84+
</Canvas>
85+
</VisualBrush.Visual>
86+
</VisualBrush>
87+
8088
<VisualBrush x:Key="Icon.Connection">
8189
<VisualBrush.Visual>
8290
<Canvas>

InvisibleMan-XRay/Core/InvisibleManXRayCore.cs

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace InvisibleManXRay.Core
44
{
55
using Models;
6-
using Models.Proxies;
6+
using Handlers.Proxies;
7+
using Handlers.Tunnels;
78
using Values;
89
using Utilities;
910

@@ -14,16 +15,28 @@ public class InvisibleManXRayCore
1415
private const int TEST_PORT = 10802;
1516

1617
private Func<Config> getConfig;
18+
private Func<Mode> getMode;
19+
private Func<string> getTunIp;
20+
private Func<string> getDns;
1721
private Func<IProxy> getProxy;
22+
private Func<ITunnel> getTunnel;
1823
private Action<string> onFailLoadingConfig;
1924

2025
public void Setup(
2126
Func<Config> getConfig,
27+
Func<Mode> getMode,
28+
Func<string> getTunIp,
29+
Func<string> getDns,
2230
Func<IProxy> getProxy,
31+
Func<ITunnel> getTunnel,
2332
Action<string> onFailLoadingConfig)
2433
{
2534
this.getConfig = getConfig;
35+
this.getMode = getMode;
36+
this.getTunIp = getTunIp;
37+
this.getDns = getDns;
2638
this.getProxy = getProxy;
39+
this.getTunnel = getTunnel;
2740
this.onFailLoadingConfig = onFailLoadingConfig;
2841
}
2942

@@ -54,31 +67,111 @@ public Status LoadConfig(string path)
5467
return new Status(Code.SUCCESS, SubCode.SUCCESS, file);
5568
}
5669

57-
public void EnableProxy()
70+
public Status EnableMode()
5871
{
59-
IProxy proxy = getProxy.Invoke();
60-
proxy.Enable(LOCAL_HOST, DEFAULT_PORT);
72+
Mode mode = getMode.Invoke();
73+
74+
if (mode == Mode.PROXY)
75+
return EnableProxy();
76+
else
77+
return EnableTunnel();
6178
}
6279

63-
public void DisableProxy()
80+
public void DisableMode()
6481
{
65-
IProxy proxy = getProxy.Invoke();
66-
proxy.Disable();
82+
DisableProxy();
83+
DisableTunnel();
6784
}
6885

6986
public void Run(string config)
7087
{
71-
XRayCoreWrapper.StartServer(config, DEFAULT_PORT);
88+
Mode mode = getMode.Invoke();
89+
XRayCoreWrapper.StartServer(config, DEFAULT_PORT, mode == Mode.TUN);
7290
}
7391

7492
public void Stop()
7593
{
7694
XRayCoreWrapper.StopServer();
7795
}
7896

97+
public void Cancel()
98+
{
99+
CancelProxy();
100+
CancelTunnel();
101+
}
102+
79103
public bool Test(string config)
80104
{
81105
return XRayCoreWrapper.TestConnection(config, TEST_PORT);
82106
}
107+
108+
private Status EnableProxy()
109+
{
110+
IProxy proxy = getProxy.Invoke();
111+
112+
return proxy.Enable(
113+
ip: LOCAL_HOST,
114+
port: DEFAULT_PORT
115+
);
116+
}
117+
118+
private void DisableProxy()
119+
{
120+
IProxy proxy = getProxy.Invoke();
121+
proxy.Disable();
122+
}
123+
124+
private Status EnableTunnel()
125+
{
126+
Status configStatus = LoadConfigFile();
127+
if (configStatus.Code == Code.ERROR)
128+
return configStatus;
129+
130+
string server = JsonUtility.Find(
131+
key: "address",
132+
parent: "outbounds",
133+
jsonString: configStatus.Content.ToString()
134+
);
135+
string address = getTunIp.Invoke();
136+
string dns = getDns.Invoke();
137+
138+
ITunnel tunnel = getTunnel.Invoke();
139+
140+
return tunnel.Enable(
141+
ip: LOCAL_HOST,
142+
port: DEFAULT_PORT,
143+
address: address,
144+
server: server,
145+
dns: dns
146+
);
147+
148+
Status LoadConfigFile()
149+
{
150+
Config config = getConfig.Invoke();
151+
152+
if (config == null)
153+
return new Status(Code.ERROR, SubCode.NO_CONFIG, Message.NO_CONFIGS_FOUND);
154+
155+
return new Status(Code.SUCCESS, SubCode.SUCCESS, System.IO.File.ReadAllText(config.Path).ToLower());
156+
}
157+
}
158+
159+
private void DisableTunnel()
160+
{
161+
ITunnel tunnel = getTunnel.Invoke();
162+
tunnel.Disable();
163+
}
164+
165+
private void CancelProxy()
166+
{
167+
IProxy proxy = getProxy.Invoke();
168+
proxy.Cancel();
169+
}
170+
171+
private void CancelTunnel()
172+
{
173+
ITunnel tunnel = getTunnel.Invoke();
174+
tunnel.Cancel();
175+
}
83176
}
84177
}

InvisibleMan-XRay/Core/XRayCoreWrapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public static string LoadConfig(string fileFormat, string filePath)
3131
static extern IntPtr LoadConfig(string format, string file);
3232
}
3333

34-
public static void StartServer(string config, int port)
34+
public static void StartServer(string config, int port, bool isSocks)
3535
{
36-
StartServer(config, port);
36+
StartServer(config, port, isSocks);
3737

3838
[DllImport(Path.XRAY_CORE_DLL, EntryPoint = "StartServer")]
39-
static extern void StartServer(string config, int port);
39+
static extern void StartServer(string config, int port, bool isSocks);
4040
}
4141

4242
public static void StopServer()

InvisibleMan-XRay/Factories/WindowFactory.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,32 @@ public void Setup(InvisibleManXRayCore core, HandlersManager handlersManager)
1717
this.handlersManager = handlersManager;
1818
}
1919

20+
public MainWindow GetMainWindow() => Application.Current.MainWindow as MainWindow;
21+
2022
public MainWindow CreateMainWindow()
2123
{
2224
ConfigHandler configHandler = handlersManager.GetHandler<ConfigHandler>();
2325
UpdateHandler updateHandler = handlersManager.GetHandler<UpdateHandler>();
26+
BroadcastHandler broadcastHandler = handlersManager.GetHandler<BroadcastHandler>();
2427
LinkHandler linkHandler = handlersManager.GetHandler<LinkHandler>();
2528

2629
MainWindow mainWindow = new MainWindow();
2730
mainWindow.Setup(
2831
getConfig: configHandler.GetCurrentConfig,
2932
loadConfig: core.LoadConfig,
33+
enableMode: core.EnableMode,
3034
checkForUpdate: updateHandler.CheckForUpdate,
35+
checkForBroadcast: broadcastHandler.CheckForBroadcast,
3136
openServerWindow: CreateServerWindow,
3237
openUpdateWindow: CreateUpdateWindow,
3338
openAboutWindow: CreateAboutWindow,
3439
onRunServer: core.Run,
3540
onStopServer: core.Stop,
36-
onEnableProxy: core.EnableProxy,
37-
onDisableProxy: core.DisableProxy,
41+
onCancelServer: core.Cancel,
42+
onDisableMode: core.DisableMode,
3843
onGitHubClick: linkHandler.OpenGitHubRepositoryLink,
39-
onBugReportingClick: linkHandler.OpenBugReportingLink
44+
onBugReportingClick: linkHandler.OpenBugReportingLink,
45+
onCustomLinkClick: linkHandler.OpenCustomLink
4046
);
4147

4248
return mainWindow;
@@ -75,7 +81,7 @@ private ServerWindow CreateServerWindow()
7581
ConfigHandler configHandler = handlersManager.GetHandler<ConfigHandler>();
7682
TemplateHandler templateHandler = handlersManager.GetHandler<TemplateHandler>();
7783
SettingsHandler settingsHandler = handlersManager.GetHandler<SettingsHandler>();
78-
MainWindow mainWindow = Application.Current.MainWindow as MainWindow;
84+
MainWindow mainWindow = GetMainWindow();
7985

8086
ServerWindow serverWindow = new ServerWindow();
8187
serverWindow.Setup(
@@ -96,7 +102,7 @@ void UpdateConfig(int index)
96102
{
97103
settingsHandler.UpdateCurrentConfigIndex(index);
98104
mainWindow.UpdateUI();
99-
mainWindow.TryReconnect();
105+
mainWindow.TryRerun();
100106
}
101107
}
102108
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System.Diagnostics;
2+
using System.Collections.Generic;
3+
4+
namespace InvisibleManXRay.Foundation
5+
{
6+
using Values;
7+
8+
public class Processor
9+
{
10+
private Dictionary<string, Process> processes;
11+
12+
public Processor()
13+
{
14+
this.processes = new Dictionary<string, Process>();
15+
}
16+
17+
public void StartProcess(string processName, string fileName, string command, bool runAsAdmin)
18+
{
19+
try
20+
{
21+
Process process = new Process();
22+
process.StartInfo.FileName = fileName;
23+
process.StartInfo.Arguments = command;
24+
process.StartInfo.UseShellExecute = true;
25+
process.StartInfo.CreateNoWindow = true;
26+
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
27+
process.StartInfo.WorkingDirectory = Directory.SERVICES;
28+
29+
if (runAsAdmin)
30+
process.StartInfo.Verb = "runas";
31+
32+
process.Start();
33+
AddProcess(process, processName);
34+
}
35+
catch
36+
{
37+
StopProcess(processName);
38+
}
39+
}
40+
41+
public void StopProcess(string processName)
42+
{
43+
try
44+
{
45+
Process process = processes[processName];
46+
RemoveProcess(processName);
47+
process.Kill(true);
48+
}
49+
catch
50+
{
51+
52+
}
53+
}
54+
55+
public void StopSystemProcesses(string processName)
56+
{
57+
Process[] runningProcesses = Process.GetProcessesByName(processName);
58+
59+
foreach(Process process in runningProcesses)
60+
{
61+
process.Kill();
62+
}
63+
}
64+
65+
private void AddProcess(Process process, string processName)
66+
{
67+
processes.Add(processName, process);
68+
}
69+
70+
private void RemoveProcess(string processName)
71+
{
72+
if (!IsProcessExists(processName))
73+
return;
74+
75+
processes.Remove(processName);
76+
}
77+
78+
public bool IsProcessRunning(string processName)
79+
{
80+
if (!IsProcessExists(processName))
81+
return false;
82+
83+
if (processes[processName].HasExited)
84+
{
85+
RemoveProcess(processName);
86+
return false;
87+
}
88+
89+
return Process.GetProcessById(processes[processName].Id) != null;
90+
}
91+
92+
private bool IsProcessExists(string processName) => processes.ContainsKey(processName);
93+
}
94+
}

0 commit comments

Comments
 (0)