Skip to content

Commit 26810c2

Browse files
authored
Merge pull request #33 from Decompollaborate/develop
2.7.1
2 parents 5f57c95 + 847c4fb commit 26810c2

14 files changed

Lines changed: 283 additions & 111 deletions

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [2.7.1] - 2024-09-25
11+
12+
### Added
13+
14+
- Add `--json` flag to `progress` frontend.
15+
- Prints the output as json instead of using a human readable format.
16+
17+
### Changed
18+
19+
- Improve lifetime usage and avoid unnecessary clones on Rust side.
20+
1021
## [2.7.0] - 2024-09-24
1122

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

417428
[unreleased]: https://github.com/Decompollaborate/mapfile_parser/compare/master...develop
429+
[2.7.1]: https://github.com/Decompollaborate/mapfile_parser/compare/2.7.0...2.7.1
418430
[2.7.0]: https://github.com/Decompollaborate/mapfile_parser/compare/2.6.0...2.7.0
419431
[2.6.0]: https://github.com/Decompollaborate/mapfile_parser/compare/2.5.1...2.6.0
420432
[2.5.1]: https://github.com/Decompollaborate/mapfile_parser/compare/2.5.0...2.5.1

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[package]
55
name = "mapfile_parser"
6-
version = "2.7.0"
6+
version = "2.7.1"
77
edition = "2021"
88
rust-version = "1.65.0"
99
authors = ["Anghelo Carvajal <angheloalf95@gmail.com>"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ If you use a `requirements.txt` file in your repository, then you can add
3535
this library with the following line:
3636

3737
```txt
38-
mapfile_parser>=2.7.0,<3.0.0
38+
mapfile_parser>=2.7.1,<3.0.0
3939
```
4040

4141
#### Development version
@@ -74,7 +74,7 @@ cargo add mapfile_parser
7474
Or add the following line manually to your `Cargo.toml` file:
7575

7676
```toml
77-
mapfile_parser = "2.7.0"
77+
mapfile_parser = "2.7.1"
7878
```
7979

8080
## Versioning and changelog

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[project]
55
name = "mapfile_parser"
6-
version = "2.7.0"
6+
version = "2.7.1"
77
description = "Map file parser library focusing decompilation projects"
88
readme = "README.md"
99
requires-python = ">=3.8"

src/mapfile_parser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
__version_info__ = (2, 7, 0)
8+
__version_info__ = (2, 7, 1)
99
__version__ = ".".join(map(str, __version_info__))# + "-dev0"
1010
__author__ = "Decompollaborate"
1111

src/mapfile_parser/frontends/progress.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import annotations
77

88
import argparse
9+
import json
910
from pathlib import Path
1011

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

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

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

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

30-
progress_stats.printStats(totalStats, progressPerFolder)
31+
if print_json:
32+
json_temp: dict[str, dict[str, int|float]] = {
33+
"all": totalStats.asJsonEntry()
34+
}
35+
for folder, statsEntry in progressPerFolder.items():
36+
json_temp[folder] = statsEntry.asJsonEntry()
37+
print(json.dumps(json_temp, indent=4))
38+
else:
39+
progress_stats.printStats(totalStats, progressPerFolder)
3140
return 0
3241

3342

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

42-
exit(doProgress(mapPath, asmPath, nonmatchingsPath, pathIndex=pathIndex, checkFunctionFiles=checkFunctionFiles, debugging=debugging))
52+
exit(doProgress(mapPath, asmPath, nonmatchingsPath, pathIndex=pathIndex, checkFunctionFiles=checkFunctionFiles, print_json=print_json, debugging=debugging))
4353

4454
def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser]):
4555
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.")
@@ -50,5 +60,6 @@ def addSubparser(subparser: argparse._SubParsersAction[argparse.ArgumentParser])
5060
parser.add_argument("-i", "--path-index", help="Specify the index to start reading the file paths. Defaults to 2", type=int, default=2)
5161
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")
5262
parser.add_argument("-d", "--debugging", help="Enable debugging prints. This option is deprecated", action="store_true")
63+
parser.add_argument("-j", "--json", help="Print the stats as json instead of a human readable format.", action="store_true")
5364

5465
parser.set_defaults(func=processArguments)

