Merge pull request #999 from 616c696365/fix-issue-895

Windows: Update pslist.py, add friendly option
This commit is contained in:
ikelos
2023-10-19 10:29:42 +01:00
committed by GitHub
2 changed files with 25 additions and 3 deletions
+13 -1
View File
@@ -43,7 +43,7 @@ class FileHandlerInterface(io.RawIOBase):
return self._preferred_filename
@preferred_filename.setter
def preferred_filename(self, filename):
def preferred_filename(self, filename: str):
"""Sets the preferred filename"""
if self.closed:
raise IOError("FileHandler name cannot be changed once closed")
@@ -57,6 +57,18 @@ class FileHandlerInterface(io.RawIOBase):
def close(self):
"""Method that commits the file and fixes the final filename for use"""
@staticmethod
def sanitize_filename(filename: str) -> str:
"""Sanititizes the filename to ensure only a specific whitelist of characters is allowed through"""
allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.- ()[]\{\}!$%^:#~?<>,|"
result = ""
for char in filename:
if char in allowed:
result += char
else:
result += "?"
return result
def __enter__(self):
return self
@@ -90,9 +90,19 @@ class PsList(interfaces.plugins.PluginInterface, timeliner.TimeLinerInterface):
offset=peb.ImageBaseAddress,
layer_name=proc_layer_name,
)
file_handle = open_method(
f"pid.{proc.UniqueProcessId}.{peb.ImageBaseAddress:#x}.dmp"
process_name = proc.ImageFileName.cast(
"string",
max_length=proc.ImageFileName.vol.count,
errors="replace",
)
file_handle = open_method(
open_method.sanitize_filename(
f"{proc.UniqueProcessId}.{process_name}.{peb.ImageBaseAddress:#x}.dmp"
)
)
for offset, data in dos_header.reconstruct():
file_handle.seek(offset)
file_handle.write(data)