Skip to content

Commit

Permalink
Add endian to first_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Mar 25, 2024
1 parent ded5b55 commit b2de35d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "mapfile_parser"
version = "2.3.7"
version = "2.3.8"
edition = "2021"
authors = ["Anghelo Carvajal <angheloalf95@gmail.com>"]
description = "Map file parser library focusing decompilation projects"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/mapfile_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
15 changes: 11 additions & 4 deletions src/mapfile_parser/frontends/first_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]):
Expand All @@ -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)

0 comments on commit b2de35d

Please sign in to comment.