Skip to content

Commit

Permalink
Merge pull request #62 from InvisibleManVPN/develop
Browse files Browse the repository at this point in the history
InvisibleMan XRay version 0.9.1
  • Loading branch information
InvisibleManVPN authored Jun 24, 2023
2 parents 2d518f2 + 6bcc7c9 commit 054c0a2
Show file tree
Hide file tree
Showing 33 changed files with 1,350 additions and 84 deletions.
2 changes: 2 additions & 0 deletions InvisibleMan-XRay/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<ResourceDictionary Source="Styles/Components/RadioButtons.xaml"/>
<ResourceDictionary Source="Styles/Components/TextBoxes.xaml"/>
<ResourceDictionary Source="Styles/Components/ScrollViews.xaml"/>
<ResourceDictionary Source="Styles/Components/ComboBoxes.xaml"/>
<ResourceDictionary Source="Styles/Components/CheckBoxes.xaml"/>
</ResourceDictionary.MergedDictionaries>

<FontFamily x:Key="SegoeUI">pack://application:,,,/Assets/Fonts/#SegoeUI</FontFamily>
Expand Down
24 changes: 24 additions & 0 deletions InvisibleMan-XRay/Assets/Icons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
</VisualBrush.Visual>
</VisualBrush>

<VisualBrush x:Key="Icon.Settings">
<VisualBrush.Visual>
<Canvas>
<Path Data="M495.9 166.6c3.2 8.7 .5 18.4-6.4 24.6l-43.3 39.4c1.1 8.3 1.7 16.8 1.7 25.4s-.6 17.1-1.7 25.4l43.3 39.4c6.9 6.2 9.6 15.9 6.4 24.6c-4.4 11.9-9.7 23.3-15.8 34.3l-4.7 8.1c-6.6 11-14 21.4-22.1 31.2c-5.9 7.2-15.7 9.6-24.5 6.8l-55.7-17.7c-13.4 10.3-28.2 18.9-44 25.4l-12.5 57.1c-2 9.1-9 16.3-18.2 17.8c-13.8 2.3-28 3.5-42.5 3.5s-28.7-1.2-42.5-3.5c-9.2-1.5-16.2-8.7-18.2-17.8l-12.5-57.1c-15.8-6.5-30.6-15.1-44-25.4L83.1 425.9c-8.8 2.8-18.6 .3-24.5-6.8c-8.1-9.8-15.5-20.2-22.1-31.2l-4.7-8.1c-6.1-11-11.4-22.4-15.8-34.3c-3.2-8.7-.5-18.4 6.4-24.6l43.3-39.4C64.6 273.1 64 264.6 64 256s.6-17.1 1.7-25.4L22.4 191.2c-6.9-6.2-9.6-15.9-6.4-24.6c4.4-11.9 9.7-23.3 15.8-34.3l4.7-8.1c6.6-11 14-21.4 22.1-31.2c5.9-7.2 15.7-9.6 24.5-6.8l55.7 17.7c13.4-10.3 28.2-18.9 44-25.4l12.5-57.1c2-9.1 9-16.3 18.2-17.8C227.3 1.2 241.5 0 256 0s28.7 1.2 42.5 3.5c9.2 1.5 16.2 8.7 18.2 17.8l12.5 57.1c15.8 6.5 30.6 15.1 44 25.4l55.7-17.7c8.8-2.8 18.6-.3 24.5 6.8c8.1 9.8 15.5 20.2 22.1 31.2l4.7 8.1c6.1 11 11.4 22.4 15.8 34.3zM256 336a80 80 0 1 0 0-160 80 80 0 1 0 0 160z" Fill="#2d2d2d" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>

<VisualBrush x:Key="Icon.Update">
<VisualBrush.Visual>
<Canvas>
Expand Down Expand Up @@ -93,6 +101,14 @@
</VisualBrush.Visual>
</VisualBrush>

<VisualBrush x:Key="Icon.Log">
<VisualBrush.Visual>
<Canvas>
<Path Data="M64 0C28.7 0 0 28.7 0 64V448c0 35.3 28.7 64 64 64H320c35.3 0 64-28.7 64-64V160H256c-17.7 0-32-14.3-32-32V0H64zM256 0V128H384L256 0zM112 256H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16zm0 64H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16zm0 64H272c8.8 0 16 7.2 16 16s-7.2 16-16 16H112c-8.8 0-16-7.2-16-16s7.2-16 16-16z" Fill="#ffffff" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>

<VisualBrush x:Key="Icon.Edit">
<VisualBrush.Visual>
<Canvas>
Expand Down Expand Up @@ -151,6 +167,14 @@
</VisualBrush.Visual>
</VisualBrush>

