From 6311d31f3a68e787b0290fb6b80be6e3c15e2e38 Mon Sep 17 00:00:00 2001 From: Zafer Balkan Date: Mon, 16 Dec 2024 22:02:43 +0200 Subject: [PATCH] Fixed formatting (#93) --- src/archive.py | 1 - src/config.py | 2 +- src/dispatcher.py | 10 +++++----- src/formats/pst.py | 6 ++++++ src/job.py | 3 +-- src/panhunt.py | 16 +++++----------- src/panutils.py | 4 ++-- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/archive.py b/src/archive.py index fbd0936..3c298fb 100644 --- a/src/archive.py +++ b/src/archive.py @@ -50,7 +50,6 @@ def get_children(self) -> tuple[list[Job], Optional[PANHuntException]]: return children, None - class TarArchive(Archive): def get_children(self) -> tuple[list[Job], Optional[PANHuntException]]: diff --git a/src/config.py b/src/config.py index 58e6526..6461c72 100644 --- a/src/config.py +++ b/src/config.py @@ -147,7 +147,7 @@ def __try_parse_int(config_from_file: dict, property: str) -> Optional[int]: @ staticmethod def __try_parse_bool(config_from_file: dict, property: str) -> Optional[bool]: - s: Optional[str]=PANHuntConfiguration.__try_parse( + s: Optional[str] = PANHuntConfiguration.__try_parse( config_from_file, property) if s: return s.lower() == 'true' diff --git a/src/dispatcher.py b/src/dispatcher.py index c91d49d..21b0655 100644 --- a/src/dispatcher.py +++ b/src/dispatcher.py @@ -55,8 +55,8 @@ def _run_dispatch_loop(self) -> None: else: self.failures.append(res) finally: - job.payload = None # Clear the payload to save memory ASAP - job = None # Clear the job to save memory ASAP + job.payload = None # Clear the payload to save memory ASAP + job = None # Clear the job to save memory ASAP # Mark the job as completed job_queue.complete_job() else: @@ -77,7 +77,7 @@ def _dispatch_job(self, job: Job) -> Optional[Finding]: doc = Finding(basename=job.basename, dirname=job.dirname, payload=job.payload, mimetype='Unknown', encoding='Unknown', err=PANHuntException( - f'File size {panutils.size_friendly(size=size)} over limit of {panutils.size_friendly(size=self.__size_limit)} for checking for file \"{job.basename}\"')) # type: ignore + f'File size {panutils.size_friendly(size=size)} over limit of {panutils.size_friendly(size=self.__size_limit)} for checking for file \"{job.basename}\"')) # type: ignore return doc mime_type, encoding, error = panutils.get_mimetype( @@ -98,7 +98,7 @@ def _dispatch_job(self, job: Job) -> Optional[Finding]: children, e = archive.get_children() if e: doc = Finding(basename=job.basename, dirname=job.dirname, - payload=job.payload, mimetype=mime_type, encoding=encoding, err=e) # type: ignore + payload=job.payload, mimetype=mime_type, encoding=encoding, err=e) # type: ignore return doc else: for child in children: @@ -134,6 +134,6 @@ def _scan_file(self, job: Job, finding.matches = matches except Exception as ex: finding = Finding( - basename=job.basename, dirname=job.dirname, payload=job.payload, mimetype=mimetype, encoding=encoding, err=ex) # type: ignore + basename=job.basename, dirname=job.dirname, payload=job.payload, mimetype=mimetype, encoding=encoding, err=ex) # type: ignore finally: return finding diff --git a/src/formats/pst.py b/src/formats/pst.py index 4227795..739e247 100644 --- a/src/formats/pst.py +++ b/src/formats/pst.py @@ -344,6 +344,7 @@ def __init__(self, payload: bytes) -> None: self.nid = NID(nid) self.bid = BID(bid) + class BlockType(IntEnum): DATA = 0 XBLOCK = 1 @@ -351,6 +352,7 @@ class BlockType(IntEnum): SLBLOCK = 3 SIBLOCK = 4 + class Block: # this has the first 512 entries removed, as decoding only uses from 512 onwards @@ -645,11 +647,13 @@ def __init__(self, payload: bytes) -> None: self.rgibAlloc.append(struct.unpack( 'H', payload[4 + i * 2:4 + (i + 1) * 2])[0]) + class HNType(IntEnum): TypeTC = 0x7C TypeBTH = 0xB5 TypePC = 0xBC + class HN: # While it is not defined in the spec, # BID data and BID sub nodes are needed to enumerate the sub nodes @@ -1084,6 +1088,7 @@ def __init__(self, bth_data: BTHData) -> None: else: # unicode (4) self.dwRowIndex = panutils.unpack_integer('I', bth_data.data) + class TCOffset(IntEnum): """ Index Name Description @@ -1098,6 +1103,7 @@ class TCOffset(IntEnum): TCI_1b = 2 TCI_bm = 3 + class TC: # Table Context hn: HN diff --git a/src/job.py b/src/job.py index 846cb6b..29d4b17 100644 --- a/src/job.py +++ b/src/job.py @@ -14,7 +14,6 @@ class Job: payload: Optional[bytes] abspath: str - def __init__(self, basename: str, dirname: str, payload: Optional[bytes] = None) -> None: self.basename = basename self.dirname = dirname @@ -94,7 +93,7 @@ def ensure_memory_ready(self, job: Job) -> None: f"Insufficient memory to process job: {job.abspath}") sleep_time = 0.0 - while size >= psutil.virtual_memory().free / 2: # We want to leave a buffer of free memory + while size >= psutil.virtual_memory().free / 2: # We want to leave a buffer of free memory sleep_time += 0.1 if (sleep_time >= self._timeout): raise MemoryError( diff --git a/src/panhunt.py b/src/panhunt.py index 161552f..0e40164 100644 --- a/src/panhunt.py +++ b/src/panhunt.py @@ -14,7 +14,6 @@ import os import platform import sys -import time from datetime import datetime from typing import Final, Optional @@ -72,18 +71,14 @@ def display_report(report: Report) -> None: for pan in sf.matches: pan_list += f"{pan}{pan_sep}" - print(colorama.Fore.YELLOW + - panutils.unicode_to_ascii(pan_list)) + print(colorama.Fore.YELLOW + panutils.unicode_to_ascii(pan_list)) if len(report.interesting_files) > 0: - print(colorama.Fore.RED + - 'Interesting Files to check separately, probably a permission or file size issue:') + print(colorama.Fore.RED + 'Interesting Files to check separately, probably a permission or file size issue:') for interesting in report.interesting_files: - print(colorama.Fore.YELLOW + '\t- ' + - f'{panutils.unicode_to_ascii(interesting.abspath)} ({panutils.unicode_to_ascii(panutils.size_friendly(interesting.size))})') + print(colorama.Fore.YELLOW + '\t- ' + f'{panutils.unicode_to_ascii(interesting.abspath)} ({panutils.unicode_to_ascii(panutils.size_friendly(interesting.size))})') - print(colorama.Fore.WHITE + - f'Report written to {panutils.unicode_to_ascii(PANHuntConfiguration().get_report_path())}') + print(colorama.Fore.WHITE + f'Report written to {panutils.unicode_to_ascii(PANHuntConfiguration().get_report_path())}') def main() -> None: @@ -94,7 +89,7 @@ def main() -> None: datefmt="%Y-%m-%dT%H:%M:%S%z", level=logging.DEBUG) - excepthook = logging.error + sys.excepthook = logging.error logging.info('Starting') colorama.init() @@ -123,7 +118,6 @@ def main() -> None: config_file: Optional[str] = args.config - # We need these as flags json_dir: Optional[str] quiet: bool diff --git a/src/panutils.py b/src/panutils.py index b4981f6..69e805b 100644 --- a/src/panutils.py +++ b/src/panutils.py @@ -55,7 +55,7 @@ def __get_mime_data_from_buffer(payload: bytes) -> tuple[str, str]: def __get_mime_data_from_file(path: str) -> tuple[str, str]: m = magic.Magic(mime=True, mime_encoding=True) - mime_data: list[str] = m.from_file(filename=path).split(';') # type: ignore + mime_data: list[str] = m.from_file(filename=path).split(';') # type: ignore mime_type: str = mime_data[0].strip().lower() encoding: str = mime_data[1].replace( ' charset=', '').strip().lower() @@ -182,7 +182,7 @@ def memoryview_to_bytes(mem_view: memoryview) -> Optional[bytes]: def get_compressed_filename(gf: GzipFile) -> str: gf.seek(0) - magic: bytes = gf.read(2) + _ = gf.read(2) # skip magic bytes method, flag = struct.unpack("