From 1f193055f63d547d094383749e582d9fdf99d1a0 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Tue, 21 Jun 2022 20:04:58 +0200 Subject: [PATCH 01/11] Draft for path and separation --- modules/agnostic_paths.py | 2 +- modules/spidey_detector.py | 31 +++++++++++++++++++------------ spideyDetector.py | 8 +++++--- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/modules/agnostic_paths.py b/modules/agnostic_paths.py index 6749070..00894be 100644 --- a/modules/agnostic_paths.py +++ b/modules/agnostic_paths.py @@ -7,7 +7,7 @@ import sys class AgnosticPaths: - def __init__(self, ptb): + def __init__(self, ptb, forced_path=None): self.ptb = ptb self.os = self.get_os() self.main_path = self.get_path() diff --git a/modules/spidey_detector.py b/modules/spidey_detector.py index ae7d024..11bf972 100644 --- a/modules/spidey_detector.py +++ b/modules/spidey_detector.py @@ -4,19 +4,26 @@ import sys class SpideyDetector: - def __init__(self, args): + def __init__(self, args, agnpath): """ - :param ptb: Whether you're using discord Public Test Version - :type ptb: bool + Main spidey runner + :param args: List of arguments + :type args: argparse.Namespace + :param agnpath: The path to the discord folder + :type agnpath: agnostic_path.AgnosticPath """ - if args.ptb: - self.ptb = "PTB" - else: - self.ptb = "" - self.is_windows = self.check_os() + self.ptb = args.ptb + self.agnostic_path = agnpath + self.os_name = agnpath.os + self.main_path = agnpath.main_path + self.latest_version = agnpath.latest_version + # self.is_windows = self.check_os() self.is_infected = False - self.paths = self.check_paths(*self.get_path()) - self.spidey_check() + self.detections = 0 + self.test_run = {} + + # self.paths = self.check_paths(*self.get_path()) + # self.spidey_check() def check_os(self): # noqa if not sys.platform.startswith('win'): @@ -90,8 +97,8 @@ class SpideyDetector: return self.is_infected -def run_check(ptb): - spd = SpideyDetector(ptb) +def run_check(args, agnpath): + spd = SpideyDetector(args, agnpath) if not spd.is_infected: return 0 else: diff --git a/spideyDetector.py b/spideyDetector.py index f678e02..8ccab05 100644 --- a/spideyDetector.py +++ b/spideyDetector.py @@ -2,7 +2,7 @@ """ Main program """ -from modules import spidey_detector +from modules import spidey_detector, agnostic_paths import argparse import sys @@ -12,7 +12,7 @@ def parse(_args): prog="Spidey Detector", description='Checks for corrupt discord install' ) - parser.add_argument('--ptb', action='store_true', help='Use Public Test Version') + parser.add_argument('--ptb', action='store_const', const="PTB", default="", 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') @@ -32,8 +32,10 @@ def parse(_args): if __name__ == "__main__": args = parse(sys.argv[1:]) + agnostic_path = agnostic_paths.AgnosticPaths(ptb=args.ptb) try: - spd = spidey_detector.run_check(args) + spd = spidey_detector.run_check(args, agnostic_path) + except FileNotFoundError as er: print(er) sys.exit(1) From 3602d1303e7462e7c1dd7458c0b2e8872d65963a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20CAMPO?= Date: Tue, 21 Jun 2022 20:23:49 +0200 Subject: [PATCH 02/11] First try at detecting list of files in linux os --- modules/agnostic_paths.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/agnostic_paths.py b/modules/agnostic_paths.py index 6749070..d01e48e 100644 --- a/modules/agnostic_paths.py +++ b/modules/agnostic_paths.py @@ -11,8 +11,7 @@ class AgnosticPaths: 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() + self.versions = self.get_version() def get_os(self): platform = sys.platform @@ -24,33 +23,39 @@ class AgnosticPaths: 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 "" + return os.path.join("/","opt","discord") + #return os.path.join("usr","share","discord") elif self.os == 'mac': return "" + raise OSError("Cannot detect discord PATH") - def get_versions(self): + def get_version(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 + if self.os == 'windows': + 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[-1] + if self.os == 'linux': + from json import load + with open(os.path.join(self.main_path,'resources','build_info.json')) as versionFile: + versions = load(versionFile) + return versions['version'] + + - def get_latest_version(self): - return self.versions[-1] def list(self, *args): """ @@ -96,5 +101,6 @@ class AgnosticPaths: if __name__ == '__main__': path = AgnosticPaths("") print(path) + print(path.versions) print(path.list_dir_files()) - print(path.list()) \ No newline at end of file + print(path.list()) From 4311692cb41ed80b565acaa3774dd7c245643d65 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Tue, 21 Jun 2022 20:38:52 +0200 Subject: [PATCH 03/11] Updated path on windows --- modules/agnostic_paths.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/modules/agnostic_paths.py b/modules/agnostic_paths.py index 12fc121..cb4d518 100644 --- a/modules/agnostic_paths.py +++ b/modules/agnostic_paths.py @@ -11,7 +11,8 @@ class AgnosticPaths: self.ptb = ptb self.os = self.get_os() self.main_path = self.get_path() - self.versions = self.get_version() + self.version = self.get_version() + self.update_path() def get_os(self): platform = sys.platform @@ -42,20 +43,23 @@ class AgnosticPaths: versions = [] if self.os == 'windows': for element in os.listdir(self.main_path): - if re.match(r"app-[\d\.]+", element): + 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[-1] - if self.os == 'linux': + elif self.os == 'linux': from json import load with open(os.path.join(self.main_path,'resources','build_info.json')) as versionFile: versions = load(versionFile) return versions['version'] + else: + raise OSError("Can't find for version on your OS.") - - + def update_path(self): + if self.os == 'windows': + self.main_path = os.path.join(self.main_path, self.version) def list(self, *args): """ @@ -80,19 +84,14 @@ class AgnosticPaths: 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) + def __call__(self, *args): + _path = os.path.join(self.main_path, *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})" + return f"AgnosticPaths(ptb={self.ptb}, os={self.os}, main_path={self.main_path}, version={self.version})" def __str__(self): return self.main_path @@ -101,6 +100,6 @@ class AgnosticPaths: if __name__ == '__main__': path = AgnosticPaths("") print(path) - print(path.versions) + print(path.version) print(path.list_dir_files()) print(path.list()) From e799252122d85c94007cd32867f58ad90d466c72 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Tue, 21 Jun 2022 20:27:09 +0200 Subject: [PATCH 04/11] Started the module loading --- modules/spidey_detector.py | 21 ++++++++++++++++++--- modules/spidey_test.py | 16 ++++++++++++++++ spideyDetector.py | 1 + 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 modules/spidey_test.py diff --git a/modules/spidey_detector.py b/modules/spidey_detector.py index 11bf972..fb1d62c 100644 --- a/modules/spidey_detector.py +++ b/modules/spidey_detector.py @@ -2,6 +2,10 @@ import os import re import sys +_TEST_MODULES = { # argparse argument : [module_name, class_name] + "spidey": ["spidey_test", "spidey"], +} + class SpideyDetector: def __init__(self, args, agnpath): @@ -18,13 +22,24 @@ class SpideyDetector: self.main_path = agnpath.main_path self.latest_version = agnpath.latest_version # self.is_windows = self.check_os() - self.is_infected = False + self.is_infected = 0 self.detections = 0 self.test_run = {} - # self.paths = self.check_paths(*self.get_path()) - # self.spidey_check() + self.loaded_modules = self.get_module_list() + self.spidey_check() + def get_module_list(self): + """ + Gets the list of modules to be loaded (in accordance to the config) + :return: List of modules + :rtype: list + """ + modules = [] + for module in _TEST_MODULES: + + if module[0] in self.loaded_modules: + modules.append(module[1]) def check_os(self): # noqa if not sys.platform.startswith('win'): raise OSError("This script can only check for Spideys on Windows.") diff --git a/modules/spidey_test.py b/modules/spidey_test.py new file mode 100644 index 0000000..7353fa9 --- /dev/null +++ b/modules/spidey_test.py @@ -0,0 +1,16 @@ +class SpideyTest: + def __init__(self, args, agnpath, test_data): + """ + Simple test runner, for testing the detection of Spidey viruses. + :param args: List of arguments + :type args: argparse.Namespace + :param agnpath: The path to the discord folder + :type agnpath: agnostic_path.AgnosticPath + :param test_data: The data to be tested + :type test_data: str + """ + self.ptb = args.ptb + self.agnostic_path = agnpath + self.os_name = agnpath.os + self.main_path = agnpath.main_path + self.test_data = test_data diff --git a/spideyDetector.py b/spideyDetector.py index 8ccab05..8dc783a 100644 --- a/spideyDetector.py +++ b/spideyDetector.py @@ -16,6 +16,7 @@ def parse(_args): 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('--spidey', action='store_true', help='Runs the spidey test') 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") From d93111a152821c96498bea8b47095f7f832d8806 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Tue, 21 Jun 2022 21:53:07 +0200 Subject: [PATCH 05/11] Added test module loading --- modules/spidey_detector.py | 124 ------------------------------------- modules/spidey_test.py | 44 +++++++++++++ modules/test_interface.py | 77 +++++++++++++++++++++++ spideyDetector.py | 4 +- 4 files changed, 123 insertions(+), 126 deletions(-) delete mode 100644 modules/spidey_detector.py create mode 100644 modules/test_interface.py diff --git a/modules/spidey_detector.py b/modules/spidey_detector.py deleted file mode 100644 index fb1d62c..0000000 --- a/modules/spidey_detector.py +++ /dev/null @@ -1,124 +0,0 @@ -import os -import re -import sys - -_TEST_MODULES = { # argparse argument : [module_name, class_name] - "spidey": ["spidey_test", "spidey"], -} - - -class SpideyDetector: - def __init__(self, args, agnpath): - """ - Main spidey runner - :param args: List of arguments - :type args: argparse.Namespace - :param agnpath: The path to the discord folder - :type agnpath: agnostic_path.AgnosticPath - """ - self.ptb = args.ptb - self.agnostic_path = agnpath - self.os_name = agnpath.os - self.main_path = agnpath.main_path - self.latest_version = agnpath.latest_version - # self.is_windows = self.check_os() - self.is_infected = 0 - self.detections = 0 - self.test_run = {} - - self.loaded_modules = self.get_module_list() - self.spidey_check() - - def get_module_list(self): - """ - Gets the list of modules to be loaded (in accordance to the config) - :return: List of modules - :rtype: list - """ - modules = [] - for module in _TEST_MODULES: - - if module[0] in self.loaded_modules: - modules.append(module[1]) - def check_os(self): # noqa - if not sys.platform.startswith('win'): - raise OSError("This script can only check for Spideys on Windows.") - return True - - def get_path(self): - """ - Gets the path of the two folders we need to check - :return: Two paths. - :rtype: str - """ - pre_version_path = os.path.join(os.path.expanduser('~'), "AppData", "Local", f"Discord{self.ptb}") - version = self.get_version(pre_version_path) - discord_modules = os.path.join(pre_version_path, version, - "modules", "discord_modules-1", "discord_modules") - discord_desktop_core = os.path.join(pre_version_path, version, - "modules", "discord_desktop_core-1", "discord_desktop_core") - return discord_modules, discord_desktop_core - - def get_version(self, pre_version_path): # noqa I swear this one is not static :( - """ - Looks for the version file in the discord folder - :param pre_version_path: the /discord/ path. - :type pre_version_path: str - :return: The folder in /discord/ that's only made of ints and dots. - :rtype: str - """ - version = None - for element in os.listdir(pre_version_path): - if re.match(r"app-[\d\.]+", element): - version = element - if not version: - raise FileNotFoundError("Could not find discord version folder.") - return version - - def check_paths(self, discord_modules, discord_desktop_core): # noqa - if not os.path.isfile(os.path.join(discord_modules, 'index.js')): - raise FileNotFoundError(f"Could not find index.js in {discord_modules}") - if not os.path.isfile(os.path.join(discord_desktop_core, 'index.js')): - raise FileNotFoundError(f"Could not find index.js in {discord_desktop_core}") - return discord_modules, discord_desktop_core - - def spidey_check(self): - """ - Counts the number of lines in both index.js files. If it's more than one, it's almost certain your discord - is corrupted. - :return: Whether any of the index.js is more than one line - :rtype: bool - """ - lines = 0 - with open(os.path.join(self.paths[0], "index.js")) as f: - for line in f: - lines = lines + 1 - if lines > 1: - self.is_infected = True - - lines = 0 - with open(os.path.join(self.paths[1], "index.js")) as f: - for line in f: - lines = lines + 1 - if lines > 1: - self.is_infected = True - - if self.is_infected: - print("\n!!! WARNING !!!\n" - "Unless you've installed a plugin you really trust, chances are your discord install " - "is corrupted. We suggest uninstalling discord and deleting all its files before reinstalling.\n" - "If you've recently downloaded a .exe directly sent from someone, " - "do also consider a clean windows reinstall.") - return self.is_infected - - -def run_check(args, agnpath): - spd = SpideyDetector(args, agnpath) - if not spd.is_infected: - return 0 - else: - return 1 - - -if __name__ == "__main__": - pass diff --git a/modules/spidey_test.py b/modules/spidey_test.py index 7353fa9..43d68cb 100644 --- a/modules/spidey_test.py +++ b/modules/spidey_test.py @@ -1,3 +1,6 @@ +import os + + class SpideyTest: def __init__(self, args, agnpath, test_data): """ @@ -14,3 +17,44 @@ class SpideyTest: self.os_name = agnpath.os self.main_path = agnpath.main_path self.test_data = test_data + + def run_test(self): + """ + Counts the number of lines in both index.js files. If it's more than one, it's almost certain your discord + is corrupted. + :return: Whether any of the index.js is more than one line + :rtype: bool + """ + paths = self.get_path() + self.is_infected = False + lines = 0 + with open(os.path.join(paths[0], "index.js")) as f: + for line in f: + lines += 1 + if lines > 1: + self.is_infected = True + + lines = 0 + with open(os.path.join(paths[1], "index.js")) as f: + for line in f: + lines += 1 + if lines > 1: + self.is_infected = True + + if self.is_infected: + print("\n!!! WARNING !!!\n" + "Unless you've installed a plugin you really trust, chances are your discord install " + "is corrupted. We suggest uninstalling discord and deleting all its files before reinstalling.\n" + "If you've recently downloaded a .exe directly sent from someone, " + "do also consider a clean windows reinstall.") + return self.is_infected + + def get_path(self): + """ + Gets the path of the two folders we need to check + :return: Two paths. + :rtype: str + """ + discord_modules = self.agnostic_path("modules", "discord_modules-1", "discord_modules") + discord_desktop_core = self.agnostic_path("modules", "discord_desktop_core-1", "discord_desktop_core") + return discord_modules, discord_desktop_core diff --git a/modules/test_interface.py b/modules/test_interface.py new file mode 100644 index 0000000..0a58a33 --- /dev/null +++ b/modules/test_interface.py @@ -0,0 +1,77 @@ +import os +import re +import sys +import importlib + +_TEST_MODULES = { # argparse argument : [module_name, class_name] + "spidey": ["spidey_test", "SpideyTest"], +} + + +class SpideyDetector: + def __init__(self, args, agnpath): + """ + Main spidey runner + :param args: List of arguments + :type args: argparse.Namespace + :param agnpath: The path to the discord folder + :type agnpath: agnostic_path.AgnosticPath + """ + self.ptb = args.ptb + self.args = args + self.agnostic_path = agnpath + self.os_name = agnpath.os + self.main_path = agnpath.main_path + self.version = agnpath.version + # self.is_windows = self.check_os() + self.is_infected = 0 + self.detections = 0 + self.test_run = {} + + self.loaded_test_modules = {} + self.loaded_test_classes = {} + self.update_module_list() + self.exec_all_tests() + + def update_module_list(self): + """ + Gets the list of modules to be loaded (in accordance to the config) + :return: List of modules + :rtype: list + """ + modules = {} + classes = {} + try: + for module_name, values in _TEST_MODULES.items(): + print(values[0]) + if self.args.__getattribute__(module_name): + modules[values[0]] = importlib.import_module(f"modules.{values[0]}") + classes[values[0]] = getattr(modules[values[0]], values[1]) + + except AttributeError: + print(f"The module {module_name} was not loaded because it was not specified in the config.") + + self.loaded_test_modules.update(modules) + self.loaded_test_classes.update(classes) + + def exec_all_tests(self): + """ + Executes all the tests + :return: + """ + for module_name, test_class in self.loaded_test_classes.items(): + tc = test_class(self.args, self.agnostic_path, None) + tc.run_test() + print(tc) + + +def run_check(args, agnpath): + spd = SpideyDetector(args, agnpath) + if not spd.is_infected: + return 0 + else: + return 1 + + +if __name__ == "__main__": + pass \ No newline at end of file diff --git a/spideyDetector.py b/spideyDetector.py index 8dc783a..72198a1 100644 --- a/spideyDetector.py +++ b/spideyDetector.py @@ -2,7 +2,7 @@ """ Main program """ -from modules import spidey_detector, agnostic_paths +from modules import test_interface, agnostic_paths import argparse import sys @@ -35,7 +35,7 @@ if __name__ == "__main__": args = parse(sys.argv[1:]) agnostic_path = agnostic_paths.AgnosticPaths(ptb=args.ptb) try: - spd = spidey_detector.run_check(args, agnostic_path) + spd = test_interface.run_check(args, agnostic_path) except FileNotFoundError as er: print(er) From 4ed63c1e4618f5af136f62437babe300b73475c1 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 22 Jun 2022 08:49:15 +0200 Subject: [PATCH 06/11] Update agnostic_paths.py --- modules/agnostic_paths.py | 75 ++++++++++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/modules/agnostic_paths.py b/modules/agnostic_paths.py index cb4d518..1caa56e 100644 --- a/modules/agnostic_paths.py +++ b/modules/agnostic_paths.py @@ -7,14 +7,32 @@ import sys class AgnosticPaths: + """ + An agnostic path object, containing all methods to access the files and folders in a standard discord install + """ + def __init__(self, ptb, forced_path=None): + """ + :param ptb: Whether the discord is a public beta install (ptb="PTB") or not (ptb="") + :type ptb: str + :param forced_path: An alternative discord install path, usefull to test the script on a non standard install + :type forced_path: str + """ self.ptb = ptb self.os = self.get_os() - self.main_path = self.get_path() + self.main_path = self._get_path() self.version = self.get_version() - self.update_path() + self._update_path() def get_os(self): + """ + Get the os string in a short, spydey-detector way. + For now only windows and linux are supported, note that due to the nature of linux builds, strings will likely become + linux-arch-deb, linux-arch-snap etc... + :return: ("windows", "linux", "mac") + :rtype: str + """ + platform = sys.platform if platform.startswith('win'): self.os = 'windows' @@ -26,7 +44,13 @@ class AgnosticPaths: raise OSError("This script can only check for Spideys on Windows, Linux and Mac.") return self.os - def get_path(self): + def _get_path(self): + """ + Return the base path of the install, note that the self.main_path is not returned, + and this method is meant to be used at init only + :return: Base path of the install (minus the version on windows) + :rtype: str + """ if self.os == 'windows': return os.path.join(os.path.expanduser('~'), "AppData", "Local", f"Discord{self.ptb}") elif self.os == 'linux': @@ -38,11 +62,14 @@ class AgnosticPaths: def get_version(self): """ - Looks for the version file in the discord folder + Looks for the version file in the discord folder + and return the latest version of the discord build + :return: The version build + :rtype: str """ versions = [] if self.os == 'windows': - for element in os.listdir(self.main_path): + for element in os.listdir(self._get_path()): if re.match(r"app-[\d.]+", element): versions.append(element) if not versions: @@ -57,14 +84,20 @@ class AgnosticPaths: else: raise OSError("Can't find for version on your OS.") - def update_path(self): + def _update_path(self): + """ + Update the main path with the version, if needed (windows & mac only) + """ if self.os == 'windows': self.main_path = os.path.join(self.main_path, self.version) def list(self, *args): """ - Lists all files in the given path. - :param args: The path + Lists all files in the path /discord_path/args[0]/args[1].../args[n] + :param args: The path as a list of parameters list("folder1", "folder2", ..., "foldern") + :type args: str + :return: The list of all files and folders in the given path + :rtype: list[str] """ return os.listdir(self(*args)) @@ -85,15 +118,39 @@ class AgnosticPaths: return dirs, files def __call__(self, *args): + """ + Tries to open the path /discord_path/args[0]/args[1].../args[n] + :param args: The path of the file or directory as a list of parameters __call__("folder1", "folder2", ..., "foldern") + :type args: str + :return: The path is it exists + :rtype: str + :raises: FileNotFoundError if the path doesn't exists + """ _path = os.path.join(self.main_path, *args) if not os.path.exists(_path): raise FileNotFoundError(f"Could not find {_path}") return _path - + + def get_path(self): + """ + The main path of the discord install + :return: self.main_path + :rtype: str + """ + return self.main_path + def __repr__(self): + """ + :return: A representation of the AgnosticPath + :rtype: str + """ return f"AgnosticPaths(ptb={self.ptb}, os={self.os}, main_path={self.main_path}, version={self.version})" def __str__(self): + """ + :return: The main path of the discord install + :rtype: str + """ return self.main_path From a7068e717498e02e2988c0f8c21afa97fa94ad79 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 22 Jun 2022 09:41:25 +0200 Subject: [PATCH 07/11] Update agnostic_paths.py Corrected a call to os.path with a call to the internal api --- modules/agnostic_paths.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/agnostic_paths.py b/modules/agnostic_paths.py index 1caa56e..a88554b 100644 --- a/modules/agnostic_paths.py +++ b/modules/agnostic_paths.py @@ -54,8 +54,8 @@ class AgnosticPaths: if self.os == 'windows': return os.path.join(os.path.expanduser('~'), "AppData", "Local", f"Discord{self.ptb}") elif self.os == 'linux': - return os.path.join("/","opt","discord") - #return os.path.join("usr","share","discord") + return os.path.join("/", "opt", "discord") + # return os.path.join("usr","share","discord") elif self.os == 'mac': return "" raise OSError("Cannot detect discord PATH") @@ -78,7 +78,7 @@ class AgnosticPaths: return versions[-1] elif self.os == 'linux': from json import load - with open(os.path.join(self.main_path,'resources','build_info.json')) as versionFile: + with open(self('resources', 'build_info.json'), "r") as versionFile: versions = load(versionFile) return versions['version'] else: @@ -158,5 +158,7 @@ if __name__ == '__main__': path = AgnosticPaths("") print(path) print(path.version) - print(path.list_dir_files()) print(path.list()) + print(path()) + print(path("resources", "bootstrap")) # Return the main_path plus resources, bootstrap + print(path.list_dir_files("resources", "bootstrap")) # List the base_path/resources/bootstrap and return [[folders], [files]] From 571b8eb34770c7b416bfb61780d9ec09d03e8060 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 22 Jun 2022 10:18:52 +0200 Subject: [PATCH 08/11] Update spideyDetector.py --- spideyDetector.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spideyDetector.py b/spideyDetector.py index 72198a1..b1d25c0 100644 --- a/spideyDetector.py +++ b/spideyDetector.py @@ -7,7 +7,7 @@ import argparse import sys -def parse(_args): +def parse(_args): # TODO: Move this to a arg_parsing module parser = argparse.ArgumentParser( prog="Spidey Detector", description='Checks for corrupt discord install' @@ -28,12 +28,13 @@ def parse(_args): 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") + parser.add_argument("--force-path", nargs=1, default="", help="Bypass the automatic path discovery with given path") return parser.parse_args(_args) if __name__ == "__main__": args = parse(sys.argv[1:]) - agnostic_path = agnostic_paths.AgnosticPaths(ptb=args.ptb) + agnostic_path = agnostic_paths.AgnosticPaths(ptb=args.ptb, force_path=args.force_path) try: spd = test_interface.run_check(args, agnostic_path) @@ -45,5 +46,5 @@ if __name__ == "__main__": sys.exit(1) if spd == 0: - print("SpideyDetector could not find anything wrong with your discord install!") + print("TestRunner could not find anything wrong with your discord install!") # TODO: Everything should be in the run_all_tests() sys.exit(spd) From e03b8ba8a9f8833c63aafe8c9a12e7c70ca1f9c4 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 22 Jun 2022 10:19:41 +0200 Subject: [PATCH 09/11] Update test_interface.py --- modules/test_interface.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/test_interface.py b/modules/test_interface.py index 0a58a33..ac571e9 100644 --- a/modules/test_interface.py +++ b/modules/test_interface.py @@ -3,12 +3,17 @@ import re import sys import importlib -_TEST_MODULES = { # argparse argument : [module_name, class_name] +""" +All modules that can be tested +Associate the arguments passed to the command line with the modules to be loaded +argparse argument : [module_name, class_name] +""" +_TEST_MODULES = { "spidey": ["spidey_test", "SpideyTest"], } -class SpideyDetector: +class TestRunner: def __init__(self, args, agnpath): """ Main spidey runner @@ -23,7 +28,7 @@ class SpideyDetector: self.os_name = agnpath.os self.main_path = agnpath.main_path self.version = agnpath.version - # self.is_windows = self.check_os() + self.is_infected = 0 self.detections = 0 self.test_run = {} @@ -56,8 +61,9 @@ class SpideyDetector: def exec_all_tests(self): """ - Executes all the tests - :return: + Executes all the tests (later in parallel), get their result as they finishes + :return: The number of test ran, success, failures, skipped (with ran = success+failures+skip) + :rtype: (int,int,int,int) # TODO: Change this to a nametuple """ for module_name, test_class in self.loaded_test_classes.items(): tc = test_class(self.args, self.agnostic_path, None) @@ -65,8 +71,8 @@ class SpideyDetector: print(tc) -def run_check(args, agnpath): - spd = SpideyDetector(args, agnpath) +def run_check(args, agnpath): # Todo, skip the is_infected check and defer everything to the exec_all_tests + spd = TestRunner(args, agnpath) if not spd.is_infected: return 0 else: @@ -74,4 +80,4 @@ def run_check(args, agnpath): if __name__ == "__main__": - pass \ No newline at end of file + pass From 8a1ee4d82f2be123c2d3ce4561390326746d90d3 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 22 Jun 2022 10:20:07 +0200 Subject: [PATCH 10/11] Update spidey_test.py --- modules/spidey_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/spidey_test.py b/modules/spidey_test.py index 43d68cb..7132318 100644 --- a/modules/spidey_test.py +++ b/modules/spidey_test.py @@ -58,3 +58,21 @@ class SpideyTest: discord_modules = self.agnostic_path("modules", "discord_modules-1", "discord_modules") discord_desktop_core = self.agnostic_path("modules", "discord_desktop_core-1", "discord_desktop_core") return discord_modules, discord_desktop_core + + def get_status_code(self): + """ + The status code of the test + :return: 0: The test was not run, 1: The test is running, 2: The test is a success, 3: Test has failed, 4: Test found problems + :rtype: int + """ + # TODO: Add this to a global_dict + return 0 + + def get_status(self): + """ + Return the status of the test, as a string, as the test is ran + :return: "Test is running", "Test was not run", "Test was run and nothing was detected", "Test was run and some problems were detected (list of problems)" + :rtype: (int, str) + """ + # TODO: Make use of a global_dict + return (self.get_status_code(), "") From b65e32dbae4b91acbb97a6df1c5eff47f1d8cd6d Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Wed, 22 Jun 2022 10:20:30 +0200 Subject: [PATCH 11/11] Update agnostic_paths.py --- modules/agnostic_paths.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/agnostic_paths.py b/modules/agnostic_paths.py index a88554b..5a8f9f2 100644 --- a/modules/agnostic_paths.py +++ b/modules/agnostic_paths.py @@ -11,7 +11,7 @@ class AgnosticPaths: An agnostic path object, containing all methods to access the files and folders in a standard discord install """ - def __init__(self, ptb, forced_path=None): + def __init__(self, ptb, force_path=""): """ :param ptb: Whether the discord is a public beta install (ptb="PTB") or not (ptb="") :type ptb: str @@ -20,6 +20,7 @@ class AgnosticPaths: """ self.ptb = ptb self.os = self.get_os() + self.force_path = force_path[0] self.main_path = self._get_path() self.version = self.get_version() self._update_path() @@ -51,6 +52,8 @@ class AgnosticPaths: :return: Base path of the install (minus the version on windows) :rtype: str """ + if self.force_path != "": + return self.force_path if self.os == 'windows': return os.path.join(os.path.expanduser('~'), "AppData", "Local", f"Discord{self.ptb}") elif self.os == 'linux':