src/mapfile_parser/progress_stats.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def getEntryAsStr(self, category: str, totalStats: ProgressStats, categoryColumn
5151
def print(self, category: str, totalStats: ProgressStats, categoryColumnSize: int=28):
5252
print(self.getEntryAsStr(category, totalStats, categoryColumnSize=categoryColumnSize))
5353

54+
def asJsonEntry(self) -> dict[str, int|float]:
55+
return {
56+
"decomped": self.decompedSize,
57+
"total": self.total,
58+
"percentage": round(self.decompedPercentage(), 4)
59+
}
60+
5461

5562
def printStats(totalStats: ProgressStats, progressPerFolder: dict[str, ProgressStats]):
5663
ProgressStats.printHeader()

src/rs/found_symbol_info.rs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,25 @@
44
use crate::{file, symbol};
55
use std::fmt::Write;
66

7-
#[cfg(feature = "python_bindings")]
8-
use pyo3::prelude::*;
9-
107
#[derive(Debug, Clone)]
11-
#[cfg_attr(feature = "python_bindings", pyclass(module = "mapfile_parser"))]
12-
pub struct FoundSymbolInfo {
13-
pub file: file::File,
8+
pub struct FoundSymbolInfo<'a> {
9+
pub file: &'a file::File,
1410

15-
pub symbol: symbol::Symbol,
11+
pub symbol: &'a symbol::Symbol,
1612

1713
pub offset: i64,
1814
}
1915

20-
impl FoundSymbolInfo {
21-
pub fn new(file: file::File, symbol: symbol::Symbol, offset: i64) -> Self {
16+
impl<'a> FoundSymbolInfo<'a> {
17+
pub fn new(file: &'a file::File, symbol: &'a symbol::Symbol, offset: i64) -> Self {
2218
Self {
2319
file,
2420
symbol,
2521
offset,
2622
}
2723
}
2824

29-
pub fn new_default(file: file::File, symbol: symbol::Symbol) -> Self {
25+
pub fn new_default(file: &'a file::File, symbol: &'a symbol::Symbol) -> Self {
3026
Self {
3127
file,
3228
symbol,
@@ -70,12 +66,26 @@ pub(crate) mod python_bindings {
7066

7167
use crate::{file, symbol};
7268

69+
#[derive(Debug, Clone)]
70+
#[pyclass(module = "mapfile_parser", name = "FoundSymbolInfo")]
71+
pub struct PyFoundSymbolInfo {
72+
pub file: file::File,
73+
74+
pub symbol: symbol::Symbol,
75+
76+
pub offset: i64,
77+
}
78+
7379
#[pymethods]
74-
impl super::FoundSymbolInfo {
80+
impl PyFoundSymbolInfo {
7581
#[new]
7682
#[pyo3(signature=(file, symbol, offset=0))]
77-
fn py_new(file: file::File, symbol: symbol::Symbol, offset: i64) -> Self {
78-
Self::new(file, symbol, offset)
83+
fn new(file: file::File, symbol: symbol::Symbol, offset: i64) -> Self {
84+
Self {
85+
file,
86+
symbol,
87+
offset,
88+
}
7989
}
8090

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

118128
#[pyo3(name = "getAsStr")]
119129
fn getAsStr(&self) -> String {
120-
self.get_as_str()
130+
let temp = super::FoundSymbolInfo::from(self);
131+
temp.get_as_str()
121132
}
122133

123134
#[pyo3(name = "getAsStrPlusOffset")]
124135
fn getAsStrPlusOffset(&self, sym_name: Option<String>) -> String {
125-
self.get_as_str_plus_offset(sym_name)
136+
let temp = super::FoundSymbolInfo::from(self);
137+
temp.get_as_str_plus_offset(sym_name)
138+
}
139+
}
140+
141+
impl<'a> From<&'a PyFoundSymbolInfo> for super::FoundSymbolInfo<'a> {
142+
fn from(value: &'a PyFoundSymbolInfo) -> Self {
143+
Self::new(&value.file, &value.symbol, value.offset)
144+
}
145+
}
146+
147+
impl<'a> From<super::FoundSymbolInfo<'a>> for PyFoundSymbolInfo {
148+
fn from(value: super::FoundSymbolInfo) -> Self {
149+
Self::new(value.file.clone(), value.symbol.clone(), value.offset)
126150
}
127151
}
128152
}

src/rs/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ fn mapfile_parser(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
3333
m.add_class::<segment::Segment>()?;
3434
m.add_class::<file::File>()?;
3535
m.add_class::<symbol::Symbol>()?;
36-
m.add_class::<found_symbol_info::FoundSymbolInfo>()?;
37-
m.add_class::<symbol_comparison_info::SymbolComparisonInfo>()?;
38-
m.add_class::<maps_comparison_info::MapsComparisonInfo>()?;
36+
m.add_class::<found_symbol_info::python_bindings::PyFoundSymbolInfo>()?;
37+
m.add_class::<symbol_comparison_info::python_bindings::PySymbolComparisonInfo>()?;
38+
m.add_class::<maps_comparison_info::python_bindings::PyMapsComparisonInfo>()?;
3939
m.add_class::<progress_stats::ProgressStats>()?;
4040
Ok(())
4141
}

0 commit comments

Comments
 (0)