From 62ff1665c85f12f6bfba71511fb2170f35f73880 Mon Sep 17 00:00:00 2001 From: Shahm Najeeb Date: Tue, 17 Dec 2024 22:10:43 +0400 Subject: [PATCH 1/8] Create cflite_pr.yml Signed-off-by: Shahm Najeeb --- .github/workflows/cflite_pr.yml | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/cflite_pr.yml diff --git a/.github/workflows/cflite_pr.yml b/.github/workflows/cflite_pr.yml new file mode 100644 index 0000000..faf9ef1 --- /dev/null +++ b/.github/workflows/cflite_pr.yml @@ -0,0 +1,49 @@ +name: ClusterFuzzLite PR fuzzing +on: + pull_request: + paths: + - '**' +permissions: read-all +jobs: + PR: + runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ matrix.sanitizer }}-${{ github.ref }} + cancel-in-progress: true + strategy: + fail-fast: false + matrix: + sanitizer: + - address + # Override this with the sanitizers you want. + # - undefined + # - memory + steps: + - name: Build Fuzzers (${{ matrix.sanitizer }}) + id: build + uses: google/clusterfuzzlite/actions/build_fuzzers@v1 + with: + language: python # Change this to the language you are fuzzing. + github-token: ${{ secrets.GITHUB_TOKEN }} + sanitizer: ${{ matrix.sanitizer }} + # Optional but recommended: used to only run fuzzers that are affected + # by the PR. + # See later section on "Git repo for storage". + # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git + # storage-repo-branch: main # Optional. Defaults to "main" + # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". + - name: Run Fuzzers (${{ matrix.sanitizer }}) + id: run + uses: google/clusterfuzzlite/actions/run_fuzzers@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fuzz-seconds: 600 + mode: 'code-change' + sanitizer: ${{ matrix.sanitizer }} + output-sarif: true + # Optional but recommended: used to download the corpus produced by + # batch fuzzing. + # See later section on "Git repo for storage". + # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git + # storage-repo-branch: main # Optional. Defaults to "main" + # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". From 430261985d2d22f7adeafce5d6d7acdce1399bbf Mon Sep 17 00:00:00 2001 From: Shahm Najeeb Date: Tue, 17 Dec 2024 22:13:33 +0400 Subject: [PATCH 2/8] Create cflite_batch.yml Signed-off-by: Shahm Najeeb --- .github/workflows/cflite_batch.yml | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/cflite_batch.yml diff --git a/.github/workflows/cflite_batch.yml b/.github/workflows/cflite_batch.yml new file mode 100644 index 0000000..9a27a95 --- /dev/null +++ b/.github/workflows/cflite_batch.yml @@ -0,0 +1,37 @@ +name: ClusterFuzzLite batch fuzzing +on: + schedule: + - cron: '0 0/6 * * *' # Every 6th hour. Change this to whatever is suitable. +permissions: read-all +jobs: + BatchFuzzing: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sanitizer: + - address + # Override this with the sanitizers you want. + # - undefined + # - memory + steps: + - name: Build Fuzzers (${{ matrix.sanitizer }}) + id: build + uses: google/clusterfuzzlite/actions/build_fuzzers@v1 + with: + language: python # Change this to the language you are fuzzing. + sanitizer: ${{ matrix.sanitizer }} + - name: Run Fuzzers (${{ matrix.sanitizer }}) + id: run + uses: google/clusterfuzzlite/actions/run_fuzzers@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fuzz-seconds: 3600 + mode: 'batch' + sanitizer: ${{ matrix.sanitizer }} + output-sarif: true + # Optional but recommended: For storing certain artifacts from fuzzing. + # See later section on "Git repo for storage". + # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git + # storage-repo-branch: main # Optional. Defaults to "main" + # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". From d8899344b97fa817e93ba1c690685b7db614435e Mon Sep 17 00:00:00 2001 From: Shahm Najeeb Date: Tue, 17 Dec 2024 22:13:57 +0400 Subject: [PATCH 3/8] Create cflite_build.yml Signed-off-by: Shahm Najeeb --- .github/workflows/cflite_build.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/cflite_build.yml diff --git a/.github/workflows/cflite_build.yml b/.github/workflows/cflite_build.yml new file mode 100644 index 0000000..32040e9 --- /dev/null +++ b/.github/workflows/cflite_build.yml @@ -0,0 +1,28 @@ +name: ClusterFuzzLite continuous builds +on: + push: + branches: + - main # Use your actual default branch here. +permissions: read-all +jobs: + Build: + runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ matrix.sanitizer }}-${{ github.ref }} + cancel-in-progress: true + strategy: + fail-fast: false + matrix: + sanitizer: + - address + # Override this with the sanitizers you want. + # - undefined + # - memory + steps: + - name: Build Fuzzers (${{ matrix.sanitizer }}) + id: build + uses: google/clusterfuzzlite/actions/build_fuzzers@v1 + with: + language: python # Change this to the language you are fuzzing. + sanitizer: ${{ matrix.sanitizer }} + upload-build: true From 9cf04f95dc6f3a0b17c9cb63016b61ae2a7ac8b9 Mon Sep 17 00:00:00 2001 From: Shahm Najeeb Date: Tue, 17 Dec 2024 22:14:27 +0400 Subject: [PATCH 4/8] Create cflite_cron.yml Signed-off-by: Shahm Najeeb --- .github/workflows/cflite_cron.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/cflite_cron.yml diff --git a/.github/workflows/cflite_cron.yml b/.github/workflows/cflite_cron.yml new file mode 100644 index 0000000..a8267ad --- /dev/null +++ b/.github/workflows/cflite_cron.yml @@ -0,0 +1,27 @@ +name: ClusterFuzzLite cron tasks +on: + schedule: + - cron: '0 0 * * *' # Once a day at midnight. +permissions: read-all +jobs: + Pruning: + runs-on: ubuntu-latest + steps: + - name: Build Fuzzers + id: build + uses: google/clusterfuzzlite/actions/build_fuzzers@v1 + with: + language: python # Change this to the language you are fuzzing + - name: Run Fuzzers + id: run + uses: google/clusterfuzzlite/actions/run_fuzzers@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + fuzz-seconds: 600 + mode: 'prune' + output-sarif: true + # Optional but recommended. + # See later section on "Git repo for storage". + # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git + # storage-repo-branch: main # Optional. Defaults to "main" + # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". From 38a8658faae1e0b79a7e9f3f4d445fd2e6f3c5fa Mon Sep 17 00:00:00 2001 From: Shahm Najeeb Date: Tue, 17 Dec 2024 22:18:05 +0400 Subject: [PATCH 5/8] Delete .github/workflows/cflite_pr.yml Signed-off-by: Shahm Najeeb --- .github/workflows/cflite_pr.yml | 49 --------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 .github/workflows/cflite_pr.yml diff --git a/.github/workflows/cflite_pr.yml b/.github/workflows/cflite_pr.yml deleted file mode 100644 index faf9ef1..0000000 --- a/.github/workflows/cflite_pr.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: ClusterFuzzLite PR fuzzing -on: - pull_request: - paths: - - '**' -permissions: read-all -jobs: - PR: - runs-on: ubuntu-latest - concurrency: - group: ${{ github.workflow }}-${{ matrix.sanitizer }}-${{ github.ref }} - cancel-in-progress: true - strategy: - fail-fast: false - matrix: - sanitizer: - - address - # Override this with the sanitizers you want. - # - undefined - # - memory - steps: - - name: Build Fuzzers (${{ matrix.sanitizer }}) - id: build - uses: google/clusterfuzzlite/actions/build_fuzzers@v1 - with: - language: python # Change this to the language you are fuzzing. - github-token: ${{ secrets.GITHUB_TOKEN }} - sanitizer: ${{ matrix.sanitizer }} - # Optional but recommended: used to only run fuzzers that are affected - # by the PR. - # See later section on "Git repo for storage". - # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git - # storage-repo-branch: main # Optional. Defaults to "main" - # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". - - name: Run Fuzzers (${{ matrix.sanitizer }}) - id: run - uses: google/clusterfuzzlite/actions/run_fuzzers@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - fuzz-seconds: 600 - mode: 'code-change' - sanitizer: ${{ matrix.sanitizer }} - output-sarif: true - # Optional but recommended: used to download the corpus produced by - # batch fuzzing. - # See later section on "Git repo for storage". - # storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/OWNER/STORAGE-REPO-NAME.git - # storage-repo-branch: main # Optional. Defaults to "main" - # storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages". From 70f9544ebabcea470f45981166323bf5c9bf9c64 Mon Sep 17 00:00:00 2001 From: Shahm Najeeb Date: Wed, 18 Dec 2024 08:57:09 +0400 Subject: [PATCH 6/8] Optimised _debug.py Now its better and more efficient, as well as less redundant, new function added to Checks.py which allows you to check the execution policy Signed-off-by: Shahm Najeeb --- CODE/_debug.py | 129 ++++++++++++++------------------------ CODE/logicytics/Checks.py | 10 +++ 2 files changed, 58 insertions(+), 81 deletions(-) diff --git a/CODE/_debug.py b/CODE/_debug.py index 784ef60..e5f1f4f 100644 --- a/CODE/_debug.py +++ b/CODE/_debug.py @@ -3,9 +3,7 @@ import configparser import os import platform -import subprocess import sys -from datetime import datetime import psutil import requests @@ -13,27 +11,27 @@ from logicytics import Log, DEBUG, VERSION, Check if __name__ == "__main__": - log_debug = Log({"log_level": DEBUG, "filename": "../ACCESS/LOGS/DEBUG/DEBUG.log", "truncate_message": False}) + log_debug = Log( + {"log_level": DEBUG, + "filename": "../ACCESS/LOGS/DEBUG/DEBUG.log", + "truncate_message": False} + ) class HealthCheck: @staticmethod - def check_files(directory: str, required_files: list[str]) -> tuple[str, str]: + def check_files(directory: str, required_files: list[str]): """ Checks if all required files are present in the directory and its subdirectories. Args: directory (str): Path to the directory to check. required_files (list[str]): List of required file names with relative paths. - - Returns: - tuple[str, str]: Status message and severity level. """ try: log_debug.debug(f"Checking directory: {directory}") if not os.path.exists(directory): log_debug.error(f"Directory {directory} does not exist.") - return f"Directory {directory} does not exist.", "ERROR" # Gather all files with relative paths actual_files = [] @@ -68,14 +66,13 @@ def check_files(directory: str, required_files: list[str]) -> tuple[str, str]: log_debug.debug(f"Extra files: {extra_files}") if missing_files: - return f"Missing files: {', '.join(missing_files)}", "ERROR" + log_debug.error(f"Missing files: {', '.join(missing_files)}") if extra_files: - return f"Extra files found: {', '.join(extra_files)}", "WARNING" - return "All required files are present.", "INFO" + log_debug.warning(f"Extra files found: {', '.join(extra_files)}") + log_debug.info("All required files are present.") except Exception as e: log_debug.error(f"Unexpected error during file check: {e}") - return f"Unexpected error during file check: {e}", "ERROR" @staticmethod def get_online_config() -> dict | None: @@ -92,47 +89,38 @@ def get_online_config() -> dict | None: config.read_string(requests.get(url, timeout=15).text) return config except requests.exceptions.RequestException as e: - log_debug.warning(f"Connection error: {e}") + log_debug.error(f"Connection error: {e}") return None @staticmethod - def compare_versions(local_version: str, remote_version: str) -> tuple[str, str, str]: + def compare_versions(local_version: str, remote_version: str): """ Compares local and remote versions. Args: local_version (str): Local version. remote_version (str): Remote version. - - Returns: - tuple[str, str, str]: Comparison result, version details, and severity level. """ if local_version == remote_version: - return "Version is up to date.", f"Your Version: {local_version}", "INFO" - if local_version > remote_version: - return ( - "Version is ahead of the repository.", - f"Your Version: {local_version}, Repository Version: {remote_version}", - "WARNING", - ) - return ( - "Version is behind the repository.", - f"Your Version: {local_version}, Repository Version: {remote_version}", - "ERROR", - ) + log_debug.info(f"Version is up to date. Your Version: {local_version}") + elif local_version > remote_version: + log_debug.warning("Version is ahead of the repository. " + f"Your Version: {local_version}, " + f"Repository Version: {remote_version}") + else: + log_debug.error("Version is behind the repository." + f"Your Version: {local_version}, Repository Version: {remote_version}" + ) class DebugCheck: @staticmethod - def sys_internal_binaries(path: str) -> tuple[str, str]: + def sys_internal_binaries(path: str): """ Checks the SysInternal Binaries in the given directory. Args: path (str): Directory path. - - Returns: - tuple[str, str]: Status message and severity level. """ try: if not os.path.exists(path): @@ -145,34 +133,15 @@ def sys_internal_binaries(path: str) -> tuple[str, str]: has_exe = any(file.endswith(".exe") for file in contents) if any(file.endswith(".ignore") for file in contents): - return "A `.sys.ignore` file was found - Ignoring", "WARNING" - if has_zip and not has_exe: - return "Only zip files - Missing EXEs due to no `ignore` file", "ERROR" - if has_zip and has_exe: - return "Both zip and exe files - All good", "INFO" - - return "SysInternal Binaries Not Found: Missing Files - Corruption detected", "ERROR" + log_debug.warning("A `.sys.ignore` file was found - Ignoring") + elif has_zip and not has_exe: + log_debug.error("Only zip files - Missing EXEs due to no `ignore` file") + elif has_zip and has_exe: + log_debug.info("Both zip and exe files - All good") + else: + log_debug.error("SysInternal Binaries Not Found: Missing Files - Corruption detected") except Exception as e: - return f"Unexpected error: {e}", "ERROR" - - @staticmethod - def execution_policy() -> bool: - """ - Checks if the execution policy is unrestricted. - - Returns: - bool: True if unrestricted, False otherwise. - """ - try: - result = subprocess.run( - ["powershell", "-Command", "Get-ExecutionPolicy"], - capture_output=True, - text=True, - ) - return result.stdout.strip().lower() == "unrestricted" - except Exception as e: - log_debug.error(f"Failed to check execution policy: {e}") - return False + log_debug.error(f"Unexpected error: {e}") @staticmethod def cpu_info() -> tuple[str, str, str]: @@ -189,6 +158,20 @@ def cpu_info() -> tuple[str, str, str]: ) +def python_version(): + version = sys.version.split()[0] + try: + major, minor = map(int, version.split(".")[:2]) + if (major, minor) == (3, 11): + log_debug.info(f"Python Version: {version} - Perfect") + elif major == 3: + log_debug.warning(f"Python Version: {version} - Recommended: 3.11.x") + else: + log_debug.error(f"Python Version: {version} - Incompatible") + except Exception as e: + log_debug.error(f"Failed to parse Python Version: {e}") + + def debug(): """ Executes system checks and logs results. @@ -201,18 +184,14 @@ def debug(): # Online Configuration Check config = HealthCheck.get_online_config() if config: - version_check = HealthCheck.compare_versions(VERSION, config["System Settings"]["version"]) - log_debug.string(version_check[0], version_check[2]) - log_debug.raw(f"[{datetime.now():%Y-%m-%d %H:%M:%S}] > DATA: {version_check[1]}") + HealthCheck.compare_versions(VERSION, config["System Settings"]["version"]) # File Integrity Check required_files = config["System Settings"].get("files", "").split(",") - message, severity = HealthCheck.check_files(".", required_files) - log_debug.string(message, severity) + HealthCheck.check_files(".", required_files) # SysInternal Binaries Check - message, severity = DebugCheck.sys_internal_binaries("SysInternal_Suite") - log_debug.string(message, severity) + DebugCheck.sys_internal_binaries("SysInternal_Suite") # System Checks log_debug.info("Admin privileges found" if Check.admin() else "Admin privileges not found") @@ -222,23 +201,11 @@ def debug(): log_debug.info(f"Local execution path: {sys.prefix}") log_debug.info( "Running in a virtual environment" if sys.prefix != sys.base_prefix else "Not running in a virtual environment") - - # Execution Policy Check log_debug.info( - "Execution policy is unrestricted" if DebugCheck.execution_policy() else "Execution policy is not unrestricted") + "Execution policy is unrestricted" if Check.execution_policy() else "Execution policy is not unrestricted") # Python Version Check - python_version = sys.version.split()[0] - try: - major, minor = map(int, python_version.split(".")[:2]) - if (major, minor) == (3, 11): - log_debug.info(f"Python Version: {python_version} - Perfect") - elif major == 3: - log_debug.warning(f"Python Version: {python_version} - Recommended: 3.11.x") - else: - log_debug.error(f"Python Version: {python_version} - Incompatible") - except Exception as e: - log_debug.error(f"Failed to parse Python Version: {e}") + python_version() # CPU Info for info in DebugCheck.cpu_info(): diff --git a/CODE/logicytics/Checks.py b/CODE/logicytics/Checks.py index 8e1275d..b0ab254 100644 --- a/CODE/logicytics/Checks.py +++ b/CODE/logicytics/Checks.py @@ -2,6 +2,7 @@ import ctypes import os.path +import subprocess import zipfile from logicytics.Execute import Execute @@ -21,6 +22,15 @@ def admin() -> bool: except AttributeError: return False + @staticmethod + def execution_policy() -> bool: + result = subprocess.run( + ["powershell", "-Command", "Get-ExecutionPolicy"], + capture_output=True, + text=True, + ) + return result.stdout.strip().lower() == "unrestricted" + @staticmethod def uac() -> bool: """ From 04eec595a6d1427467c54981e8f7c21827060f48 Mon Sep 17 00:00:00 2001 From: Shahm Najeeb Date: Wed, 18 Dec 2024 10:10:11 +0400 Subject: [PATCH 7/8] Fixed minor bugs Signed-off-by: Shahm Najeeb --- CODE/_debug.py | 113 +++++++++++++++++++++++++------------- CODE/logicytics/Checks.py | 27 +++++++-- 2 files changed, 97 insertions(+), 43 deletions(-) diff --git a/CODE/_debug.py b/CODE/_debug.py index e5f1f4f..6d79a68 100644 --- a/CODE/_debug.py +++ b/CODE/_debug.py @@ -20,7 +20,31 @@ class HealthCheck: @staticmethod - def check_files(directory: str, required_files: list[str]): + def __version_tuple(version: str) -> tuple[int, int, int | str, str]: + """ + Parses a version string into a tuple. + + Args: + version (str): The version string to parse. + + Returns: + tuple[int, int, int, str]: A tuple containing the major, minor, and patch versions, + and a string indicating whether it is a snapshot or release version. + """ + try: + if version.startswith("snapshot-"): + parts = version.split('-')[1].split('.') + major, minor = map(int, parts[:2]) + patch = parts[2] if len(parts) > 2 else "0" + return major, minor, patch, "snapshot" + else: + return tuple(map(int, version.split('.'))) + ("release",) + except Exception as err: + log_debug.error(f"Failed to parse version: {err}") + return 0, 0, 0, "error" + + @staticmethod + def files(directory: str, required_files: list[str]): """ Checks if all required files are present in the directory and its subdirectories. @@ -74,26 +98,8 @@ def check_files(directory: str, required_files: list[str]): except Exception as e: log_debug.error(f"Unexpected error during file check: {e}") - @staticmethod - def get_online_config() -> dict | None: - """ - Retrieves configuration data from a remote repository. - - Returns: - dict: Parsed configuration data if successful. - None: If there was an error fetching the configuration. - """ - try: - url = "https://raw.githubusercontent.com/DefinetlyNotAI/Logicytics/main/CODE/config.ini" - config = configparser.ConfigParser() - config.read_string(requests.get(url, timeout=15).text) - return config - except requests.exceptions.RequestException as e: - log_debug.error(f"Connection error: {e}") - return None - - @staticmethod - def compare_versions(local_version: str, remote_version: str): + @classmethod + def versions(cls, local_version: str, remote_version: str): """ Compares local and remote versions. @@ -101,16 +107,29 @@ def compare_versions(local_version: str, remote_version: str): local_version (str): Local version. remote_version (str): Remote version. """ - if local_version == remote_version: - log_debug.info(f"Version is up to date. Your Version: {local_version}") - elif local_version > remote_version: - log_debug.warning("Version is ahead of the repository. " - f"Your Version: {local_version}, " - f"Repository Version: {remote_version}") - else: - log_debug.error("Version is behind the repository." - f"Your Version: {local_version}, Repository Version: {remote_version}" - ) + + local_version_tuple = cls.__version_tuple(local_version) + remote_version_tuple = cls.__version_tuple(remote_version) + + if "error" in local_version_tuple or "error" in remote_version_tuple: + log_debug.error("Version parsing error.") + return + + try: + if "snapshot" in local_version_tuple or "snapshot" in remote_version_tuple: + log_debug.warning("Snapshot versions are unstable.") + + if local_version_tuple == remote_version_tuple: + log_debug.info(f"Version is up to date. Your Version: {local_version}") + elif local_version_tuple > remote_version_tuple: + log_debug.warning("Version is ahead of the repository. " + f"Your Version: {local_version}, " + f"Repository Version: {remote_version}") + else: + log_debug.error("Version is behind the repository. " + f"Your Version: {local_version}, Repository Version: {remote_version}") + except Exception as e: + log_debug.error(f"Version comparison error: {e}") class DebugCheck: @@ -160,11 +179,13 @@ def cpu_info() -> tuple[str, str, str]: def python_version(): version = sys.version.split()[0] + MIN_VERSION = (3, 11) + MAX_VERSION = (3, 13) try: major, minor = map(int, version.split(".")[:2]) - if (major, minor) == (3, 11): + if MIN_VERSION <= (major, minor) < MAX_VERSION: log_debug.info(f"Python Version: {version} - Perfect") - elif major == 3: + elif (major, minor) < MIN_VERSION: log_debug.warning(f"Python Version: {version} - Recommended: 3.11.x") else: log_debug.error(f"Python Version: {version} - Incompatible") @@ -172,23 +193,41 @@ def python_version(): log_debug.error(f"Failed to parse Python Version: {e}") +def get_online_config() -> dict | None: + """ + Retrieves configuration data from a remote repository. + + Returns: + dict: Parsed configuration data if successful. + None: If there was an error fetching the configuration. + """ + try: + url = "https://raw.githubusercontent.com/DefinetlyNotAI/Logicytics/main/CODE/config.ini" + config = configparser.ConfigParser() + config.read_string(requests.get(url, timeout=15).text) + return config + except requests.exceptions.RequestException as e: + log_debug.error(f"Connection error: {e}") + return None + + def debug(): """ Executes system checks and logs results. """ # Clear Debug Log - log_path = "../ACCESS/LOGS/DEBUG/DEBUG.LOG" + log_path = "../ACCESS/LOGS/DEBUG/DEBUG.log" if os.path.exists(log_path): os.remove(log_path) # Online Configuration Check - config = HealthCheck.get_online_config() + config = get_online_config() if config: - HealthCheck.compare_versions(VERSION, config["System Settings"]["version"]) + HealthCheck.versions(VERSION, config["System Settings"]["version"]) # File Integrity Check required_files = config["System Settings"].get("files", "").split(",") - HealthCheck.check_files(".", required_files) + HealthCheck.files(".", required_files) # SysInternal Binaries Check DebugCheck.sys_internal_binaries("SysInternal_Suite") diff --git a/CODE/logicytics/Checks.py b/CODE/logicytics/Checks.py index b0ab254..6a2566f 100644 --- a/CODE/logicytics/Checks.py +++ b/CODE/logicytics/Checks.py @@ -24,12 +24,27 @@ def admin() -> bool: @staticmethod def execution_policy() -> bool: - result = subprocess.run( - ["powershell", "-Command", "Get-ExecutionPolicy"], - capture_output=True, - text=True, - ) - return result.stdout.strip().lower() == "unrestricted" + """ + Check if PowerShell execution policy is set to unrestricted. + + Returns: + bool: True if execution policy is unrestricted, False otherwise. + + Note: + This method requires PowerShell to be available on the system. + """ + if not os.path.exists("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"): + return False + try: + result = subprocess.run( + ["powershell", "-Command", "Get-ExecutionPolicy"], + capture_output=True, + text=True, + timeout=5 # Don't hang forever + ) + return result.returncode == 0 and result.stdout.strip().lower() == "unrestricted" + except (subprocess.TimeoutExpired, subprocess.SubprocessError) as e: + return False @staticmethod def uac() -> bool: From 391a6edd9217a7f7fdc3395996ce540eb786c2aa Mon Sep 17 00:00:00 2001 From: Shahm Najeeb Date: Wed, 18 Dec 2024 10:18:30 +0400 Subject: [PATCH 8/8] Fixed minor bugs Signed-off-by: Shahm Najeeb --- CODE/logicytics/Checks.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CODE/logicytics/Checks.py b/CODE/logicytics/Checks.py index 6a2566f..1bdd2dc 100644 --- a/CODE/logicytics/Checks.py +++ b/CODE/logicytics/Checks.py @@ -33,8 +33,6 @@ def execution_policy() -> bool: Note: This method requires PowerShell to be available on the system. """ - if not os.path.exists("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"): - return False try: result = subprocess.run( ["powershell", "-Command", "Get-ExecutionPolicy"], @@ -44,7 +42,8 @@ def execution_policy() -> bool: ) return result.returncode == 0 and result.stdout.strip().lower() == "unrestricted" except (subprocess.TimeoutExpired, subprocess.SubprocessError) as e: - return False + print(f"Failed to check execution policy: {e}") + exit(1) @staticmethod def uac() -> bool: