Skip to content

Commit

Permalink
Merge pull request #6 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
2.0.0
AngheloAlf authored Aug 1, 2023
2 parents c8fd532 + 2f15e42 commit ff70076
Showing 15 changed files with 456 additions and 228 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ The list can be checked in runtime with `python3 -m mapfile_parser --help`.
Each one of them can be executed with `python3 -m mapfile_parser utilityname`, for example `python3 -m mapfile_parser pj64_syms`.

- `first_diff`: Find the first difference(s) between the built ROM and the base ROM.
- `jsonify`: Converts a mapfile into a json format.
- `pj64_syms`: Produce a PJ64 compatible symbol map.
- `progress`: Computes current progress of the matched functions. Relies on a [splat](https://github.com/ethteck/splat) folder structure and matched functions not longer having a file.
- `sym_info`: Display various information about a symbol or address.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

[project]
name = "mapfile_parser"
version = "1.2.1"
version = "2.0.0"
description = "Map file parser library focusing decompilation projects"
readme = "README.md"
requires-python = ">=3.7"
17 changes: 10 additions & 7 deletions src/mapfile_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations

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

from . import utils
from . import utils as utils

from .mapfile import MapFile
from .mapfile import Symbol, File, FoundSymbolInfo
from .mapfile import MapFile as MapFile
from .mapfile import Symbol as Symbol
from .mapfile import File as File
from .mapfile import Segment as Segment
from .mapfile import FoundSymbolInfo as FoundSymbolInfo

from .progress_stats import ProgressStats
from .progress_stats import ProgressStats as ProgressStats

from . import frontends
from . import frontends as frontends
3 changes: 2 additions & 1 deletion src/mapfile_parser/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations
@@ -16,6 +16,7 @@ def mapfileParserMain():
subparsers = parser.add_subparsers(description="action", help="the action to perform", required=True)

mapfile_parser.frontends.first_diff.addSubparser(subparsers)
mapfile_parser.frontends.jsonify.addSubparser(subparsers)
mapfile_parser.frontends.pj64_syms.addSubparser(subparsers)
mapfile_parser.frontends.progress.addSubparser(subparsers)
mapfile_parser.frontends.sym_info.addSubparser(subparsers)
15 changes: 8 additions & 7 deletions src/mapfile_parser/frontends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations


from . import first_diff
from . import pj64_syms
from . import progress
from . import sym_info
from . import symbol_sizes_csv
from . import upload_frogress
from . import first_diff as first_diff
from . import jsonify as jsonify
from . import pj64_syms as pj64_syms
from . import progress as progress
from . import sym_info as sym_info
from . import symbol_sizes_csv as symbol_sizes_csv
from . import upload_frogress as upload_frogress
2 changes: 1 addition & 1 deletion src/mapfile_parser/frontends/first_diff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations
42 changes: 42 additions & 0 deletions src/mapfile_parser/frontends/jsonify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations

import argparse
import json
from pathlib import Path

from .. import mapfile


def doJsonify(mapPath: Path, outputPath: Path|None) -> int:
mapFile = mapfile.MapFile()
mapFile.readMapFile(mapPath)

jsonStr = json.dumps(mapFile.toJson(), indent=4)

if outputPath is None:
print(jsonStr)
else:
outputPath.parent.mkdir(parents=True, exist_ok=True)
outputPath.write_text(jsonStr)

return 0


def processArguments(args: argparse.Namespace):
mapPath: Path = args.mapfile
outputPath: Path|None = Path(args.output) if args.output is not None else None

exit(doJsonify(mapPath, outputPath))

def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]):
parser = subparser.add_parser("jsonify", help="Converts a mapfile into a json format.")

parser.add_argument("mapfile", help="Path to a map file", type=Path)
parser.add_argument("-o", "--output", help="Output path of for the generated json. If omitted then stdout is used instead.")

parser.set_defaults(func=processArguments)
11 changes: 6 additions & 5 deletions src/mapfile_parser/frontends/pj64_syms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations
@@ -14,10 +14,11 @@


def writePj64SymsToFile(mapFile: mapfile.MapFile, outFile: TextIO):
for file in mapFile:
for sym in file:
symType = "code" if file.segmentType == ".text" else "data"
outFile.write(f"{sym.vram:08X},{symType},{sym.name}\n")
for segment in mapFile:
for file in segment:
for sym in file:
symType = "code" if file.sectionType == ".text" else "data"
outFile.write(f"{sym.vram:08X},{symType},{sym.name}\n")

def doPj64Syms(mapPath: Path, outputPath: Path|None) -> int:
mapFile = mapfile.MapFile()
4 changes: 2 additions & 2 deletions src/mapfile_parser/frontends/progress.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations
@@ -18,7 +18,7 @@ def getProgress(mapPath: Path, asmPath: Path, nonmatchingsPath: Path, pathIndex:
mapFile.debugging = debugging
mapFile.readMapFile(mapPath)

return mapFile.filterBySegmentType(".text").getProgress(asmPath, nonmatchingsPath, pathIndex=pathIndex)
return mapFile.filterBySectionType(".text").getProgress(asmPath, nonmatchingsPath, pathIndex=pathIndex)

def doProgress(mapPath: Path, asmPath: Path, nonmatchingsPath: Path, pathIndex: int=2, debugging: bool=False) -> int:
totalStats, progressPerFolder = getProgress(mapPath, asmPath, nonmatchingsPath, pathIndex=pathIndex, debugging=debugging)
2 changes: 1 addition & 1 deletion src/mapfile_parser/frontends/sym_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations
4 changes: 2 additions & 2 deletions src/mapfile_parser/frontends/symbol_sizes_csv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations
@@ -15,7 +15,7 @@ def processArguments(args: argparse.Namespace):
mapFile = mapfile.MapFile()
mapFile.readMapFile(args.mapfile)
if args.filter_section is not None:
mapFile = mapFile.filterBySegmentType(args.filter_section)
mapFile = mapFile.filterBySectionType(args.filter_section)

if args.same_folder:
mapFile = mapFile.mixFolders()
2 changes: 1 addition & 1 deletion src/mapfile_parser/frontends/upload_frogress.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2022 Decompollaborate
# SPDX-FileCopyrightText: © 2022-2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations
Loading

0 comments on commit ff70076

Please sign in to comment.