Skip to content

Commit 2b2117f

Browse files
committed
Check number of found offsets
1 parent 5504dff commit 2b2117f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

search_offsets/search.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66

77
import lief
8+
from loguru import logger
89
from omegaconf import DictConfig
910
from rich import print # noqa: A004
1011

@@ -91,6 +92,20 @@ def change_dir_path_to_file_path(path: Path) -> Path | None:
9192
return None
9293

9394

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+
94109
@dataclass
95110
class _Config:
96111
patterns: Path
@@ -159,6 +174,7 @@ def process_game_directory(config: DictConfig, path: Path) -> None: # noqa: PLR
159174
else:
160175
patterns = load_patterns(config.patterns)
161176
found = search_offsets(file_path, patterns)
177+
validate_offsets(found)
162178
processed = dict(process_offsets(parsed_binary, patterns, found))
163179
print_offsets(processed)
164180
if any(not row for row in processed.values()):

0 commit comments

Comments
 (0)