Skip to content

Commit

Permalink
Fixed formatting (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbalkan authored Dec 16, 2024
1 parent 224f295 commit 6311d31
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions src/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/formats/pst.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,15 @@ def __init__(self, payload: bytes) -> None:
self.nid = NID(nid)
self.bid = BID(bid)


class BlockType(IntEnum):
DATA = 0
XBLOCK = 1
XXBLOCK = 2
SLBLOCK = 3
SIBLOCK = 4


class Block:

# this has the first 512 entries removed, as decoding only uses from 512 onwards
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -1098,6 +1103,7 @@ class TCOffset(IntEnum):
TCI_1b = 2
TCI_bm = 3


class TC: # Table Context

hn: HN
Expand Down
3 changes: 1 addition & 2 deletions src/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 5 additions & 11 deletions src/panhunt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import os
import platform
import sys
import time
from datetime import datetime
from typing import Final, Optional

Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -123,7 +118,6 @@ def main() -> None:

config_file: Optional[str] = args.config


# We need these as flags
json_dir: Optional[str]
quiet: bool
Expand Down
4 changes: 2 additions & 2 deletions src/panutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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("<BB", gf.read(2))

if not flag & FNAME:
Expand Down

0 comments on commit 6311d31

Please sign in to comment.