CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
99 lines
2.6 KiB
Python
99 lines
2.6 KiB
Python
"""
|
|
Common verification utilities for binary formats.
|
|
|
|
This module provides the base VerificationResult class and BinaryVerifier
|
|
abstract base class that ELF and COFF verifiers extend.
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass, field
|
|
from pathlib import Path
|
|
|
|
|
|
@dataclass
|
|
class VerificationResult:
|
|
"""Result of binary verification.
|
|
|
|
Used by both ELF and COFF verifiers to report errors and warnings
|
|
in a consistent format.
|
|
"""
|
|
|
|
passed: bool = True
|
|
errors: list[str] = field(default_factory=list)
|
|
warnings: list[str] = field(default_factory=list)
|
|
|
|
def add_error(self, msg: str) -> None:
|
|
"""Add an error (verification failed)."""
|
|
self.errors.append(msg)
|
|
self.passed = False
|
|
|
|
def add_warning(self, msg: str) -> None:
|
|
"""Add a warning (verification passed but with concerns)."""
|
|
self.warnings.append(msg)
|
|
|
|
def merge(self, other: "VerificationResult") -> None:
|
|
"""Merge another result into this one."""
|
|
if not other.passed:
|
|
self.passed = False
|
|
self.errors.extend(other.errors)
|
|
self.warnings.extend(other.warnings)
|
|
|
|
def __str__(self) -> str:
|
|
"""Human-readable summary."""
|
|
lines = []
|
|
if self.passed:
|
|
lines.append("Verification PASSED")
|
|
else:
|
|
lines.append("Verification FAILED")
|
|
|
|
if self.errors:
|
|
lines.append(f"Errors ({len(self.errors)}):")
|
|
for e in self.errors:
|
|
lines.append(f" - {e}")
|
|
|
|
if self.warnings:
|
|
lines.append(f"Warnings ({len(self.warnings)}):")
|
|
for w in self.warnings:
|
|
lines.append(f" - {w}")
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
|
class BinaryVerifier(ABC):
|
|
"""Abstract base class for binary verifiers.
|
|
|
|
ELF and COFF verifiers extend this to provide format-specific
|
|
structural validation.
|
|
"""
|
|
|
|
@classmethod
|
|
@abstractmethod
|
|
def verify(cls, path: Path) -> VerificationResult:
|
|
"""Verify a binary file on disk.
|
|
|
|
Args:
|
|
path: Path to binary
|
|
|
|
Returns:
|
|
VerificationResult with any errors/warnings
|
|
"""
|
|
...
|
|
|
|
@classmethod
|
|
@abstractmethod
|
|
def verify_data(cls, data: bytes | bytearray) -> VerificationResult:
|
|
"""Verify binary data in memory.
|
|
|
|
Args:
|
|
data: Binary data
|
|
|
|
Returns:
|
|
VerificationResult with any errors/warnings
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
def run_all_checks(self) -> VerificationResult:
|
|
"""Run all internal structural checks."""
|
|
...
|