Skip to content

Commit

Permalink
Tweak symbol comparison logic a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Jul 18, 2024
1 parent c478ac1 commit 1d17580
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Tweak symbol comparison logic a bit.
- Symbol shifting (due to different sizes or extra/missing symbols) should
not affect comparing non shifted files.

## [2.4.0] - 2024-03-25

### Added
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.4.0"
version = "2.4.1-dev0"
edition = "2021"
authors = ["Anghelo Carvajal <angheloalf95@gmail.com>"]
description = "Map file parser library focusing decompilation projects"
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.4.0"
version = "2.4.1-dev0"
description = "Map file parser library focusing decompilation projects"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
4 changes: 2 additions & 2 deletions src/mapfile_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from __future__ import annotations

__version_info__ = (2, 4, 0)
__version__ = ".".join(map(str, __version_info__))
__version_info__ = (2, 4, 1)
__version__ = ".".join(map(str, __version_info__)) + "-dev0"
__author__ = "Decompollaborate"

from . import utils as utils
Expand Down
24 changes: 20 additions & 4 deletions src/mapfile_parser/mapfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,23 @@ class SymbolComparisonInfo:
buildFile: File|None
expectedAddress: int
expectedFile: File|None
diff: int|None

@property
def diff(self) -> int|None:
if self.buildAddress < 0:
return None
if self.expectedAddress < 0:
return None

buildAddress = self.buildAddress
expectedAddress = self.expectedAddress

if self.buildFile is not None and self.expectedFile is not None:
buildAddress = buildAddress - self.buildFile.vram
expectedAddress = expectedAddress - self.expectedFile.vram

return buildAddress - expectedAddress


class MapsComparisonInfo:
def __init__(self):
Expand Down Expand Up @@ -695,13 +711,13 @@ def compareFilesAndSymbols(self, otherMapFile: MapFile, *, checkOtherOnSelf: boo
for symbol in file:
foundSymInfo = otherMapFile.findSymbolByName(symbol.name)
if foundSymInfo is not None:
comp = SymbolComparisonInfo(symbol, symbol.vram, file, foundSymInfo.symbol.vram, foundSymInfo.file, symbol.vram - foundSymInfo.symbol.vram)
comp = SymbolComparisonInfo(symbol, symbol.vram, file, foundSymInfo.symbol.vram, foundSymInfo.file)
compInfo.comparedList.append(comp)
if comp.diff != 0:
compInfo.badFiles.add(file)
else:
compInfo.missingFiles.add(file)
compInfo.comparedList.append(SymbolComparisonInfo(symbol, symbol.vram, file, -1, None, None))
compInfo.comparedList.append(SymbolComparisonInfo(symbol, symbol.vram, file, -1, None))

if checkOtherOnSelf:
for segment in otherMapFile:
Expand All @@ -710,7 +726,7 @@ def compareFilesAndSymbols(self, otherMapFile: MapFile, *, checkOtherOnSelf: boo
foundSymInfo = self.findSymbolByName(symbol.name)
if foundSymInfo is None:
compInfo.missingFiles.add(file)
compInfo.comparedList.append(SymbolComparisonInfo(symbol, -1, None, symbol.vram, file, None))
compInfo.comparedList.append(SymbolComparisonInfo(symbol, -1, None, symbol.vram, file))

return compInfo

Expand Down

0 comments on commit 1d17580

Please sign in to comment.