diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ae0c94..2f738ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `endian` argument to `doFirstDiff`. +- Add `--endian` option to `first_diff` script. + ## [2.3.7] - 2024-02-27 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index 0c43567..3841809 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "mapfile_parser" -version = "2.3.7" +version = "2.3.8" edition = "2021" authors = ["Anghelo Carvajal "] description = "Map file parser library focusing decompilation projects" diff --git a/README.md b/README.md index 14da536..4b36908 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ If you use a `requirements.txt` file in your repository, then you can add this library with the following line: ```txt -mapfile_parser>=2.3.7,<3.0.0 +mapfile_parser>=2.3.8,<3.0.0 ``` #### Development version @@ -74,7 +74,7 @@ cargo add mapfile_parser Or add the following line manually to your `Cargo.toml` file: ```toml -mapfile_parser = "2.3.5" +mapfile_parser = "2.3.8" ``` ## Versioning and changelog diff --git a/pyproject.toml b/pyproject.toml index c03e756..fb57d91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ [project] name = "mapfile_parser" -version = "2.3.7" +version = "2.3.8" description = "Map file parser library focusing decompilation projects" readme = "README.md" requires-python = ">=3.7" diff --git a/src/mapfile_parser/__init__.py b/src/mapfile_parser/__init__.py index f60efd7..55816c3 100644 --- a/src/mapfile_parser/__init__.py +++ b/src/mapfile_parser/__init__.py @@ -5,7 +5,7 @@ from __future__ import annotations -__version_info__ = (2, 3, 7) +__version_info__ = (2, 3, 8) __version__ = ".".join(map(str, __version_info__)) __author__ = "Decompollaborate" diff --git a/src/mapfile_parser/frontends/first_diff.py b/src/mapfile_parser/frontends/first_diff.py index c00f6b5..4480bd4 100644 --- a/src/mapfile_parser/frontends/first_diff.py +++ b/src/mapfile_parser/frontends/first_diff.py @@ -7,13 +7,13 @@ import argparse from pathlib import Path -from typing import Callable +from typing import Callable, Literal from .. import mapfile from .. import utils -def doFirstDiff(mapPath: Path, expectedMapPath: Path, romPath: Path, expectedRomPath: Path, diffCount: int=5, mismatchSize: bool=False, addColons: bool=True, bytesConverterCallback:Callable[[bytes, mapfile.MapFile],str|None]|None=None) -> int: +def doFirstDiff(mapPath: Path, expectedMapPath: Path, romPath: Path, expectedRomPath: Path, diffCount: int=5, mismatchSize: bool=False, addColons: bool=True, bytesConverterCallback:Callable[[bytes, mapfile.MapFile],str|None]|None=None, endian: Literal["big", "little"] ="big") -> int: if not mapPath.exists(): print(f"{mapPath} must exist") return 1 @@ -45,6 +45,10 @@ def doFirstDiff(mapPath: Path, expectedMapPath: Path, romPath: Path, expectedRom expectedMapFile = mapfile.MapFile() expectedMapFile.readMapFile(expectedMapPath) + endian_diff = 0 + if endian == "little": + endian_diff = 3 + map_search_diff: set[str] = set() diffs = 0 shift_cap = 1000 @@ -74,7 +78,7 @@ def doFirstDiff(mapPath: Path, expectedMapPath: Path, romPath: Path, expectedRom if ( len(map_search_diff) < diffCount - and builtRom[i] >> 2 != expectedRom[i] >> 2 + and builtRom[i+endian_diff] >> 2 != expectedRom[i+endian_diff] >> 2 ): vromInfo = builtMapFile.findSymbolByVramOrVrom(i) if vromInfo is not None: @@ -133,7 +137,9 @@ def processArguments(args: argparse.Namespace): diffCount: int = args.count mismatchSize: bool = args.mismatch_size - exit(doFirstDiff(mapPath, expectedMapPath, romPath, expectedRomPath, diffCount, mismatchSize)) + endian = args.endian + + exit(doFirstDiff(mapPath, expectedMapPath, romPath, expectedRomPath, diffCount, mismatchSize, endian=endian)) def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]): @@ -146,5 +152,6 @@ def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]) parser.add_argument("-c", "--count", type=int, default=5, help="find up to this many instruction difference(s)") parser.add_argument("-m", "--mismatch-size", help="Do not exit early if the ROM sizes does not match", action="store_true") + parser.add_argument("-e", "--endian", help="Specify endianness of the binary", choices=["big", "little"], default="big") parser.set_defaults(func=processArguments)