Skip to content

Commit

Permalink
Merge pull request #33 from Decompollaborate/develop
Browse files Browse the repository at this point in the history
2.7.1
  • Loading branch information
AngheloAlf committed Sep 25, 2024
2 parents 5f57c95 + 847c4fb commit 26810c2
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 111 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.7.1] - 2024-09-25

### Added

- Add `--json` flag to `progress` frontend.
- Prints the output as json instead of using a human readable format.

### Changed

- Improve lifetime usage and avoid unnecessary clones on Rust side.

## [2.7.0] - 2024-09-24

### Added
Expand Down Expand Up @@ -415,6 +426,7 @@ Full changes: <https://github.com/Decompollaborate/mapfile_parser/compare/702a73
- Initial release

[unreleased]: https://github.com/Decompollaborate/mapfile_parser/compare/master...develop
[2.7.1]: https://github.com/Decompollaborate/mapfile_parser/compare/2.7.0...2.7.1
[2.7.0]: https://github.com/Decompollaborate/mapfile_parser/compare/2.6.0...2.7.0
[2.6.0]: https://github.com/Decompollaborate/mapfile_parser/compare/2.5.1...2.6.0
[2.5.1]: https://github.com/Decompollaborate/mapfile_parser/compare/2.5.0...2.5.1
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.7.0"
version = "2.7.1"
edition = "2021"
rust-version = "1.65.0"
authors = ["Anghelo Carvajal <[email protected]>"]
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.7.0,<3.0.0
mapfile_parser>=2.7.1,<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.7.0"
mapfile_parser = "2.7.1"
```

## 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.7.0"
version = "2.7.1"
description = "Map file parser library focusing decompilation projects"
readme = "README.md"
requires-python = ">=3.8"
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, 7, 0)
__version_info__ = (2, 7, 1)
__version__ = ".".join(map(str, __version_info__))# + "-dev0"
__author__ = "Decompollaborate"

Expand Down
17 changes: 14 additions & 3 deletions src/mapfile_parser/frontends/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

import argparse
import json
from pathlib import Path

from .. import mapfile
Expand All @@ -20,14 +21,22 @@ def getProgress(mapPath: Path, asmPath: Path, nonmatchingsPath: Path, pathIndex:

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

def doProgress(mapPath: Path, asmPath: Path, nonmatchingsPath: Path, pathIndex: int=2, checkFunctionFiles: bool=True, debugging: bool=False) -> int:
def doProgress(mapPath: Path, asmPath: Path, nonmatchingsPath: Path, pathIndex: int=2, checkFunctionFiles: bool=True, print_json: bool=False, debugging: bool=False) -> int:
if not mapPath.exists():
print(f"Could not find mapfile at '{mapPath}'")
return 1

totalStats, progressPerFolder = getProgress(mapPath, asmPath, nonmatchingsPath, pathIndex=pathIndex, checkFunctionFiles=checkFunctionFiles, debugging=debugging)

progress_stats.printStats(totalStats, progressPerFolder)
if print_json:
json_temp: dict[str, dict[str, int|float]] = {
"all": totalStats.asJsonEntry()
}
for folder, statsEntry in progressPerFolder.items():
json_temp[folder] = statsEntry.asJsonEntry()
print(json.dumps(json_temp, indent=4))
else:
progress_stats.printStats(totalStats, progressPerFolder)
return 0


Expand All @@ -38,8 +47,9 @@ def processArguments(args: argparse.Namespace):
pathIndex: int = args.path_index
checkFunctionFiles: bool = not args.avoid_function_files
debugging: bool = args.debugging #! @deprecated
print_json: bool = args.json

exit(doProgress(mapPath, asmPath, nonmatchingsPath, pathIndex=pathIndex, checkFunctionFiles=checkFunctionFiles, debugging=debugging))
exit(doProgress(mapPath, asmPath, nonmatchingsPath, pathIndex=pathIndex, checkFunctionFiles=checkFunctionFiles, print_json=print_json, debugging=debugging))

def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]):
parser = subparser.add_parser("progress", help="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.")
Expand All @@ -50,5 +60,6 @@ def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser])
parser.add_argument("-i", "--path-index", help="Specify the index to start reading the file paths. Defaults to 2", type=int, default=2)
parser.add_argument("-f", "--avoid-function-files", help="Avoid checking if the assembly file for a function exists as a way to determine if the function has been matched or not", action="store_true")
parser.add_argument("-d", "--debugging", help="Enable debugging prints. This option is deprecated", action="store_true")
parser.add_argument("-j", "--json", help="Print the stats as json instead of a human readable format.", action="store_true")

parser.set_defaults(func=processArguments)
7 changes: 7 additions & 0 deletions src/mapfile_parser/progress_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ def getEntryAsStr(self, category: str, totalStats: ProgressStats, categoryColumn
def print(self, category: str, totalStats: ProgressStats, categoryColumnSize: int=28):
print(self.getEntryAsStr(category, totalStats, categoryColumnSize=categoryColumnSize))

def asJsonEntry(self) -> dict[str, int|float]:
return {
"decomped": self.decompedSize,
"total": self.total,
"percentage": round(self.decompedPercentage(), 4)
}


def printStats(totalStats: ProgressStats, progressPerFolder: dict[str, ProgressStats]):
ProgressStats.printHeader()
Expand Down
54 changes: 39 additions & 15 deletions src/rs/found_symbol_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@
use crate::{file, symbol};
use std::fmt::Write;

#[cfg(feature = "python_bindings")]
use pyo3::prelude::*;

#[derive(Debug, Clone)]
#[cfg_attr(feature = "python_bindings", pyclass(module = "mapfile_parser"))]
pub struct FoundSymbolInfo {
pub file: file::File,
pub struct FoundSymbolInfo<'a> {
pub file: &'a file::File,

pub symbol: symbol::Symbol,
pub symbol: &'a symbol::Symbol,

pub offset: i64,
}

impl FoundSymbolInfo {
pub fn new(file: file::File, symbol: symbol::Symbol, offset: i64) -> Self {
impl<'a> FoundSymbolInfo<'a> {
pub fn new(file: &'a file::File, symbol: &'a symbol::Symbol, offset: i64) -> Self {
Self {
file,
symbol,
offset,
}
}

pub fn new_default(file: file::File, symbol: symbol::Symbol) -> Self {
pub fn new_default(file: &'a file::File, symbol: &'a symbol::Symbol) -> Self {
Self {
file,
symbol,
Expand Down Expand Up @@ -70,12 +66,26 @@ pub(crate) mod python_bindings {

use crate::{file, symbol};

#[derive(Debug, Clone)]
#[pyclass(module = "mapfile_parser", name = "FoundSymbolInfo")]
pub struct PyFoundSymbolInfo {
pub file: file::File,

pub symbol: symbol::Symbol,

pub offset: i64,
}

#[pymethods]
impl super::FoundSymbolInfo {
impl PyFoundSymbolInfo {
#[new]
#[pyo3(signature=(file, symbol, offset=0))]
fn py_new(file: file::File, symbol: symbol::Symbol, offset: i64) -> Self {
Self::new(file, symbol, offset)
fn new(file: file::File, symbol: symbol::Symbol, offset: i64) -> Self {
Self {
file,
symbol,
offset,
}
}

/* Getters and setters */
Expand Down Expand Up @@ -117,12 +127,26 @@ pub(crate) mod python_bindings {

#[pyo3(name = "getAsStr")]
fn getAsStr(&self) -> String {
self.get_as_str()
let temp = super::FoundSymbolInfo::from(self);
temp.get_as_str()
}

#[pyo3(name = "getAsStrPlusOffset")]
fn getAsStrPlusOffset(&self, sym_name: Option<String>) -> String {
self.get_as_str_plus_offset(sym_name)
let temp = super::FoundSymbolInfo::from(self);
temp.get_as_str_plus_offset(sym_name)
}
}

impl<'a> From<&'a PyFoundSymbolInfo> for super::FoundSymbolInfo<'a> {
fn from(value: &'a PyFoundSymbolInfo) -> Self {
Self::new(&value.file, &value.symbol, value.offset)
}
}

impl<'a> From<super::FoundSymbolInfo<'a>> for PyFoundSymbolInfo {
fn from(value: super::FoundSymbolInfo) -> Self {
Self::new(value.file.clone(), value.symbol.clone(), value.offset)
}
}
}
6 changes: 3 additions & 3 deletions src/rs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ fn mapfile_parser(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<segment::Segment>()?;
m.add_class::<file::File>()?;
m.add_class::<symbol::Symbol>()?;
m.add_class::<found_symbol_info::FoundSymbolInfo>()?;
m.add_class::<symbol_comparison_info::SymbolComparisonInfo>()?;
m.add_class::<maps_comparison_info::MapsComparisonInfo>()?;
m.add_class::<found_symbol_info::python_bindings::PyFoundSymbolInfo>()?;
m.add_class::<symbol_comparison_info::python_bindings::PySymbolComparisonInfo>()?;
m.add_class::<maps_comparison_info::python_bindings::PyMapsComparisonInfo>()?;
m.add_class::<progress_stats::ProgressStats>()?;
Ok(())
}
Expand Down
Loading

0 comments on commit 26810c2

Please sign in to comment.