mirror of https://github.com/quasar/Quasar.git
Improved BuilderProfile
- Ready for implementing multiple profiles
This commit is contained in:
parent
a7b373969c
commit
e18dcc66c7
|
@ -3,6 +3,7 @@ using System.IO;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.XPath;
|
using System.Xml.XPath;
|
||||||
|
using xServer.Core.Helper;
|
||||||
|
|
||||||
namespace xServer.Core.Data
|
namespace xServer.Core.Data
|
||||||
{
|
{
|
||||||
|
@ -10,13 +11,289 @@ namespace xServer.Core.Data
|
||||||
{
|
{
|
||||||
private readonly string _profilePath;
|
private readonly string _profilePath;
|
||||||
|
|
||||||
public BuilderProfile(string profilePath)
|
public string Hosts
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(profilePath)) throw new ArgumentException("Invalid Profile Path");
|
get
|
||||||
_profilePath = Path.Combine(Application.StartupPath, "Profiles\\" + profilePath);
|
{
|
||||||
|
return ReadValueSafe("Hosts");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Hosts", value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ReadValue(string pstrValueToRead)
|
public string Tag
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("Tag", "Office04");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Tag", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Password
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("Password", Settings.Password);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Password", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Delay
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return int.Parse(ReadValueSafe("Delay", "3000"));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Delay", value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Mutex
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("Mutex", FormatHelper.GenerateMutex());
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Mutex", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool InstallClient
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return bool.Parse(ReadValueSafe("InstallClient", "False"));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("InstallClient", value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string InstallName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("InstallName", "Client");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("InstallName", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public short InstallPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return short.Parse(ReadValueSafe("InstallPath", "1"));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("InstallPath", value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string InstallSub
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("InstallSub", "SubDir");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("InstallSub", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HideFile
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return bool.Parse(ReadValueSafe("HideFile", "False"));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("HideFile", value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddStartup
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return bool.Parse(ReadValueSafe("AddStartup", "False"));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("AddStartup", value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string RegistryName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("RegistryName", "xRAT Client Startup");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("RegistryName", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ChangeIcon
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return bool.Parse(ReadValueSafe("ChangeIcon", "False"));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("ChangeIcon", value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ChangeAsmInfo
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return bool.Parse(ReadValueSafe("ChangeAsmInfo", "False"));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("ChangeAsmInfo", value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Keylogger
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return bool.Parse(ReadValueSafe("Keylogger", "False"));
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Keylogger", value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ProductName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("ProductName");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("ProductName", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("Description");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Description", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CompanyName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("CompanyName");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("CompanyName", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Copyright
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("Copyright");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Copyright", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Trademarks
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("Trademarks");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("Trademarks", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string OriginalFilename
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("OriginalFilename");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("OriginalFilename", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ProductVersion
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("ProductVersion");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("ProductVersion", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string FileVersion
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ReadValueSafe("FileVersion");
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
WriteValue("FileVersion", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuilderProfile(string profileName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(profileName)) throw new ArgumentException("Invalid Profile Path");
|
||||||
|
_profilePath = Path.Combine(Application.StartupPath, "Profiles\\" + profileName + ".xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ReadValue(string pstrValueToRead)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -37,13 +314,13 @@ namespace xServer.Core.Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ReadValueSafe(string pstrValueToRead, string defaultValue = "")
|
private string ReadValueSafe(string pstrValueToRead, string defaultValue = "")
|
||||||
{
|
{
|
||||||
string value = ReadValue(pstrValueToRead);
|
string value = ReadValue(pstrValueToRead);
|
||||||
return (!string.IsNullOrEmpty(value)) ? value : defaultValue;
|
return (!string.IsNullOrEmpty(value)) ? value : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WriteValue(string pstrValueToRead, string pstrValueToWrite)
|
private void WriteValue(string pstrValueToRead, string pstrValueToWrite)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -73,15 +350,13 @@ namespace xServer.Core.Data
|
||||||
oldNode = doc.SelectSingleNode("settings");
|
oldNode = doc.SelectSingleNode("settings");
|
||||||
oldNode.AppendChild(doc.CreateElement(pstrValueToRead)).InnerText = pstrValueToWrite;
|
oldNode.AppendChild(doc.CreateElement(pstrValueToRead)).InnerText = pstrValueToWrite;
|
||||||
doc.Save(_profilePath);
|
doc.Save(_profilePath);
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
oldNode.InnerText = pstrValueToWrite;
|
oldNode.InnerText = pstrValueToWrite;
|
||||||
doc.Save(_profilePath);
|
doc.Save(_profilePath);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ using System.Windows.Forms;
|
||||||
using xServer.Core.Build;
|
using xServer.Core.Build;
|
||||||
using xServer.Core.Data;
|
using xServer.Core.Data;
|
||||||
using xServer.Core.Helper;
|
using xServer.Core.Helper;
|
||||||
using xServer.Core.Utilities;
|
|
||||||
|
|
||||||
namespace xServer.Forms
|
namespace xServer.Forms
|
||||||
{
|
{
|
||||||
|
@ -24,62 +23,64 @@ namespace xServer.Forms
|
||||||
|
|
||||||
private void LoadProfile(string profilename)
|
private void LoadProfile(string profilename)
|
||||||
{
|
{
|
||||||
var profile = new BuilderProfile(profilename + ".xml");
|
var profile = new BuilderProfile(profilename);
|
||||||
var rawHosts = profile.ReadValueSafe("Hosts");
|
|
||||||
foreach (var host in HostHelper.GetHostsList(rawHosts))
|
foreach (var host in HostHelper.GetHostsList(profile.Hosts))
|
||||||
_hosts.Add(host);
|
_hosts.Add(host);
|
||||||
lstHosts.DataSource = new BindingSource(_hosts, null);
|
lstHosts.DataSource = new BindingSource(_hosts, null);
|
||||||
txtTag.Text = profile.ReadValueSafe("Tag", "Office04");
|
|
||||||
txtPassword.Text = profile.ReadValueSafe("Password", Settings.Password);
|
txtTag.Text = profile.Tag;
|
||||||
txtDelay.Text = profile.ReadValueSafe("Delay", "5000");
|
txtPassword.Text = profile.Password;
|
||||||
txtMutex.Text = profile.ReadValueSafe("Mutex", FormatHelper.GenerateMutex());
|
txtDelay.Text = profile.Delay.ToString();
|
||||||
chkInstall.Checked = bool.Parse(profile.ReadValueSafe("InstallClient", "False"));
|
txtMutex.Text = profile.Mutex;
|
||||||
txtInstallname.Text = profile.ReadValueSafe("InstallName", "Client");
|
chkInstall.Checked = profile.InstallClient;
|
||||||
GetInstallPath(int.Parse(profile.ReadValueSafe("InstallPath", "1"))).Checked = true;
|
txtInstallname.Text = profile.InstallName;
|
||||||
txtInstallsub.Text = profile.ReadValueSafe("InstallSub", "SubDir");
|
GetInstallPath(profile.InstallPath).Checked = true;
|
||||||
chkHide.Checked = bool.Parse(profile.ReadValueSafe("HideFile", "False"));
|
txtInstallsub.Text = profile.InstallSub;
|
||||||
chkStartup.Checked = bool.Parse(profile.ReadValueSafe("AddStartup", "False"));
|
chkHide.Checked = profile.HideFile;
|
||||||
txtRegistryKeyName.Text = profile.ReadValueSafe("RegistryName", "Client Startup");
|
chkStartup.Checked = profile.AddStartup;
|
||||||
chkIconChange.Checked = bool.Parse(profile.ReadValueSafe("ChangeIcon", "False"));
|
txtRegistryKeyName.Text = profile.RegistryName;
|
||||||
chkChangeAsmInfo.Checked = bool.Parse(profile.ReadValueSafe("ChangeAsmInfo", "False"));
|
chkIconChange.Checked = profile.ChangeIcon;
|
||||||
chkKeylogger.Checked = bool.Parse(profile.ReadValueSafe("Keylogger", "False"));
|
chkChangeAsmInfo.Checked = profile.ChangeAsmInfo;
|
||||||
txtProductName.Text = profile.ReadValueSafe("ProductName");
|
chkKeylogger.Checked = profile.Keylogger;
|
||||||
txtDescription.Text = profile.ReadValueSafe("Description");
|
txtProductName.Text = profile.ProductName;
|
||||||
txtCompanyName.Text = profile.ReadValueSafe("CompanyName");
|
txtDescription.Text = profile.Description;
|
||||||
txtCopyright.Text = profile.ReadValueSafe("Copyright");
|
txtCompanyName.Text = profile.CompanyName;
|
||||||
txtTrademarks.Text = profile.ReadValueSafe("Trademarks");
|
txtCopyright.Text = profile.Copyright;
|
||||||
txtOriginalFilename.Text = profile.ReadValueSafe("OriginalFilename");
|
txtTrademarks.Text = profile.Trademarks;
|
||||||
txtProductVersion.Text = profile.ReadValueSafe("ProductVersion");
|
txtOriginalFilename.Text = profile.OriginalFilename;
|
||||||
txtFileVersion.Text = profile.ReadValueSafe("FileVersion");
|
txtProductVersion.Text = profile.ProductVersion;
|
||||||
|
txtFileVersion.Text = profile.FileVersion;
|
||||||
|
|
||||||
_profileLoaded = true;
|
_profileLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveProfile(string profilename)
|
private void SaveProfile(string profilename)
|
||||||
{
|
{
|
||||||
var profile = new BuilderProfile(profilename + ".xml");
|
var profile = new BuilderProfile(profilename);
|
||||||
profile.WriteValue("Tag", txtTag.Text);
|
|
||||||
profile.WriteValue("Hosts", HostHelper.GetRawHosts(_hosts));
|
profile.Tag = txtTag.Text;
|
||||||
profile.WriteValue("Password", txtPassword.Text);
|
profile.Hosts = HostHelper.GetRawHosts(_hosts);
|
||||||
profile.WriteValue("Delay", txtDelay.Text);
|
profile.Password = txtPassword.Text;
|
||||||
profile.WriteValue("Mutex", txtMutex.Text);
|
profile.Delay = int.Parse(txtDelay.Text);
|
||||||
profile.WriteValue("InstallClient", chkInstall.Checked.ToString());
|
profile.Mutex = txtMutex.Text;
|
||||||
profile.WriteValue("InstallName", txtInstallname.Text);
|
profile.InstallClient = chkInstall.Checked;
|
||||||
profile.WriteValue("InstallPath", GetInstallPath().ToString());
|
profile.InstallName = txtInstallname.Text;
|
||||||
profile.WriteValue("InstallSub", txtInstallsub.Text);
|
profile.InstallPath = GetInstallPath();
|
||||||
profile.WriteValue("HideFile", chkHide.Checked.ToString());
|
profile.HideFile = chkHide.Checked;
|
||||||
profile.WriteValue("AddStartup", chkStartup.Checked.ToString());
|
profile.AddStartup = chkStartup.Checked;
|
||||||
profile.WriteValue("RegistryName", txtRegistryKeyName.Text);
|
profile.RegistryName = txtRegistryKeyName.Text;
|
||||||
profile.WriteValue("ChangeIcon", chkIconChange.Checked.ToString());
|
profile.ChangeIcon = chkIconChange.Checked;
|
||||||
profile.WriteValue("ChangeAsmInfo", chkChangeAsmInfo.Checked.ToString());
|
profile.ChangeAsmInfo = chkChangeAsmInfo.Checked;
|
||||||
profile.WriteValue("Keylogger", chkKeylogger.Checked.ToString());
|
profile.Keylogger = chkKeylogger.Checked;
|
||||||
profile.WriteValue("ProductName", txtProductName.Text);
|
profile.ProductName = txtProductName.Text;
|
||||||
profile.WriteValue("Description", txtDescription.Text);
|
profile.Description = txtDescription.Text;
|
||||||
profile.WriteValue("CompanyName", txtCompanyName.Text);
|
profile.CompanyName = txtCompanyName.Text;
|
||||||
profile.WriteValue("Copyright", txtCopyright.Text);
|
profile.Copyright = txtCopyright.Text;
|
||||||
profile.WriteValue("Trademarks", txtTrademarks.Text);
|
profile.Trademarks = txtTrademarks.Text;
|
||||||
profile.WriteValue("OriginalFilename", txtOriginalFilename.Text);
|
profile.OriginalFilename = txtOriginalFilename.Text;
|
||||||
profile.WriteValue("ProductVersion", txtProductVersion.Text);
|
profile.ProductVersion = txtProductVersion.Text;
|
||||||
profile.WriteValue("FileVersion", txtFileVersion.Text);
|
profile.FileVersion = txtFileVersion.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FrmBuilder_Load(object sender, EventArgs e)
|
private void FrmBuilder_Load(object sender, EventArgs e)
|
||||||
|
@ -96,7 +97,7 @@ namespace xServer.Forms
|
||||||
private void FrmBuilder_FormClosing(object sender, FormClosingEventArgs e)
|
private void FrmBuilder_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
if (_changed &&
|
if (_changed &&
|
||||||
MessageBox.Show("Do you want to save your current settings?", "Save your settings?",
|
MessageBox.Show("Do you want to save your current settings?", "Changes detected",
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
SaveProfile("Default");
|
SaveProfile("Default");
|
||||||
|
@ -316,7 +317,7 @@ namespace xServer.Forms
|
||||||
this.Invoke((MethodInvoker)delegate { txtExamplePath.Text = path + ".exe"; });
|
this.Invoke((MethodInvoker)delegate { txtExamplePath.Text = path + ".exe"; });
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetInstallPath()
|
private short GetInstallPath()
|
||||||
{
|
{
|
||||||
if (rbAppdata.Checked) return 1;
|
if (rbAppdata.Checked) return 1;
|
||||||
if (rbProgramFiles.Checked) return 2;
|
if (rbProgramFiles.Checked) return 2;
|
||||||
|
@ -324,7 +325,7 @@ namespace xServer.Forms
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RadioButton GetInstallPath(int installPath)
|
private RadioButton GetInstallPath(short installPath)
|
||||||
{
|
{
|
||||||
switch (installPath)
|
switch (installPath)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue