|
5 | 5 | from pathlib import Path |
6 | 6 |
|
7 | 7 | import lief |
| 8 | +from loguru import logger |
8 | 9 | from omegaconf import DictConfig |
9 | 10 | from rich import print # noqa: A004 |
10 | 11 |
|
@@ -91,6 +92,20 @@ def change_dir_path_to_file_path(path: Path) -> Path | None: |
91 | 92 | return None |
92 | 93 |
|
93 | 94 |
|
| 95 | +def validate_offset(name: str, found_offsets: Mapping[str, list[int]], count: int) -> None: |
| 96 | + """Check one offset.""" |
| 97 | + offsets = found_offsets[name] |
| 98 | + if len(offsets) != count: |
| 99 | + offsets_str = ", ".join(hex(item) for item in offsets) |
| 100 | + logger.warning(f"Found wrong number of offsets for '{name}' pattern: {len(offsets)=}, {offsets_str=}") |
| 101 | + |
| 102 | + |
| 103 | +def validate_offsets(found: Mapping[str, list[int]]) -> None: |
| 104 | + """Check found offsets.""" |
| 105 | + for key in found: |
| 106 | + validate_offset(key, found, 1) |
| 107 | + |
| 108 | + |
94 | 109 | @dataclass |
95 | 110 | class _Config: |
96 | 111 | patterns: Path |
@@ -159,6 +174,7 @@ def process_game_directory(config: DictConfig, path: Path) -> None: # noqa: PLR |
159 | 174 | else: |
160 | 175 | patterns = load_patterns(config.patterns) |
161 | 176 | found = search_offsets(file_path, patterns) |
| 177 | + validate_offsets(found) |
162 | 178 | processed = dict(process_offsets(parsed_binary, patterns, found)) |
163 | 179 | print_offsets(processed) |
164 | 180 | if any(not row for row in processed.values()): |
|
0 commit comments