<VisualBrush x:Key="Icon.Settings.MintyGreen">
<VisualBrush.Visual>
<Canvas>
<Path Data="M495.9 166.6c3.2 8.7 .5 18.4-6.4 24.6l-43.3 39.4c1.1 8.3 1.7 16.8 1.7 25.4s-.6 17.1-1.7 25.4l43.3 39.4c6.9 6.2 9.6 15.9 6.4 24.6c-4.4 11.9-9.7 23.3-15.8 34.3l-4.7 8.1c-6.6 11-14 21.4-22.1 31.2c-5.9 7.2-15.7 9.6-24.5 6.8l-55.7-17.7c-13.4 10.3-28.2 18.9-44 25.4l-12.5 57.1c-2 9.1-9 16.3-18.2 17.8c-13.8 2.3-28 3.5-42.5 3.5s-28.7-1.2-42.5-3.5c-9.2-1.5-16.2-8.7-18.2-17.8l-12.5-57.1c-15.8-6.5-30.6-15.1-44-25.4L83.1 425.9c-8.8 2.8-18.6 .3-24.5-6.8c-8.1-9.8-15.5-20.2-22.1-31.2l-4.7-8.1c-6.1-11-11.4-22.4-15.8-34.3c-3.2-8.7-.5-18.4 6.4-24.6l43.3-39.4C64.6 273.1 64 264.6 64 256s.6-17.1 1.7-25.4L22.4 191.2c-6.9-6.2-9.6-15.9-6.4-24.6c4.4-11.9 9.7-23.3 15.8-34.3l4.7-8.1c6.6-11 14-21.4 22.1-31.2c5.9-7.2 15.7-9.6 24.5-6.8l55.7 17.7c13.4-10.3 28.2-18.9 44-25.4l12.5-57.1c2-9.1 9-16.3 18.2-17.8C227.3 1.2 241.5 0 256 0s28.7 1.2 42.5 3.5c9.2 1.5 16.2 8.7 18.2 17.8l12.5 57.1c15.8 6.5 30.6 15.1 44 25.4l55.7-17.7c8.8-2.8 18.6-.3 24.5 6.8c8.1 9.8 15.5 20.2 22.1 31.2l4.7 8.1c6.1 11 11.4 22.4 15.8 34.3zM256 336a80 80 0 1 0 0-160 80 80 0 1 0 0 160z" Fill="#6dcc8e" />
</Canvas>
</VisualBrush.Visual>
</VisualBrush>

<VisualBrush x:Key="Icon.Update.MintyGreen">
<VisualBrush.Visual>
<Canvas>
Expand Down
49 changes: 39 additions & 10 deletions InvisibleMan-XRay/Core/InvisibleManXRayCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ namespace InvisibleManXRay.Core

