Ajusted arguments

This commit is contained in:
Maximilien Rigaut 2022-06-22 21:33:29 +02:00
parent ae3da2a172
commit 7134d9737c
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
4 changed files with 41 additions and 35 deletions

24
discordHelper.py Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/python3
""" Main program """
from modules import test_interface, agnostic_paths, argument_parser
import sys
if __name__ == "__main__":
args = argument_parser.parse(sys.argv[1:])
agnostic_path = agnostic_paths.AgnosticPaths(ptb=args.ptb, force_path=args.force_path)
try:
spd = test_interface.run_check(args, agnostic_path)
except FileNotFoundError as er:
print(er)
sys.exit(1)
except OSError as er:
print(er.strerror)
sys.exit(1)
if spd == 0:
print("Discord Helper could not find anything wrong with your discord install!") # TODO: Everything should be in the run_all_tests()
sys.exit(spd)

View File

@ -11,16 +11,19 @@ class AgnosticPaths:
An agnostic path object, containing all methods to access the files and folders in a standard discord install
"""
def __init__(self, ptb, force_path=""):
def __init__(self, ptb, force_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
:param force_path: An alternative discord install path, usefull to test the script on a non standard install
:type force_path: str
"""
self.ptb = ptb
self.os = self.get_os()
self.force_path = force_path[0]
if force_path is not None:
self.force_path = force_path[0]
else:
self.force_path = None
self.main_path = self._get_path()
self.version = self.get_version()
self._update_path()
@ -47,12 +50,12 @@ class AgnosticPaths:
def _get_path(self):
"""
Return the base path of the install, note that the self.main_path is not returned,
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)
:return: Base path of the install (minus the version on Windows)
:rtype: str
"""
if self.force_path != "":
if self.force_path is not None:
return self.force_path
if self.os == 'windows':
return os.path.join(os.path.expanduser('~'), "AppData", "Local", f"Discord{self.ptb}")

View File

@ -1,13 +1,7 @@
#!/usr/bin/python3
""" Main program """
from modules import test_interface, agnostic_paths
import argparse
import sys
def parse(_args): # TODO: Move this to a arg_parsing module
def parse(_args):
parser = argparse.ArgumentParser(
prog="Spidey Detector",
description='Checks for corrupt discord install'
@ -28,26 +22,13 @@ def parse(_args): # TODO: Move this to a arg_parsing module
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")
parser.add_argument("--force-path", nargs=1, default=None, help="Bypass the automatic path discovery with given path")
parser.add_argument("--only-known-paths", "--fast", action='store_true', help="Only run the check on the known paths")
parser.add_argument("--no-eval", action="store_true", help="Check for the eval function wich is a HUGE red flag")
parser.add_argument("--const-abuse", "--no-const", action="store_true", help="Check for the abuse of the const: keyword, wich is massively used for obfucation")
parser.add_argument("--gen-data", "--generate-data", "--gen", action="store_true", help="Generate data for the analysis")
parser.add_argument("--gen-data-path", "--generate-data-path", "--gen-path", nargs=1, default="", help="Path to generate the data in")
parser.add_argument("--database", "--db", nargs=1, default="", help="Alternative database for the analysis")
parser.add_argument("--continue", action="store_true", help="Continue the analysis in case of failure")
return parser.parse_args(_args)
if __name__ == "__main__":
args = parse(sys.argv[1:])
agnostic_path = agnostic_paths.AgnosticPaths(ptb=args.ptb, force_path=args.force_path)
try:
spd = test_interface.run_check(args, agnostic_path)
except FileNotFoundError as er:
print(er)
sys.exit(1)
except OSError as er:
print(er.strerror)
sys.exit(1)
if spd == 0:
print("TestRunner could not find anything wrong with your discord install!") # TODO: Everything should be in the run_all_tests()
sys.exit(spd)

View File

@ -48,7 +48,6 @@ class TestRunner:
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])
@ -68,7 +67,6 @@ class TestRunner:
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): # Todo, skip the is_infected check and defer everything to the exec_all_tests