Working agnostics
This commit is contained in:
parent
e14885b187
commit
0b9ecf1e3c
32
__main__.py
32
__main__.py
|
|
@ -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)
|
||||
|
|
@ -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())
|
||||
|
|
@ -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 = ""
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
Reference in New Issue