public class InvisibleManXRayCore
{
private const string LOCAL_HOST = "127.0.0.1";
private const int DEFAULT_PORT = 10801;
private const int TEST_PORT = 10802;

private Func<Config> getConfig;
private Func<Mode> getMode;
private Func<Protocol> getProtocol;
private Func<LogLevel> getLogLevel;
private Func<string> getLogPath;
private Func<int> getProxyPort;
private Func<int> getTunPort;
private Func<int> getTestPort;
private Func<bool> getUdpEnabled;
private Func<string> getTunIp;
private Func<string> getDns;
private Func<IProxy> getProxy;
Expand All @@ -25,6 +28,13 @@ public class InvisibleManXRayCore
public void Setup(
Func<Config> getConfig,
Func<Mode> getMode,
Func<Protocol> getProtocol,
Func<LogLevel> getLogLevel,
Func<string> getLogPath,
Func<int> getProxyPort,
Func<int> getTunPort,
Func<int> getTestPort,
Func<bool> getUdpEnabled,
Func<string> getTunIp,
Func<string> getDns,
Func<IProxy> getProxy,
Expand All @@ -33,6 +43,13 @@ public void Setup(
{
this.getConfig = getConfig;
this.getMode = getMode;
this.getProtocol = getProtocol;
this.getLogLevel = getLogLevel;
this.getLogPath = getLogPath;
this.getProxyPort = getProxyPort;
this.getTunPort = getTunPort;
this.getTestPort = getTestPort;
this.getUdpEnabled = getUdpEnabled;
this.getTunIp = getTunIp;
this.getDns = getDns;
this.getProxy = getProxy;
Expand Down Expand Up @@ -86,7 +103,13 @@ public void DisableMode()
public void Run(string config)
{
Mode mode = getMode.Invoke();
XRayCoreWrapper.StartServer(config, DEFAULT_PORT, mode == Mode.TUN);
int port = mode == Mode.PROXY ? getProxyPort.Invoke() : getTunPort.Invoke();
LogLevel logLevel = getLogLevel.Invoke();
string logPath = System.IO.Path.GetFullPath($"{getLogPath.Invoke()}/{getConfig.Invoke().Name}");
bool isSocks = getProtocol.Invoke() == Protocol.SOCKS || mode == Mode.TUN;
bool isUdpEnabled = getUdpEnabled.Invoke();

XRayCoreWrapper.StartServer(config, port, logLevel, logPath, isSocks, isUdpEnabled);
}

public void Stop()
Expand All @@ -102,16 +125,21 @@ public void Cancel()

public bool Test(string config)
{
return XRayCoreWrapper.TestConnection(config, TEST_PORT);
return XRayCoreWrapper.TestConnection(config, getTestPort.Invoke());
}

public string GetVersion()
{
return XRayCoreWrapper.GetVersion();
}

private Status EnableProxy()
{
IProxy proxy = getProxy.Invoke();

return proxy.Enable(
ip: LOCAL_HOST,
port: DEFAULT_PORT
ip: Global.LOCAL_HOST,
port: getProxyPort.Invoke()
);
}

Expand All @@ -132,14 +160,15 @@ private Status EnableTunnel()
parent: "outbounds",
jsonString: configStatus.Content.ToString()
);
int port = getTunPort.Invoke();
string address = getTunIp.Invoke();
string dns = getDns.Invoke();

ITunnel tunnel = getTunnel.Invoke();

return tunnel.Enable(
ip: LOCAL_HOST,
port: DEFAULT_PORT,
ip: Global.LOCAL_HOST,
port: port,
address: address,
server: server,
dns: dns
Expand Down
15 changes: 12 additions & 3 deletions InvisibleMan-XRay/Core/XRayCoreWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace InvisibleManXRay.Core
{
using Models;
using Values;

internal class XRayCoreWrapper
Expand Down Expand Up @@ -31,12 +32,12 @@ public static string LoadConfig(string fileFormat, string filePath)
static extern IntPtr LoadConfig(string format, string file);
}

public static void StartServer(string config, int port, bool isSocks)
public static void StartServer(string config, int port, LogLevel logLevel, string logPath, bool isSocks, bool isUdpEnabled)
{
StartServer(config, port, isSocks);
StartServer(config, port, logLevel.ToString(), logPath, isSocks, isUdpEnabled);

[DllImport(Path.XRAY_CORE_DLL, EntryPoint = "StartServer")]
static extern void StartServer(string config, int port, bool isSocks);
static extern void StartServer(string config, int port, string logLevel, string logPath, bool isSocks, bool isUdpEnabled);
}

public static void StopServer()
Expand All @@ -54,5 +55,13 @@ public static bool TestConnection(string config, int port)
[DllImport(Path.XRAY_CORE_DLL, EntryPoint = "TestConnection")]
static extern bool TestConnection(string config, int port);
}

public static string GetVersion()
{
return Marshal.PtrToStringAnsi(GetXRayCoreVersion());

[DllImport(Path.XRAY_CORE_DLL, EntryPoint = "GetXrayCoreVersion")]
static extern IntPtr GetXRayCoreVersion();
}
}
}
48 changes: 48 additions & 0 deletions InvisibleMan-XRay/Factories/WindowFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace InvisibleManXRay.Factories
{
using Core;
using Models;
using Managers;
using Handlers;

Expand Down Expand Up @@ -34,6 +35,7 @@ public MainWindow CreateMainWindow()
checkForUpdate: updateHandler.CheckForUpdate,
checkForBroadcast: broadcastHandler.CheckForBroadcast,
openServerWindow: CreateServerWindow,
openSettingsWindow: CreateSettingsWindow,
openUpdateWindow: CreateUpdateWindow,
openAboutWindow: CreateAboutWindow,
onRunServer: core.Run,
Expand All @@ -48,6 +50,37 @@ public MainWindow CreateMainWindow()
return mainWindow;
}

public SettingsWindow CreateSettingsWindow()
{
SettingsHandler settingsHandler = handlersManager.GetHandler<SettingsHandler>();
NotifyHandler notifyHandler = handlersManager.GetHandler<NotifyHandler>();

SettingsWindow settingsWindow = new SettingsWindow();
settingsWindow.Setup(
getMode: settingsHandler.UserSettings.GetMode,
getProtocol: settingsHandler.UserSettings.GetProtocol,
getUdpEnabled: settingsHandler.UserSettings.GetUdpEnabled,
getRunAtStartupEnabled: settingsHandler.UserSettings.GetRunAtStartupEnabled,
getProxyPort: settingsHandler.UserSettings.GetProxyPort,
getTunPort: settingsHandler.UserSettings.GetTunPort,
getTestPort: settingsHandler.UserSettings.GetTestPort,
getDeviceIp: settingsHandler.UserSettings.GetTunIp,
getDns: settingsHandler.UserSettings.GetDns,
getLogLevel: settingsHandler.UserSettings.GetLogLevel,
getLogPath: settingsHandler.UserSettings.GetLogPath,
onUpdateUserSettings: UpdateUserSettings
);

return settingsWindow;

void UpdateUserSettings(UserSettings userSettings)
{
settingsHandler.UpdateUserSettings(userSettings);
notifyHandler.CheckModeItem(userSettings.GetMode());
GetMainWindow().TryDisableModeAndRerun();
}
}

public UpdateWindow CreateUpdateWindow()
{
UpdateHandler updateHandler = handlersManager.GetHandler<UpdateHandler>();
Expand All @@ -64,16 +97,30 @@ public UpdateWindow CreateUpdateWindow()

public AboutWindow CreateAboutWindow()
{
VersionHandler versionHandler = handlersManager.GetHandler<VersionHandler>();
LinkHandler linkHandler = handlersManager.GetHandler<LinkHandler>();

AboutWindow aboutWindow = new AboutWindow();
aboutWindow.Setup(
getApplicationVersion: GetApplicationVersion,
getXRayCoreVersion: GetXRayCoreVersion,
onEmailClick: linkHandler.OpenEmailLink,
onWebsiteClick: linkHandler.OpenWebsiteLink,
onBugReportingClick: linkHandler.OpenBugReportingLink
);

return aboutWindow;

string GetApplicationVersion()
{
AppVersion appVersion = versionHandler.GetApplicationVersion();
return $"{appVersion.Major}.{appVersion.Feature}.{appVersion.BugFix}";
}

string GetXRayCoreVersion()
{
return core.GetVersion();
}
}

private ServerWindow CreateServerWindow()
Expand All @@ -90,6 +137,7 @@ private ServerWindow CreateServerWindow()
convertConfigLinkToV2Ray: templateHandler.ConverLinkToV2Ray,
loadConfig: core.LoadConfig,
testConnection: core.Test,
getLogPath: settingsHandler.UserSettings.GetLogPath,
onCopyConfig: configHandler.CopyConfig,
onCreateConfig: configHandler.CreateConfig,
onDeleteConfig: configHandler.LoadConfigFiles,
Expand Down
39 changes: 25 additions & 14 deletions InvisibleMan-XRay/Handlers/NotifyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

namespace InvisibleManXRay.Handlers
{
Expand All @@ -19,6 +20,8 @@ public class NotifyHandler : Handler
private Action onProxyModeClick;
private Action onTunnelModeClick;

private Dictionary<Mode, ToolStripMenuItem> modeItems;

public NotifyHandler()
{
InitializeNotifyIcon();
Expand Down Expand Up @@ -46,6 +49,13 @@ Action onTunnelModeClick
AddMenuStrip();
}

public void CheckModeItem(Mode mode)
{
ToolStripMenuItem modeItem = modeItems[mode];
UncheckAllItems();
CheckItem(modeItem);
}

private void InitializeNotifyIcon()
{
notifyIcon = new NotifyIcon();
Expand All @@ -71,12 +81,13 @@ private void HandleNotifyIconClick()
private void AddMenuStrip()
{
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
modeItems = new Dictionary<Mode, ToolStripMenuItem>() {
{ Mode.PROXY, CreateItem("Proxy", onProxyModeClick, true, getMode.Invoke() == Mode.PROXY) },
{ Mode.TUN, CreateItem("TUN (Experimental)", onTunnelModeClick, true, getMode.Invoke() == Mode.TUN) }
};

AddMenuItem("Open Invisible Man XRay", onOpenClick);
AddMenuItem("Mode", delegate { }, new ToolStripMenuItem[] {
CreateItem("Proxy", onProxyModeClick, true, getMode.Invoke() == Mode.PROXY),
CreateItem("TUN (Experimental)", onTunnelModeClick, true, getMode.Invoke() == Mode.TUN)
});
AddMenuItem("Mode", delegate { }, modeItems.Values.ToArray());
AddMenuItem("Check for updates", onUpdateClick);
AddMenuItem("About", onAboutClick);
AddMenuItem("Close", onCloseClick);
Expand Down Expand Up @@ -117,18 +128,18 @@ void HandleToggleClick()
UncheckAllItems();
CheckItem(item);
}
}
}

void UncheckAllItems()
{
foreach(ToolStripMenuItem item in item.GetCurrentParent().Items)
item.Checked = false;
}
private void UncheckAllItems()
{
foreach(ToolStripMenuItem itemElement in modeItems.Values)
itemElement.Checked = false;
}

void CheckItem(ToolStripMenuItem item)
{
item.Checked = true;
}
}
private void CheckItem(ToolStripMenuItem item)
{
item.Checked = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace InvisibleManXRay.Handlers.Settings.Startup
{
public interface IStartupSetting
{
void EnableRunAtStartup();
void DisableRunAtStartup();
}
}
Loading

0 comments on commit 054c0a2

Please sign in to comment.