From 0b9ecf1e3ccd09c06b41a2dcb4022a0037b19f6c Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Tue, 21 Jun 2022 19:20:28 +0200 Subject: [PATCH] Working agnostics --- __main__.py | 32 ------------ modules/agnostic_paths.py | 100 +++++++++++++++++++++++++++++++++++++ modules/spidey_detector.py | 4 +- spideyDetector.py | 46 +++++++++++++++++ 4 files changed, 148 insertions(+), 34 deletions(-) delete mode 100644 __main__.py create mode 100644 modules/agnostic_paths.py create mode 100644 spideyDetector.py diff --git a/__main__.py b/__main__.py deleted file mode 100644 index 86b897a..0000000 --- a/__main__.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/python3 - -""" Main program """ - -from modules import spidey_detector -import argparse -import sys - - -def parse(_args): - parser = argparse.ArgumentParser( - prog="Spidey Detector", - description='Checks for corrupt discord install' - ) - parser.add_argument('ptb', help="Set to True if you're using the PTB") - return parser.parse_args(_args) - - -if __name__ == "__main__": - args = parse(sys.argv) - try: - spd = spidey_detector.run_check(args) - except FileNotFoundError as er: - print(er) - sys.exit(1) - except OSError as er: - print(er.strerror) - sys.exit(1) - - if spd == 0: - print("SpideyDetector could not find anything wrong with your discord install!") - sys.exit(spd) diff --git a/modules/agnostic_paths.py b/modules/agnostic_paths.py new file mode 100644 index 0000000..6749070 --- /dev/null +++ b/modules/agnostic_paths.py @@ -0,0 +1,100 @@ +""" +The agnostic path handler, gives all methods to access all paths of the discord client, regardless of the os. +""" +import os +import re +import sys + + +class AgnosticPaths: + def __init__(self, ptb): + self.ptb = ptb + self.os = self.get_os() + self.main_path = self.get_path() + self.versions = self.get_versions() + self.latest_version = self.get_latest_version() + + def get_os(self): + platform = sys.platform + if platform.startswith('win'): + self.os = 'windows' + elif platform.startswith('linux'): + self.os = 'linux' + elif platform.startswith('darwin'): + self.os = 'mac' + else: + raise OSError("This script can only check for Spideys on Windows, Linux and Mac.") + if self.os == 'linux' or self.os == 'mac': + raise OSError("This script can only check for Spideys on Windows for now.") + return self.os + + def get_path(self): + if self.os == 'windows': + return os.path.join(os.path.expanduser('~'), "AppData", "Local", f"Discord{self.ptb}") + elif self.os == 'linux': + return "" + elif self.os == 'mac': + return "" + + def get_versions(self): + """ + Looks for the version file in the discord folder + """ + versions = [] + for element in os.listdir(self.main_path): + if re.match(r"app-[\d\.]+", element): + versions.append(element) + if not versions: + raise FileNotFoundError("Could not find discord version folder.") + versions.sort() + return versions + + def get_latest_version(self): + return self.versions[-1] + + def list(self, *args): + """ + Lists all files in the given path. + :param args: The path + """ + return os.listdir(self(*args)) + + def list_dir_files(self, *args): + """ + Lists all files and directories in the given path. + :param args: The path + """ + all_files = self.list(*args) + _path = self(*args) + files = [] + dirs = [] + for element in all_files: + if os.path.isdir(os.path.join(_path, element)): + dirs.append(element) + else: + files.append(element) + return dirs, files + + def __call__(self, *args, version=None): + if version is None: + _path = os.path.join(self.main_path, *args) + elif version == "LATEST": + _path = os.path.join(self.main_path, self.latest_version, *args) + else: + _path = os.path.join(self.main_path, version, *args) + if not os.path.exists(_path): + raise FileNotFoundError(f"Could not find {_path}") + return _path + + def __repr__(self): + return f"AgnosticPaths(ptb={self.ptb}, os={self.os}, main_path={self.main_path}, version={self.latest_version})" + + def __str__(self): + return self.main_path + + +if __name__ == '__main__': + path = AgnosticPaths("") + print(path) + print(path.list_dir_files()) + print(path.list()) \ No newline at end of file diff --git a/modules/spidey_detector.py b/modules/spidey_detector.py index 3c73fbd..ae7d024 100644 --- a/modules/spidey_detector.py +++ b/modules/spidey_detector.py @@ -4,12 +4,12 @@ import sys class SpideyDetector: - def __init__(self, ptb=False): + def __init__(self, args): """ :param ptb: Whether you're using discord Public Test Version :type ptb: bool """ - if ptb: + if args.ptb: self.ptb = "PTB" else: self.ptb = "" diff --git a/spideyDetector.py b/spideyDetector.py new file mode 100644 index 0000000..f678e02 --- /dev/null +++ b/spideyDetector.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 + +""" Main program """ + +from modules import spidey_detector +import argparse +import sys + + +def parse(_args): + parser = argparse.ArgumentParser( + prog="Spidey Detector", + description='Checks for corrupt discord install' + ) + parser.add_argument('--ptb', action='store_true', help='Use Public Test Version') + parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0') + parser.add_argument('-d', '--debug', action='store_true', help='Debug mode') + parser.add_argument('-s', '--silent', action='store_true', help='Silent mode') + parser.add_argument('--line-count', action='store_true', help='Test all known files for line count') + parser.add_argument('--file-count', action='store_true', help="Test the number of files in the discord folder") + parser.add_argument('--file-size', action='store_true', help="Test the size of the files in the discord folder") + parser.add_argument('--file-hash', action='store_true', help="Test the hash of the files in the discord folder") + parser.add_argument('--file-path', action='store_true', help="Test the path of the files in the discord folder") + parser.add_argument('--file-name', action='store_true', help="Test the name of the files in the discord folder") + parser.add_argument('--file-extension', action='store_true', help="Test the extension of the files in the discord folder") + parser.add_argument('--file-date', action='store_true', help="Test the date of the files in the discord folder") + parser.add_argument('--analyze', action='store_true', help="Analyze the files in the discord folder for known js obfuscators") + parser.add_argument('--all', action='store_true', help="Run all tests in parallel, and wait for a potential interupt") + parser.add_argument('--launch', action='store_true', help="Launch the discord client after the tests are done") + return parser.parse_args(_args) + + +if __name__ == "__main__": + args = parse(sys.argv[1:]) + try: + spd = spidey_detector.run_check(args) + except FileNotFoundError as er: + print(er) + sys.exit(1) + except OSError as er: + print(er.strerror) + sys.exit(1) + + if spd == 0: + print("SpideyDetector could not find anything wrong with your discord install!") + sys.exit(spd)