Merge pull request #7 from idle-org/feature/doc_followup

Update spideyDetector.py
This commit is contained in:
Maximilien Rigaut 2022-06-22 10:21:00 +02:00 committed by GitHub
commit e237ed2886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 12 deletions

View File

@ -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':

View File

@ -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(), "")

View File

@ -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
pass

View File

@ -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)