From c5f7efafc13c4e47f09abe8c38a6ef05336f31e1 Mon Sep 17 00:00:00 2001 From: Zeecka Date: Fri, 2 Jan 2026 01:06:39 +0100 Subject: [PATCH] WIP --- aperisolve/analyzers/pngcheck.py | 5 +++++ aperisolve/analyzers/steghide.py | 15 +++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/aperisolve/analyzers/pngcheck.py b/aperisolve/analyzers/pngcheck.py index 36ee677..d62fca6 100644 --- a/aperisolve/analyzers/pngcheck.py +++ b/aperisolve/analyzers/pngcheck.py @@ -18,6 +18,11 @@ class PngcheckAnalyzer(SubprocessAnalyzer): def is_error(self, returncode: int, stdout: str, stderr: str, zip_exist: bool) -> bool: return "this is neither a PNG or JNG image nor a MNG stream" in stdout + def process_error(self, stdout: str, stderr: str) -> str: + """Process the stderr.""" + if "this is neither a PNG or JNG image nor a MNG stream" in stdout: + return "The file format of the file is not supported (PNG or JNG only)." + return stdout def analyze_pngcheck(input_img: Path, output_dir: Path) -> None: """Analyze an image submission using pngcheck.""" diff --git a/aperisolve/analyzers/steghide.py b/aperisolve/analyzers/steghide.py index 0454e13..2f3058a 100644 --- a/aperisolve/analyzers/steghide.py +++ b/aperisolve/analyzers/steghide.py @@ -36,16 +36,19 @@ class SteghideAnalyzer(SubprocessAnalyzer): def is_error(self, returncode: int, stdout: str, stderr: str, zip_exist: bool) -> bool: """Check if the result is an error.""" - match = re.search(r'embedded file "([^"]+)"', stdout) + match = re.search(r'embedded file "([^"]+)".*', stdout + stderr) embedded_filename = match.group(1) if match else None + match = re.search(r'wrote extracted data to "([^"]+)".*', stdout + stderr) + extracted_filename = match.group(1) if match else None + # if bad file format or wrong password, raise an error - return returncode != 0 or embedded_filename is None + return embedded_filename is None and extracted_filename is None def process_output(self, stdout: str, stderr: str) -> str | list[str] | dict[str, str]: """Process the stdout into a list of lines.""" out = [] - for line in stderr.split("\n"): + for line in (stdout + '\n' + stderr).split("\n"): if line.startswith('wrote extracted data to "'): out.append(line) return out @@ -54,11 +57,7 @@ class SteghideAnalyzer(SubprocessAnalyzer): """Process stderr.""" if "the file format of the file" in stderr and "not supported" in stderr: return "The file format of the file is not supported (JPEG or BMP only)." - out = "" - for line in stderr.split("\n"): - if line and not line.startswith('wrote extracted data to "'): - out += line + "\n" - return out + return stderr def analyze_steghide(input_img: Path, output_dir: Path, password: Optional[str] = None) -> None: