Skip to content

Commit

Permalink
Merge pull request #4 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
1.2.0
  • Loading branch information
AngheloAlf committed Jul 28, 2023
2 parents 9e413ac + ea02ca9 commit 95c6849
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
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 = "1.1.5"
version = "1.2.0"
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__ = (1, 1, 5)
__version_info__ = (1, 2, 0)
__version__ = ".".join(map(str, __version_info__))
__author__ = "Decompollaborate"

Expand Down
21 changes: 18 additions & 3 deletions src/mapfile_parser/frontends/first_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

import argparse
from pathlib import Path
from typing import Callable

from .. import mapfile
from .. import utils


def doFirstDiff(mapPath: Path, expectedMapPath: Path, romPath: Path, expectedRomPath: Path, diffCount: int=5, mismatchSize: bool=False) -> 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) -> int:
if not mapPath.exists():
print(f"{mapPath} must exist")
return 1
Expand Down Expand Up @@ -61,7 +62,14 @@ def doFirstDiff(mapPath: Path, expectedMapPath: Path, romPath: Path, expectedRom
if vromInfo is not None:
extraMessage = f", {vromInfo.getAsStrPlusOffset()}"
print(f"First difference at ROM addr 0x{i:X}{extraMessage}")
print(f"Bytes: {utils.hexbytes(builtRom[i : i + 4])} vs {utils.hexbytes(expectedRom[i : i + 4])}")
builtBytes = builtRom[i : i + 4]
expectedBytes = expectedRom[i : i + 4]
print(f"Bytes: {utils.hexbytes(builtBytes, addColons=addColons)} vs {utils.hexbytes(expectedBytes, addColons=addColons)}")
if bytesConverterCallback is not None:
builtConverted = bytesConverterCallback(builtBytes, builtMapFile)
expectedConverted = bytesConverterCallback(expectedBytes, expectedMapFile)
if builtConverted is not None and expectedConverted is not None:
print(f"{builtConverted} vs {expectedConverted}")
diffs += 1

if (
Expand All @@ -78,7 +86,14 @@ def doFirstDiff(mapPath: Path, expectedMapPath: Path, romPath: Path, expectedRom
if vromInfo is not None:
extraMessage = f", {vromInfo.getAsStrPlusOffset()}"
print(f"Instruction difference at ROM addr 0x{i:X}{extraMessage}")
print(f"Bytes: {utils.hexbytes(builtRom[i : i + 4])} vs {utils.hexbytes(expectedRom[i : i + 4])}")
builtBytes = builtRom[i : i + 4]
expectedBytes = expectedRom[i : i + 4]
print(f"Bytes: {utils.hexbytes(builtBytes, addColons=addColons)} vs {utils.hexbytes(expectedBytes, addColons=addColons)}")
if bytesConverterCallback is not None:
builtConverted = bytesConverterCallback(builtBytes, builtMapFile)
expectedConverted = bytesConverterCallback(expectedBytes, expectedMapFile)
if builtConverted is not None and expectedConverted is not None:
print(f"{builtConverted} vs {expectedConverted}")

if len(map_search_diff) >= diffCount and diffs > shift_cap:
break
Expand Down
7 changes: 5 additions & 2 deletions src/mapfile_parser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ def readFileAsBytearray(filepath: Path) -> bytearray:
with filepath.open(mode="rb") as f:
return bytearray(f.read())

def hexbytes(bs):
return ":".join("{:02X}".format(c) for c in bs)
def hexbytes(bs: bytes, addColons: bool=True) -> str:
glue = ""
if addColons:
glue = ""
return glue.join("{:02X}".format(c) for c in bs)

def getGitCommitTimestamp() -> int:
return int(subprocess.check_output(['git', 'show', '-s', '--format=%ct']).decode('ascii').rstrip())
Expand Down

0 comments on commit 95c6849

Please sign in to comment.