mirror of
https://github.com/encounter/objdiff.git
synced 2026-07-10 12:18:36 -07:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb9ff4b928 | |||
| 57392daaeb | |||
| 2dd3dd60a8 | |||
| f4757b8d92 | |||
| 52f8c5d4f9 | |||
| 711f40b591 | |||
| 26932b2e44 | |||
| 192a06bc0b | |||
| 5bfa47fce9 | |||
| 1d9b9b6893 | |||
| 6b8e469261 | |||
| bf3ba48539 | |||
| 21cdf268f0 | |||
| 3970bc8acf | |||
| eaf0fabc2d | |||
| 91d11c83d6 | |||
| 94924047b7 | |||
| f5f6869029 | |||
| b02e32f2b7 | |||
| c7a326b160 |
Generated
+821
-511
File diff suppressed because it is too large
Load Diff
+34
-28
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "objdiff"
|
name = "objdiff"
|
||||||
version = "0.3.2"
|
version = "0.5.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.65"
|
rust-version = "1.70"
|
||||||
authors = ["Luke Street <luke@street.dev>"]
|
authors = ["Luke Street <luke@street.dev>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/encounter/objdiff"
|
repository = "https://github.com/encounter/objdiff"
|
||||||
@@ -22,40 +22,46 @@ default = []
|
|||||||
wgpu = ["eframe/wgpu"]
|
wgpu = ["eframe/wgpu"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.75"
|
||||||
bytes = "1.4.0"
|
byteorder = "1.5.0"
|
||||||
|
bytes = "1.5.0"
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
const_format = "0.2.30"
|
const_format = "0.2.31"
|
||||||
cwdemangle = "0.1.5"
|
cwdemangle = "0.1.6"
|
||||||
eframe = { version = "0.21.3", features = ["persistence"] }
|
dirs = "5.0.1"
|
||||||
egui = "0.21.0"
|
eframe = { version = "0.23.0", features = ["persistence"] }
|
||||||
egui_extras = "0.21.0"
|
egui = "0.23.0"
|
||||||
flagset = "0.4.3"
|
egui_extras = "0.23.0"
|
||||||
log = "0.4.17"
|
flagset = "0.4.4"
|
||||||
memmap2 = "0.6.1"
|
globset = { version = "0.4.13", features = ["serde1"] }
|
||||||
notify = "5.1.0"
|
log = "0.4.20"
|
||||||
object = { version = "0.31.1", features = ["read_core", "std", "elf"], default-features = false }
|
memmap2 = "0.9.0"
|
||||||
png = "0.17.8"
|
notify = "6.1.1"
|
||||||
|
object = { version = "0.32.1", features = ["read_core", "std", "elf"], default-features = false }
|
||||||
|
png = "0.17.10"
|
||||||
ppc750cl = { git = "https://github.com/terorie/ppc750cl", rev = "9ae36eef34aa6d74e00972c7671f547a2acfd0aa" }
|
ppc750cl = { git = "https://github.com/terorie/ppc750cl", rev = "9ae36eef34aa6d74e00972c7671f547a2acfd0aa" }
|
||||||
rabbitizer = "1.7.1"
|
rabbitizer = "1.7.10"
|
||||||
rfd = { version = "0.11.3" } #, default-features = false, features = ['xdg-portal']
|
rfd = { version = "0.12.0" } #, default-features = false, features = ['xdg-portal']
|
||||||
|
ron = "0.8.1"
|
||||||
|
semver = "1.0.19"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
tempfile = "3.5.0"
|
serde_json = "1.0.107"
|
||||||
thiserror = "1.0.40"
|
serde_yaml = "0.9.25"
|
||||||
time = { version = "0.3.21", features = ["formatting", "local-offset"] }
|
tempfile = "3.8.0"
|
||||||
toml = "0.7.3"
|
thiserror = "1.0.49"
|
||||||
|
time = { version = "0.3.29", features = ["formatting", "local-offset"] }
|
||||||
|
toml = "0.8.2"
|
||||||
twox-hash = "1.6.3"
|
twox-hash = "1.6.3"
|
||||||
byteorder = "1.4.3"
|
|
||||||
|
|
||||||
# For Linux static binaries, use rustls
|
# For Linux static binaries, use rustls
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
reqwest = { version = "0.11.17", default-features = false, features = ["blocking", "json", "rustls"] }
|
reqwest = { version = "0.11.22", default-features = false, features = ["blocking", "json", "rustls"] }
|
||||||
self_update = { version = "0.36.0", default-features = false, features = ["rustls"] }
|
self_update = { version = "0.38.0", default-features = false, features = ["rustls"] }
|
||||||
|
|
||||||
# For all other platforms, use native TLS
|
# For all other platforms, use native TLS
|
||||||
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
||||||
reqwest = "0.11.17"
|
reqwest = "0.11.22"
|
||||||
self_update = "0.36.0"
|
self_update = "0.38.0"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
path-slash = "0.2.1"
|
path-slash = "0.2.1"
|
||||||
@@ -77,5 +83,5 @@ console_error_panic_hook = "0.1.7"
|
|||||||
tracing-wasm = "0.2"
|
tracing-wasm = "0.2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.71"
|
anyhow = "1.0.75"
|
||||||
vergen = { version = "8.1.3", features = ["build", "cargo", "git", "gitcl"] }
|
vergen = { version = "8.2.5", features = ["build", "cargo", "git", "gitcl"] }
|
||||||
|
|||||||
@@ -5,14 +5,122 @@
|
|||||||
|
|
||||||
A local diffing tool for decompilation projects.
|
A local diffing tool for decompilation projects.
|
||||||
|
|
||||||
Currently supports:
|
Supports:
|
||||||
- PowerPC 750CL (GameCube & Wii)
|
- PowerPC 750CL (GameCube & Wii)
|
||||||
- MIPS (Nintendo 64)
|
- MIPS (Nintendo 64)
|
||||||
|
|
||||||
|
See [Usage](#usage) for more information.
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
### License
|
## Usage
|
||||||
|
|
||||||
|
objdiff works by comparing two relocatable object files (`.o`). The objects are expected to have the same relative path
|
||||||
|
from the "target" and "base" directories.
|
||||||
|
|
||||||
|
For example, if the target ("expected") object is located at `build/asm/MetroTRK/mslsupp.o` and the base ("actual")
|
||||||
|
object is located at `build/src/MetroTRK/mslsupp.o`, the following configuration would be used:
|
||||||
|
|
||||||
|
- Target build directory: `build/asm`
|
||||||
|
- Base build directory: `build/src`
|
||||||
|
- Object: `MetroTRK/mslsupp.o`
|
||||||
|
|
||||||
|
objdiff will then execute the build system from the project directory to build both objects:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ make build/asm/MetroTRK/mslsupp.o # Only if "Build target object" is enabled
|
||||||
|
$ make build/src/MetroTRK/mslsupp.o
|
||||||
|
```
|
||||||
|
|
||||||
|
The objects will then be compared and the results will be displayed in the UI.
|
||||||
|
|
||||||
|
See [Configuration](#configuration) for more information.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
While **not required** (most settings can be specified in the UI), projects can add an `objdiff.json` (or
|
||||||
|
`objdiff.yaml`, `objdiff.yml`) file to configure the tool automatically. The configuration file must be located in
|
||||||
|
the root project directory.
|
||||||
|
|
||||||
|
If your project has a generator script (e.g. `configure.py`), it's recommended to generate the objdiff configuration
|
||||||
|
file as well. You can then add `objdiff.json` to your `.gitignore` to prevent it from being committed.
|
||||||
|
|
||||||
|
```json5
|
||||||
|
// objdiff.json
|
||||||
|
{
|
||||||
|
"custom_make": "ninja",
|
||||||
|
|
||||||
|
// Only required if objects use "path" instead of "target_path" and "base_path".
|
||||||
|
"target_dir": "build/asm",
|
||||||
|
"base_dir": "build/src",
|
||||||
|
|
||||||
|
"build_target": true,
|
||||||
|
"watch_patterns": [
|
||||||
|
"*.c",
|
||||||
|
"*.cp",
|
||||||
|
"*.cpp",
|
||||||
|
"*.h",
|
||||||
|
"*.hpp",
|
||||||
|
"*.py"
|
||||||
|
],
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"name": "main/MetroTRK/mslsupp",
|
||||||
|
|
||||||
|
// Option 1: Relative to target_dir and base_dir
|
||||||
|
"path": "MetroTRK/mslsupp.o",
|
||||||
|
// Option 2: Explicit paths from project root
|
||||||
|
// Useful for more complex directory layouts
|
||||||
|
"target_path": "build/asm/MetroTRK/mslsupp.o",
|
||||||
|
"base_path": "build/src/MetroTRK/mslsupp.o",
|
||||||
|
|
||||||
|
"reverse_fn_order": false
|
||||||
|
},
|
||||||
|
// ...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`custom_make` _(optional)_: By default, objdiff will use `make` to build the project.
|
||||||
|
If the project uses a different build system (e.g. `ninja`), specify it here.
|
||||||
|
|
||||||
|
`target_dir` _(optional)_: Relative from the root of the project, this where the "target" or "expected" objects are located.
|
||||||
|
These are the **intended result** of the match.
|
||||||
|
|
||||||
|
`base_dir` _(optional)_: Relative from the root of the project, this is where the "base" or "actual" objects are located.
|
||||||
|
These are objects built from the **current source code**.
|
||||||
|
|
||||||
|
`build_target`: If true, objdiff will tell the build system to build the target objects before diffing (e.g.
|
||||||
|
`make path/to/target.o`).
|
||||||
|
This is useful if the target objects are not built by default or can change based on project configuration or edits
|
||||||
|
to assembly files.
|
||||||
|
Requires the build system to be configured properly.
|
||||||
|
|
||||||
|
`watch_patterns` _(optional)_: A list of glob patterns to watch for changes.
|
||||||
|
([Supported syntax](https://docs.rs/globset/latest/globset/#syntax))
|
||||||
|
If any of these files change, objdiff will automatically rebuild the objects and re-compare them.
|
||||||
|
If not specified, objdiff will use the default patterns listed above.
|
||||||
|
|
||||||
|
`objects` _(optional)_: If specified, objdiff will display a list of objects in the sidebar for easy navigation.
|
||||||
|
|
||||||
|
> `name` _(optional)_: The name of the object in the UI. If not specified, the object's `path` will be used.
|
||||||
|
>
|
||||||
|
> `path`: Relative path to the object from the `target_dir` and `base_dir`.
|
||||||
|
> Requires `target_dir` and `base_dir` to be specified.
|
||||||
|
>
|
||||||
|
> `target_path`: Path to the target object from the project root.
|
||||||
|
> Required if `path` is not specified.
|
||||||
|
>
|
||||||
|
> `base_path`: Path to the base object from the project root.
|
||||||
|
> Required if `path` is not specified.
|
||||||
|
>
|
||||||
|
> `reverse_fn_order` _(optional)_: Displays function symbols in reversed order.
|
||||||
|
Used to support MWCC's `-inline deferred` option, which reverses the order of functions in the object file.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
Licensed under either of
|
Licensed under either of
|
||||||
|
|
||||||
@@ -23,6 +131,5 @@ at your option.
|
|||||||
|
|
||||||
### Contribution
|
### Contribution
|
||||||
|
|
||||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as
|
||||||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
|
defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
||||||
additional terms or conditions.
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 86 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 158 KiB After Width: | Height: | Size: 144 KiB |
@@ -48,9 +48,11 @@ notice = "warn"
|
|||||||
# A list of advisory IDs to ignore. Note that ignored advisories will still
|
# A list of advisory IDs to ignore. Note that ignored advisories will still
|
||||||
# output a note when they are encountered.
|
# output a note when they are encountered.
|
||||||
ignore = [
|
ignore = [
|
||||||
# git2 (build dependency)
|
"RUSTSEC-2023-0022",
|
||||||
"RUSTSEC-2023-0002",
|
"RUSTSEC-2023-0023",
|
||||||
"RUSTSEC-2023-0003",
|
"RUSTSEC-2023-0024",
|
||||||
|
"RUSTSEC-2023-0034",
|
||||||
|
"RUSTSEC-2023-0044",
|
||||||
]
|
]
|
||||||
# Threshold for security vulnerabilities, any vulnerability with a CVSS score
|
# Threshold for security vulnerabilities, any vulnerability with a CVSS score
|
||||||
# lower than the range specified will be ignored. Note that ignored advisories
|
# lower than the range specified will be ignored. Note that ignored advisories
|
||||||
@@ -86,6 +88,7 @@ allow = [
|
|||||||
"OFL-1.1",
|
"OFL-1.1",
|
||||||
"LicenseRef-UFL-1.0",
|
"LicenseRef-UFL-1.0",
|
||||||
"OpenSSL",
|
"OpenSSL",
|
||||||
|
"GPL-3.0",
|
||||||
]
|
]
|
||||||
# List of explictly disallowed licenses
|
# List of explictly disallowed licenses
|
||||||
# See https://spdx.org/licenses/ for list of possible licenses
|
# See https://spdx.org/licenses/ for list of possible licenses
|
||||||
|
|||||||
+367
-412
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use eframe::Storage;
|
||||||
|
use globset::Glob;
|
||||||
|
|
||||||
|
use crate::app::{AppConfig, ObjectConfig, CONFIG_KEY};
|
||||||
|
|
||||||
|
#[derive(Clone, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct AppConfigVersion {
|
||||||
|
pub version: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AppConfigVersion {
|
||||||
|
fn default() -> Self { Self { version: 1 } }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deserialize the AppConfig from storage, handling upgrades from older versions.
|
||||||
|
pub fn deserialize_config(storage: &dyn Storage) -> Option<AppConfig> {
|
||||||
|
let str = storage.get_string(CONFIG_KEY)?;
|
||||||
|
match ron::from_str::<AppConfigVersion>(&str) {
|
||||||
|
Ok(version) => match version.version {
|
||||||
|
1 => from_str::<AppConfig>(&str),
|
||||||
|
_ => {
|
||||||
|
log::warn!("Unknown config version: {}", version.version);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("Failed to decode config version: {e}");
|
||||||
|
// Try to decode as v0
|
||||||
|
from_str::<AppConfigV0>(&str).map(|c| c.into_config())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_str<T>(str: &str) -> Option<T>
|
||||||
|
where T: serde::de::DeserializeOwned {
|
||||||
|
match ron::from_str(str) {
|
||||||
|
Ok(config) => Some(config),
|
||||||
|
Err(err) => {
|
||||||
|
log::warn!("Failed to decode config: {err}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct ObjectConfigV0 {
|
||||||
|
pub name: String,
|
||||||
|
pub target_path: PathBuf,
|
||||||
|
pub base_path: PathBuf,
|
||||||
|
pub reverse_fn_order: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectConfigV0 {
|
||||||
|
fn into_config(self) -> ObjectConfig {
|
||||||
|
ObjectConfig {
|
||||||
|
name: self.name,
|
||||||
|
target_path: Some(self.target_path),
|
||||||
|
base_path: Some(self.base_path),
|
||||||
|
reverse_fn_order: self.reverse_fn_order,
|
||||||
|
complete: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct AppConfigV0 {
|
||||||
|
pub custom_make: Option<String>,
|
||||||
|
pub selected_wsl_distro: Option<String>,
|
||||||
|
pub project_dir: Option<PathBuf>,
|
||||||
|
pub target_obj_dir: Option<PathBuf>,
|
||||||
|
pub base_obj_dir: Option<PathBuf>,
|
||||||
|
pub selected_obj: Option<ObjectConfigV0>,
|
||||||
|
pub build_target: bool,
|
||||||
|
pub auto_update_check: bool,
|
||||||
|
pub watch_patterns: Vec<Glob>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppConfigV0 {
|
||||||
|
fn into_config(self) -> AppConfig {
|
||||||
|
log::info!("Upgrading configuration from v0");
|
||||||
|
AppConfig {
|
||||||
|
custom_make: self.custom_make,
|
||||||
|
selected_wsl_distro: self.selected_wsl_distro,
|
||||||
|
project_dir: self.project_dir,
|
||||||
|
target_obj_dir: self.target_obj_dir,
|
||||||
|
base_obj_dir: self.base_obj_dir,
|
||||||
|
selected_obj: self.selected_obj.map(|obj| obj.into_config()),
|
||||||
|
build_target: self.build_target,
|
||||||
|
auto_update_check: self.auto_update_check,
|
||||||
|
watch_patterns: self.watch_patterns,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+180
@@ -0,0 +1,180 @@
|
|||||||
|
use std::{
|
||||||
|
fs::File,
|
||||||
|
path::{Component, Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
|
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||||
|
|
||||||
|
use crate::{app::AppConfig, views::config::DEFAULT_WATCH_PATTERNS};
|
||||||
|
|
||||||
|
#[derive(Default, Clone, serde::Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct ProjectConfig {
|
||||||
|
pub min_version: Option<String>,
|
||||||
|
pub custom_make: Option<String>,
|
||||||
|
pub target_dir: Option<PathBuf>,
|
||||||
|
pub base_dir: Option<PathBuf>,
|
||||||
|
pub build_target: bool,
|
||||||
|
pub watch_patterns: Option<Vec<Glob>>,
|
||||||
|
#[serde(alias = "units")]
|
||||||
|
pub objects: Vec<ProjectObject>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Clone, serde::Deserialize)]
|
||||||
|
pub struct ProjectObject {
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub path: Option<PathBuf>,
|
||||||
|
pub target_path: Option<PathBuf>,
|
||||||
|
pub base_path: Option<PathBuf>,
|
||||||
|
pub reverse_fn_order: Option<bool>,
|
||||||
|
pub complete: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProjectObject {
|
||||||
|
pub fn name(&self) -> &str {
|
||||||
|
if let Some(name) = &self.name {
|
||||||
|
name
|
||||||
|
} else if let Some(path) = &self.path {
|
||||||
|
path.to_str().unwrap_or("[invalid path]")
|
||||||
|
} else {
|
||||||
|
"[unknown]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum ProjectObjectNode {
|
||||||
|
File(String, ProjectObject),
|
||||||
|
Dir(String, Vec<ProjectObjectNode>),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_dir<'a>(
|
||||||
|
name: &str,
|
||||||
|
nodes: &'a mut Vec<ProjectObjectNode>,
|
||||||
|
) -> &'a mut Vec<ProjectObjectNode> {
|
||||||
|
if let Some(index) = nodes
|
||||||
|
.iter()
|
||||||
|
.position(|node| matches!(node, ProjectObjectNode::Dir(dir_name, _) if dir_name == name))
|
||||||
|
{
|
||||||
|
if let ProjectObjectNode::Dir(_, children) = &mut nodes[index] {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nodes.push(ProjectObjectNode::Dir(name.to_string(), vec![]));
|
||||||
|
if let Some(ProjectObjectNode::Dir(_, children)) = nodes.last_mut() {
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_nodes(
|
||||||
|
objects: &[ProjectObject],
|
||||||
|
project_dir: &Path,
|
||||||
|
target_obj_dir: &Option<PathBuf>,
|
||||||
|
base_obj_dir: &Option<PathBuf>,
|
||||||
|
) -> Vec<ProjectObjectNode> {
|
||||||
|
let mut nodes = vec![];
|
||||||
|
for object in objects {
|
||||||
|
let mut out_nodes = &mut nodes;
|
||||||
|
let path = if let Some(name) = &object.name {
|
||||||
|
Path::new(name)
|
||||||
|
} else if let Some(path) = &object.path {
|
||||||
|
path
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if let Some(parent) = path.parent() {
|
||||||
|
for component in parent.components() {
|
||||||
|
if let Component::Normal(name) = component {
|
||||||
|
let name = name.to_str().unwrap();
|
||||||
|
out_nodes = find_dir(name, out_nodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut object = object.clone();
|
||||||
|
if let (Some(target_obj_dir), Some(path), None) =
|
||||||
|
(target_obj_dir, &object.path, &object.target_path)
|
||||||
|
{
|
||||||
|
object.target_path = Some(target_obj_dir.join(path));
|
||||||
|
} else if let Some(path) = &object.target_path {
|
||||||
|
object.target_path = Some(project_dir.join(path));
|
||||||
|
}
|
||||||
|
if let (Some(base_obj_dir), Some(path), None) =
|
||||||
|
(base_obj_dir, &object.path, &object.base_path)
|
||||||
|
{
|
||||||
|
object.base_path = Some(base_obj_dir.join(path));
|
||||||
|
} else if let Some(path) = &object.base_path {
|
||||||
|
object.base_path = Some(project_dir.join(path));
|
||||||
|
}
|
||||||
|
let filename = path.file_name().unwrap().to_str().unwrap().to_string();
|
||||||
|
out_nodes.push(ProjectObjectNode::File(filename, object));
|
||||||
|
}
|
||||||
|
nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const CONFIG_FILENAMES: [&str; 3] = ["objdiff.yml", "objdiff.yaml", "objdiff.json"];
|
||||||
|
|
||||||
|
pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
|
||||||
|
let Some(project_dir) = &config.project_dir else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
if let Some(result) = try_project_config(project_dir) {
|
||||||
|
let project_config = result?;
|
||||||
|
if let Some(min_version) = &project_config.min_version {
|
||||||
|
let version_str = env!("CARGO_PKG_VERSION");
|
||||||
|
let version = semver::Version::parse(version_str).unwrap();
|
||||||
|
let version_req = semver::VersionReq::parse(&format!(">={min_version}"))?;
|
||||||
|
if !version_req.matches(&version) {
|
||||||
|
bail!("Project requires objdiff version {} or higher", min_version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.custom_make = project_config.custom_make;
|
||||||
|
config.target_obj_dir = project_config.target_dir.map(|p| project_dir.join(p));
|
||||||
|
config.base_obj_dir = project_config.base_dir.map(|p| project_dir.join(p));
|
||||||
|
config.build_target = project_config.build_target;
|
||||||
|
config.watch_patterns = project_config.watch_patterns.unwrap_or_else(|| {
|
||||||
|
DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect()
|
||||||
|
});
|
||||||
|
config.watcher_change = true;
|
||||||
|
config.objects = project_config.objects;
|
||||||
|
config.object_nodes =
|
||||||
|
build_nodes(&config.objects, project_dir, &config.target_obj_dir, &config.base_obj_dir);
|
||||||
|
config.project_config_loaded = true;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_project_config(dir: &Path) -> Option<Result<ProjectConfig>> {
|
||||||
|
for filename in CONFIG_FILENAMES.iter() {
|
||||||
|
let config_path = dir.join(filename);
|
||||||
|
if config_path.is_file() {
|
||||||
|
return match filename.contains("json") {
|
||||||
|
true => Some(read_json_config(&config_path)),
|
||||||
|
false => Some(read_yml_config(&config_path)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_yml_config(config_path: &Path) -> Result<ProjectConfig> {
|
||||||
|
let mut reader = File::open(config_path)
|
||||||
|
.with_context(|| format!("Failed to open config file '{}'", config_path.display()))?;
|
||||||
|
Ok(serde_yaml::from_reader(&mut reader)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_json_config(config_path: &Path) -> Result<ProjectConfig> {
|
||||||
|
let mut reader = File::open(config_path)
|
||||||
|
.with_context(|| format!("Failed to open config file '{}'", config_path.display()))?;
|
||||||
|
Ok(serde_json::from_reader(&mut reader)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build_globset(vec: &[Glob]) -> std::result::Result<GlobSet, globset::Error> {
|
||||||
|
let mut builder = GlobSetBuilder::new();
|
||||||
|
for glob in vec {
|
||||||
|
builder.add(glob.clone());
|
||||||
|
}
|
||||||
|
builder.build()
|
||||||
|
}
|
||||||
+76
-52
@@ -3,7 +3,6 @@ use std::{collections::BTreeMap, mem::take};
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::DiffConfig,
|
|
||||||
editops::{editops_find, LevEditType},
|
editops::{editops_find, LevEditType},
|
||||||
obj::{
|
obj::{
|
||||||
mips, ppc, ObjArchitecture, ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjInsArg,
|
mips, ppc, ObjArchitecture, ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjInsArg,
|
||||||
@@ -373,64 +372,80 @@ fn find_section_and_symbol(obj: &ObjInfo, name: &str) -> Option<(usize, usize)>
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffConfig) -> Result<()> {
|
pub fn diff_objs(mut left: Option<&mut ObjInfo>, mut right: Option<&mut ObjInfo>) -> Result<()> {
|
||||||
for left_section in &mut left.sections {
|
if let Some(left) = left.as_mut() {
|
||||||
if left_section.kind == ObjSectionKind::Code {
|
for left_section in &mut left.sections {
|
||||||
for left_symbol in &mut left_section.symbols {
|
if left_section.kind == ObjSectionKind::Code {
|
||||||
if let Some((right_section_idx, right_symbol_idx)) =
|
for left_symbol in &mut left_section.symbols {
|
||||||
find_section_and_symbol(right, &left_symbol.name)
|
if let Some((right, (right_section_idx, right_symbol_idx))) =
|
||||||
{
|
right.as_mut().and_then(|obj| {
|
||||||
let right_section = &mut right.sections[right_section_idx];
|
find_section_and_symbol(obj, &left_symbol.name).map(|s| (obj, s))
|
||||||
let right_symbol = &mut right_section.symbols[right_symbol_idx];
|
})
|
||||||
left_symbol.diff_symbol = Some(right_symbol.name.clone());
|
{
|
||||||
right_symbol.diff_symbol = Some(left_symbol.name.clone());
|
let right_section = &mut right.sections[right_section_idx];
|
||||||
diff_code(
|
let right_symbol = &mut right_section.symbols[right_symbol_idx];
|
||||||
left.architecture,
|
left_symbol.diff_symbol = Some(right_symbol.name.clone());
|
||||||
&left_section.data,
|
right_symbol.diff_symbol = Some(left_symbol.name.clone());
|
||||||
&right_section.data,
|
diff_code(
|
||||||
left_symbol,
|
left.architecture,
|
||||||
right_symbol,
|
&left_section.data,
|
||||||
&left_section.relocations,
|
&right_section.data,
|
||||||
&right_section.relocations,
|
left_symbol,
|
||||||
&left.line_info,
|
right_symbol,
|
||||||
&right.line_info,
|
&left_section.relocations,
|
||||||
)?;
|
&right_section.relocations,
|
||||||
} else {
|
&left.line_info,
|
||||||
no_diff_code(
|
&right.line_info,
|
||||||
left.architecture,
|
)?;
|
||||||
&left_section.data,
|
} else {
|
||||||
left_symbol,
|
no_diff_code(
|
||||||
&left_section.relocations,
|
left.architecture,
|
||||||
&left.line_info,
|
&left_section.data,
|
||||||
)?;
|
left_symbol,
|
||||||
|
&left_section.relocations,
|
||||||
|
&left.line_info,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if let Some(right_section) = right
|
||||||
} else {
|
.as_mut()
|
||||||
let Some(right_section) = right.sections.iter_mut().find(|s| s.name == left_section.name) else {
|
.and_then(|obj| obj.sections.iter_mut().find(|s| s.name == left_section.name))
|
||||||
continue;
|
{
|
||||||
};
|
if left_section.kind == ObjSectionKind::Data {
|
||||||
if left_section.kind == ObjSectionKind::Data {
|
diff_data(left_section, right_section);
|
||||||
diff_data(left_section, right_section);
|
// diff_data_symbols(left_section, right_section)?;
|
||||||
// diff_data_symbols(left_section, right_section)?;
|
} else if left_section.kind == ObjSectionKind::Bss {
|
||||||
} else if left_section.kind == ObjSectionKind::Bss {
|
diff_bss_symbols(&mut left_section.symbols, &mut right_section.symbols)?;
|
||||||
diff_bss_symbols(&mut left_section.symbols, &mut right_section.symbols)?;
|
}
|
||||||
|
} else if left_section.kind == ObjSectionKind::Data {
|
||||||
|
no_diff_data(left_section);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for right_section in right.sections.iter_mut().filter(|s| s.kind == ObjSectionKind::Code) {
|
if let Some(right) = right.as_mut() {
|
||||||
for right_symbol in &mut right_section.symbols {
|
for right_section in right.sections.iter_mut() {
|
||||||
if right_symbol.instructions.is_empty() {
|
if right_section.kind == ObjSectionKind::Code {
|
||||||
no_diff_code(
|
for right_symbol in &mut right_section.symbols {
|
||||||
right.architecture,
|
if right_symbol.instructions.is_empty() {
|
||||||
&right_section.data,
|
no_diff_code(
|
||||||
right_symbol,
|
right.architecture,
|
||||||
&right_section.relocations,
|
&right_section.data,
|
||||||
&right.line_info,
|
right_symbol,
|
||||||
)?;
|
&right_section.relocations,
|
||||||
|
&right.line_info,
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if right_section.kind == ObjSectionKind::Data
|
||||||
|
&& right_section.data_diff.is_empty()
|
||||||
|
{
|
||||||
|
no_diff_data(right_section);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
diff_bss_symbols(&mut left.common, &mut right.common)?;
|
if let (Some(left), Some(right)) = (left, right) {
|
||||||
|
diff_bss_symbols(&mut left.common, &mut right.common)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,3 +724,12 @@ fn diff_data(left: &mut ObjSection, right: &mut ObjSection) {
|
|||||||
left.data_diff = left_diff;
|
left.data_diff = left_diff;
|
||||||
right.data_diff = right_diff;
|
right.data_diff = right_diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn no_diff_data(section: &mut ObjSection) {
|
||||||
|
section.data_diff = vec![ObjDataDiff {
|
||||||
|
data: section.data.clone(),
|
||||||
|
kind: ObjDataDiffKind::None,
|
||||||
|
len: section.data.len(),
|
||||||
|
symbol: String::new(),
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
use std::sync::{mpsc::Receiver, Arc, RwLock};
|
|
||||||
|
|
||||||
use anyhow::{Error, Result};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
app::{AppConfig, DiffConfig},
|
|
||||||
diff::diff_objs,
|
|
||||||
jobs::{queue_job, update_status, Job, JobResult, JobState, Status},
|
|
||||||
obj::{elf, ObjInfo},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct BinDiffResult {
|
|
||||||
pub first_obj: ObjInfo,
|
|
||||||
pub second_obj: ObjInfo,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run_build(
|
|
||||||
status: &Status,
|
|
||||||
cancel: Receiver<()>,
|
|
||||||
config: Arc<RwLock<AppConfig>>,
|
|
||||||
) -> Result<Box<BinDiffResult>> {
|
|
||||||
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
|
|
||||||
let target_path =
|
|
||||||
config.left_obj.as_ref().ok_or_else(|| Error::msg("Missing target obj path"))?;
|
|
||||||
let base_path = config.right_obj.as_ref().ok_or_else(|| Error::msg("Missing base obj path"))?;
|
|
||||||
|
|
||||||
update_status(status, "Loading target obj".to_string(), 0, 3, &cancel)?;
|
|
||||||
let mut left_obj = elf::read(target_path)?;
|
|
||||||
|
|
||||||
update_status(status, "Loading base obj".to_string(), 1, 3, &cancel)?;
|
|
||||||
let mut right_obj = elf::read(base_path)?;
|
|
||||||
|
|
||||||
update_status(status, "Performing diff".to_string(), 2, 3, &cancel)?;
|
|
||||||
diff_objs(&mut left_obj, &mut right_obj, &DiffConfig::default() /* TODO */)?;
|
|
||||||
|
|
||||||
update_status(status, "Complete".to_string(), 3, 3, &cancel)?;
|
|
||||||
Ok(Box::new(BinDiffResult { first_obj: left_obj, second_obj: right_obj }))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn queue_bindiff(config: Arc<RwLock<AppConfig>>) -> JobState {
|
|
||||||
queue_job("Binary diff", Job::BinDiff, move |status, cancel| {
|
|
||||||
run_build(status, cancel, config).map(JobResult::BinDiff)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@ use anyhow::{Context, Result};
|
|||||||
use self_update::{cargo_crate_version, update::Release};
|
use self_update::{cargo_crate_version, update::Release};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
jobs::{queue_job, update_status, Job, JobResult, JobState, Status},
|
jobs::{start_job, update_status, Job, JobResult, JobState, JobStatusRef},
|
||||||
update::{build_updater, BIN_NAME},
|
update::{build_updater, BIN_NAME},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ pub struct CheckUpdateResult {
|
|||||||
pub found_binary: bool,
|
pub found_binary: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_check_update(status: &Status, cancel: Receiver<()>) -> Result<Box<CheckUpdateResult>> {
|
fn run_check_update(status: &JobStatusRef, cancel: Receiver<()>) -> Result<Box<CheckUpdateResult>> {
|
||||||
update_status(status, "Fetching latest release".to_string(), 0, 1, &cancel)?;
|
update_status(status, "Fetching latest release".to_string(), 0, 1, &cancel)?;
|
||||||
let updater = build_updater().context("Failed to create release updater")?;
|
let updater = build_updater().context("Failed to create release updater")?;
|
||||||
let latest_release = updater.get_latest_release()?;
|
let latest_release = updater.get_latest_release()?;
|
||||||
@@ -26,8 +26,8 @@ fn run_check_update(status: &Status, cancel: Receiver<()>) -> Result<Box<CheckUp
|
|||||||
Ok(Box::new(CheckUpdateResult { update_available, latest_release, found_binary }))
|
Ok(Box::new(CheckUpdateResult { update_available, latest_release, found_binary }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn queue_check_update() -> JobState {
|
pub fn start_check_update() -> JobState {
|
||||||
queue_job("Check for updates", Job::CheckUpdate, move |status, cancel| {
|
start_job("Check for updates", Job::CheckUpdate, move |status, cancel| {
|
||||||
run_check_update(status, cancel).map(JobResult::CheckUpdate)
|
run_check_update(status, cancel).map(|result| JobResult::CheckUpdate(Some(result)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+81
-18
@@ -9,12 +9,8 @@ use std::{
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::jobs::{
|
use crate::jobs::{check_update::CheckUpdateResult, objdiff::ObjDiffResult, update::UpdateResult};
|
||||||
bindiff::BinDiffResult, check_update::CheckUpdateResult, objdiff::ObjDiffResult,
|
|
||||||
update::UpdateResult,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub mod bindiff;
|
|
||||||
pub mod check_update;
|
pub mod check_update;
|
||||||
pub mod objdiff;
|
pub mod objdiff;
|
||||||
pub mod update;
|
pub mod update;
|
||||||
@@ -22,19 +18,88 @@ pub mod update;
|
|||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||||
pub enum Job {
|
pub enum Job {
|
||||||
ObjDiff,
|
ObjDiff,
|
||||||
BinDiff,
|
|
||||||
CheckUpdate,
|
CheckUpdate,
|
||||||
Update,
|
Update,
|
||||||
}
|
}
|
||||||
pub static JOB_ID: AtomicUsize = AtomicUsize::new(0);
|
pub static JOB_ID: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct JobQueue {
|
||||||
|
pub jobs: Vec<JobState>,
|
||||||
|
pub results: Vec<JobResult>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JobQueue {
|
||||||
|
/// Adds a job to the queue.
|
||||||
|
#[inline]
|
||||||
|
pub fn push(&mut self, state: JobState) { self.jobs.push(state); }
|
||||||
|
|
||||||
|
/// Adds a job to the queue if a job of the given kind is not already running.
|
||||||
|
#[inline]
|
||||||
|
pub fn push_once(&mut self, job: Job, func: impl FnOnce() -> JobState) {
|
||||||
|
if !self.is_running(job) {
|
||||||
|
self.push(func());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns whether a job of the given kind is running.
|
||||||
|
pub fn is_running(&self, kind: Job) -> bool {
|
||||||
|
self.jobs.iter().any(|j| j.kind == kind && j.handle.is_some())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns whether any job is running.
|
||||||
|
pub fn any_running(&self) -> bool {
|
||||||
|
self.jobs.iter().any(|job| {
|
||||||
|
if let Some(handle) = &job.handle {
|
||||||
|
return !handle.is_finished();
|
||||||
|
}
|
||||||
|
false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Iterates over all jobs mutably.
|
||||||
|
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut JobState> + '_ { self.jobs.iter_mut() }
|
||||||
|
|
||||||
|
/// Iterates over all finished jobs, returning the job state and the result.
|
||||||
|
pub fn iter_finished(
|
||||||
|
&mut self,
|
||||||
|
) -> impl Iterator<Item = (&mut JobState, std::thread::Result<JobResult>)> + '_ {
|
||||||
|
self.jobs.iter_mut().filter_map(|job| {
|
||||||
|
if let Some(handle) = &job.handle {
|
||||||
|
if !handle.is_finished() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let result = job.handle.take().unwrap().join();
|
||||||
|
return Some((job, result));
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clears all finished jobs.
|
||||||
|
pub fn clear_finished(&mut self) {
|
||||||
|
self.jobs.retain(|job| {
|
||||||
|
!(job.should_remove
|
||||||
|
&& job.handle.is_none()
|
||||||
|
&& job.status.read().unwrap().error.is_none())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes a job from the queue given its ID.
|
||||||
|
pub fn remove(&mut self, id: usize) { self.jobs.retain(|job| job.id != id); }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type JobStatusRef = Arc<RwLock<JobStatus>>;
|
||||||
|
|
||||||
pub struct JobState {
|
pub struct JobState {
|
||||||
pub id: usize,
|
pub id: usize,
|
||||||
pub job_type: Job,
|
pub kind: Job,
|
||||||
pub handle: Option<JoinHandle<JobResult>>,
|
pub handle: Option<JoinHandle<JobResult>>,
|
||||||
pub status: Arc<RwLock<JobStatus>>,
|
pub status: JobStatusRef,
|
||||||
pub cancel: Sender<()>,
|
pub cancel: Sender<()>,
|
||||||
pub should_remove: bool,
|
pub should_remove: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct JobStatus {
|
pub struct JobStatus {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
@@ -43,11 +108,11 @@ pub struct JobStatus {
|
|||||||
pub status: String,
|
pub status: String,
|
||||||
pub error: Option<anyhow::Error>,
|
pub error: Option<anyhow::Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum JobResult {
|
pub enum JobResult {
|
||||||
None,
|
None,
|
||||||
ObjDiff(Box<ObjDiffResult>),
|
ObjDiff(Option<Box<ObjDiffResult>>),
|
||||||
BinDiff(Box<BinDiffResult>),
|
CheckUpdate(Option<Box<CheckUpdateResult>>),
|
||||||
CheckUpdate(Box<CheckUpdateResult>),
|
|
||||||
Update(Box<UpdateResult>),
|
Update(Box<UpdateResult>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,12 +123,10 @@ fn should_cancel(rx: &Receiver<()>) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Status = Arc<RwLock<JobStatus>>;
|
fn start_job(
|
||||||
|
|
||||||
fn queue_job(
|
|
||||||
title: &str,
|
title: &str,
|
||||||
job_type: Job,
|
kind: Job,
|
||||||
run: impl FnOnce(&Status, Receiver<()>) -> Result<JobResult> + Send + 'static,
|
run: impl FnOnce(&JobStatusRef, Receiver<()>) -> Result<JobResult> + Send + 'static,
|
||||||
) -> JobState {
|
) -> JobState {
|
||||||
let status = Arc::new(RwLock::new(JobStatus {
|
let status = Arc::new(RwLock::new(JobStatus {
|
||||||
title: title.to_string(),
|
title: title.to_string(),
|
||||||
@@ -89,7 +152,7 @@ fn queue_job(
|
|||||||
log::info!("Started job {}", id);
|
log::info!("Started job {}", id);
|
||||||
JobState {
|
JobState {
|
||||||
id,
|
id,
|
||||||
job_type,
|
kind,
|
||||||
handle: Some(handle),
|
handle: Some(handle),
|
||||||
status: status_clone,
|
status: status_clone,
|
||||||
cancel: tx,
|
cancel: tx,
|
||||||
@@ -98,7 +161,7 @@ fn queue_job(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_status(
|
fn update_status(
|
||||||
status: &Status,
|
status: &JobStatusRef,
|
||||||
str: String,
|
str: String,
|
||||||
count: u32,
|
count: u32,
|
||||||
total: u32,
|
total: u32,
|
||||||
|
|||||||
+96
-53
@@ -1,17 +1,12 @@
|
|||||||
use std::{
|
use std::{path::Path, process::Command, str::from_utf8, sync::mpsc::Receiver};
|
||||||
path::Path,
|
|
||||||
process::Command,
|
|
||||||
str::from_utf8,
|
|
||||||
sync::{mpsc::Receiver, Arc, RwLock},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{Context, Error, Result};
|
use anyhow::{anyhow, Context, Error, Result};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::{AppConfig, DiffConfig},
|
app::{AppConfig, AppConfigRef},
|
||||||
diff::diff_objs,
|
diff::diff_objs,
|
||||||
jobs::{queue_job, update_status, Job, JobResult, JobState, Status},
|
jobs::{start_job, update_status, Job, JobResult, JobState, JobStatusRef},
|
||||||
obj::{elf, ObjInfo},
|
obj::{elf, ObjInfo},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,68 +71,116 @@ fn run_make(cwd: &Path, arg: &Path, config: &AppConfig) -> BuildStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_build(
|
fn run_build(
|
||||||
status: &Status,
|
status: &JobStatusRef,
|
||||||
cancel: Receiver<()>,
|
cancel: Receiver<()>,
|
||||||
config: Arc<RwLock<AppConfig>>,
|
config: AppConfigRef,
|
||||||
diff_config: DiffConfig,
|
|
||||||
) -> Result<Box<ObjDiffResult>> {
|
) -> Result<Box<ObjDiffResult>> {
|
||||||
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
|
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
|
||||||
let obj_path = config.obj_path.as_ref().ok_or_else(|| Error::msg("Missing obj path"))?;
|
let obj_config = config.selected_obj.as_ref().ok_or_else(|| Error::msg("Missing obj path"))?;
|
||||||
let project_dir =
|
let project_dir =
|
||||||
config.project_dir.as_ref().ok_or_else(|| Error::msg("Missing project dir"))?;
|
config.project_dir.as_ref().ok_or_else(|| Error::msg("Missing project dir"))?;
|
||||||
let mut target_path = config
|
let target_path_rel = if let Some(target_path) = &obj_config.target_path {
|
||||||
.target_obj_dir
|
Some(target_path.strip_prefix(project_dir).map_err(|_| {
|
||||||
.as_ref()
|
anyhow!(
|
||||||
.ok_or_else(|| Error::msg("Missing target obj dir"))?
|
"Target path '{}' doesn't begin with '{}'",
|
||||||
.to_owned();
|
target_path.display(),
|
||||||
target_path.push(obj_path);
|
project_dir.display()
|
||||||
let mut base_path =
|
)
|
||||||
config.base_obj_dir.as_ref().ok_or_else(|| Error::msg("Missing base obj dir"))?.to_owned();
|
})?)
|
||||||
base_path.push(obj_path);
|
} else {
|
||||||
let target_path_rel = target_path
|
None
|
||||||
.strip_prefix(project_dir)
|
};
|
||||||
.context("Failed to create relative target obj path")?;
|
let base_path_rel = if let Some(base_path) = &obj_config.base_path {
|
||||||
let base_path_rel =
|
Some(base_path.strip_prefix(project_dir).map_err(|_| {
|
||||||
base_path.strip_prefix(project_dir).context("Failed to create relative base obj path")?;
|
anyhow!(
|
||||||
|
"Base path '{}' doesn't begin with '{}'",
|
||||||
|
base_path.display(),
|
||||||
|
project_dir.display()
|
||||||
|
)
|
||||||
|
})?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let total = if config.build_target { 5 } else { 4 };
|
let mut total = 3;
|
||||||
let first_status = if config.build_target {
|
if config.build_target && target_path_rel.is_some() {
|
||||||
update_status(status, format!("Building target {obj_path}"), 0, total, &cancel)?;
|
total += 1;
|
||||||
run_make(project_dir, target_path_rel, &config)
|
}
|
||||||
|
if base_path_rel.is_some() {
|
||||||
|
total += 1;
|
||||||
|
}
|
||||||
|
let first_status = match target_path_rel {
|
||||||
|
Some(target_path_rel) if config.build_target => {
|
||||||
|
update_status(
|
||||||
|
status,
|
||||||
|
format!("Building target {}", target_path_rel.display()),
|
||||||
|
0,
|
||||||
|
total,
|
||||||
|
&cancel,
|
||||||
|
)?;
|
||||||
|
run_make(project_dir, target_path_rel, &config)
|
||||||
|
}
|
||||||
|
_ => BuildStatus { success: true, log: String::new() },
|
||||||
|
};
|
||||||
|
|
||||||
|
let second_status = if let Some(base_path_rel) = base_path_rel {
|
||||||
|
update_status(
|
||||||
|
status,
|
||||||
|
format!("Building base {}", base_path_rel.display()),
|
||||||
|
1,
|
||||||
|
total,
|
||||||
|
&cancel,
|
||||||
|
)?;
|
||||||
|
run_make(project_dir, base_path_rel, &config)
|
||||||
} else {
|
} else {
|
||||||
BuildStatus { success: true, log: String::new() }
|
BuildStatus { success: true, log: String::new() }
|
||||||
};
|
};
|
||||||
|
|
||||||
update_status(status, format!("Building base {obj_path}"), 1, total, &cancel)?;
|
|
||||||
let second_status = run_make(project_dir, base_path_rel, &config);
|
|
||||||
|
|
||||||
let time = OffsetDateTime::now_utc();
|
let time = OffsetDateTime::now_utc();
|
||||||
|
|
||||||
let mut first_obj = if first_status.success {
|
let mut first_obj =
|
||||||
update_status(status, format!("Loading target {obj_path}"), 2, total, &cancel)?;
|
match &obj_config.target_path {
|
||||||
Some(elf::read(&target_path)?)
|
Some(target_path) if first_status.success => {
|
||||||
} else {
|
update_status(
|
||||||
None
|
status,
|
||||||
|
format!("Loading target {}", target_path_rel.unwrap().display()),
|
||||||
|
2,
|
||||||
|
total,
|
||||||
|
&cancel,
|
||||||
|
)?;
|
||||||
|
Some(elf::read(target_path).with_context(|| {
|
||||||
|
format!("Failed to read object '{}'", target_path.display())
|
||||||
|
})?)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut second_obj = match &obj_config.base_path {
|
||||||
|
Some(base_path) if second_status.success => {
|
||||||
|
update_status(
|
||||||
|
status,
|
||||||
|
format!("Loading base {}", base_path_rel.unwrap().display()),
|
||||||
|
3,
|
||||||
|
total,
|
||||||
|
&cancel,
|
||||||
|
)?;
|
||||||
|
Some(
|
||||||
|
elf::read(base_path)
|
||||||
|
.with_context(|| format!("Failed to read object '{}'", base_path.display()))?,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut second_obj = if second_status.success {
|
update_status(status, "Performing diff".to_string(), 4, total, &cancel)?;
|
||||||
update_status(status, format!("Loading base {obj_path}"), 3, total, &cancel)?;
|
diff_objs(first_obj.as_mut(), second_obj.as_mut())?;
|
||||||
Some(elf::read(&base_path)?)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
if let (Some(first_obj), Some(second_obj)) = (&mut first_obj, &mut second_obj) {
|
|
||||||
update_status(status, "Performing diff".to_string(), 4, total, &cancel)?;
|
|
||||||
diff_objs(first_obj, second_obj, &diff_config)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
update_status(status, "Complete".to_string(), total, total, &cancel)?;
|
update_status(status, "Complete".to_string(), total, total, &cancel)?;
|
||||||
Ok(Box::new(ObjDiffResult { first_status, second_status, first_obj, second_obj, time }))
|
Ok(Box::new(ObjDiffResult { first_status, second_status, first_obj, second_obj, time }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn queue_build(config: Arc<RwLock<AppConfig>>, diff_config: DiffConfig) -> JobState {
|
pub fn start_build(config: AppConfigRef) -> JobState {
|
||||||
queue_job("Object diff", Job::ObjDiff, move |status, cancel| {
|
start_job("Object diff", Job::ObjDiff, move |status, cancel| {
|
||||||
run_build(status, cancel, config, diff_config).map(JobResult::ObjDiff)
|
run_build(status, cancel, config).map(|result| JobResult::ObjDiff(Some(result)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -9,7 +9,7 @@ use anyhow::{Context, Result};
|
|||||||
use const_format::formatcp;
|
use const_format::formatcp;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
jobs::{queue_job, update_status, Job, JobResult, JobState, Status},
|
jobs::{start_job, update_status, Job, JobResult, JobState, JobStatusRef},
|
||||||
update::{build_updater, BIN_NAME},
|
update::{build_updater, BIN_NAME},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ pub struct UpdateResult {
|
|||||||
pub exe_path: PathBuf,
|
pub exe_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_update(status: &Status, cancel: Receiver<()>) -> Result<Box<UpdateResult>> {
|
fn run_update(status: &JobStatusRef, cancel: Receiver<()>) -> Result<Box<UpdateResult>> {
|
||||||
update_status(status, "Fetching latest release".to_string(), 0, 3, &cancel)?;
|
update_status(status, "Fetching latest release".to_string(), 0, 3, &cancel)?;
|
||||||
let updater = build_updater().context("Failed to create release updater")?;
|
let updater = build_updater().context("Failed to create release updater")?;
|
||||||
let latest_release = updater.get_latest_release()?;
|
let latest_release = updater.get_latest_release()?;
|
||||||
@@ -53,8 +53,8 @@ fn run_update(status: &Status, cancel: Receiver<()>) -> Result<Box<UpdateResult>
|
|||||||
Ok(Box::from(UpdateResult { exe_path: target_file }))
|
Ok(Box::from(UpdateResult { exe_path: target_file }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn queue_update() -> JobState {
|
pub fn start_update() -> JobState {
|
||||||
queue_job("Update app", Job::Update, move |status, cancel| {
|
start_job("Update app", Job::Update, move |status, cancel| {
|
||||||
run_update(status, cancel).map(JobResult::Update)
|
run_update(status, cancel).map(JobResult::Update)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
pub use app::App;
|
pub use app::App;
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
|
mod app_config;
|
||||||
|
mod config;
|
||||||
mod diff;
|
mod diff;
|
||||||
mod editops;
|
mod editops;
|
||||||
mod jobs;
|
mod jobs;
|
||||||
|
|||||||
+4
-3
@@ -37,7 +37,8 @@ fn main() {
|
|||||||
|
|
||||||
let exec_path: Rc<Mutex<Option<PathBuf>>> = Rc::new(Mutex::new(None));
|
let exec_path: Rc<Mutex<Option<PathBuf>>> = Rc::new(Mutex::new(None));
|
||||||
let exec_path_clone = exec_path.clone();
|
let exec_path_clone = exec_path.clone();
|
||||||
let mut native_options = eframe::NativeOptions::default();
|
let mut native_options =
|
||||||
|
eframe::NativeOptions { follow_system_theme: false, ..Default::default() };
|
||||||
match load_icon() {
|
match load_icon() {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
native_options.icon_data = Some(data);
|
native_options.icon_data = Some(data);
|
||||||
@@ -65,7 +66,7 @@ fn main() {
|
|||||||
let result = exec::Command::new(path)
|
let result = exec::Command::new(path)
|
||||||
.args(&std::env::args().collect::<Vec<String>>())
|
.args(&std::env::args().collect::<Vec<String>>())
|
||||||
.exec();
|
.exec();
|
||||||
eprintln!("Failed to relaunch: {result:?}");
|
log::error!("Failed to relaunch: {result:?}");
|
||||||
} else {
|
} else {
|
||||||
let result = std::process::Command::new(path)
|
let result = std::process::Command::new(path)
|
||||||
.args(std::env::args())
|
.args(std::env::args())
|
||||||
@@ -73,7 +74,7 @@ fn main() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.wait();
|
.wait();
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
eprintln!("Failed to relaunch: {:?}", e);
|
log::error!("Failed to relaunch: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -26,7 +26,7 @@ fn to_obj_section_kind(kind: SectionKind) -> Option<ObjSectionKind> {
|
|||||||
fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> Result<ObjSymbol> {
|
fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> Result<ObjSymbol> {
|
||||||
let mut name = symbol.name().context("Failed to process symbol name")?;
|
let mut name = symbol.name().context("Failed to process symbol name")?;
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
println!("Found empty sym: {symbol:?}");
|
log::warn!("Found empty sym: {symbol:?}");
|
||||||
name = "?";
|
name = "?";
|
||||||
}
|
}
|
||||||
let mut flags = ObjSymbolFlagSet(ObjSymbolFlags::none());
|
let mut flags = ObjSymbolFlagSet(ObjSymbolFlags::none());
|
||||||
@@ -181,7 +181,7 @@ fn find_section_symbol(
|
|||||||
fn relocations_by_section(
|
fn relocations_by_section(
|
||||||
arch: ObjArchitecture,
|
arch: ObjArchitecture,
|
||||||
obj_file: &File<'_>,
|
obj_file: &File<'_>,
|
||||||
section: &mut ObjSection,
|
section: &ObjSection,
|
||||||
) -> Result<Vec<ObjReloc>> {
|
) -> Result<Vec<ObjReloc>> {
|
||||||
let obj_section = obj_file.section_by_index(SectionIndex(section.index))?;
|
let obj_section = obj_file.section_by_index(SectionIndex(section.index))?;
|
||||||
let mut relocations = Vec::<ObjReloc>::new();
|
let mut relocations = Vec::<ObjReloc>::new();
|
||||||
@@ -294,7 +294,7 @@ fn line_info(obj_file: &File<'_>) -> Result<Option<BTreeMap<u32, u32>>> {
|
|||||||
let address_delta = reader.read_u32::<BigEndian>()?;
|
let address_delta = reader.read_u32::<BigEndian>()?;
|
||||||
map.insert(base_address + address_delta, line_number);
|
map.insert(base_address + address_delta, line_number);
|
||||||
}
|
}
|
||||||
println!("Line info: {map:#X?}");
|
log::debug!("Line info: {map:#X?}");
|
||||||
return Ok(Some(map));
|
return Ok(Some(map));
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ pub fn process_code(
|
|||||||
reloc: reloc.cloned(),
|
reloc: reloc.cloned(),
|
||||||
branch_dest,
|
branch_dest,
|
||||||
line,
|
line,
|
||||||
|
orig: None,
|
||||||
});
|
});
|
||||||
cur_addr += 4;
|
cur_addr += 4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ pub struct ObjSection {
|
|||||||
pub data_diff: Vec<ObjDataDiff>,
|
pub data_diff: Vec<ObjDataDiff>,
|
||||||
pub match_percent: f32,
|
pub match_percent: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ObjInsArg {
|
pub enum ObjInsArg {
|
||||||
PpcArg(ppc750cl::Argument),
|
PpcArg(ppc750cl::Argument),
|
||||||
@@ -46,6 +47,40 @@ pub enum ObjInsArg {
|
|||||||
RelocWithBase,
|
RelocWithBase,
|
||||||
BranchOffset(i32),
|
BranchOffset(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO derive PartialEq on ppc750cl::Argument so this isn't necessary
|
||||||
|
impl PartialEq for ObjInsArg {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
match (self, other) {
|
||||||
|
(ObjInsArg::PpcArg(a), ObjInsArg::PpcArg(b)) => {
|
||||||
|
use ppc750cl::Argument;
|
||||||
|
match (a, b) {
|
||||||
|
(Argument::GPR(a), Argument::GPR(b)) => a == b,
|
||||||
|
(Argument::FPR(a), Argument::FPR(b)) => a == b,
|
||||||
|
(Argument::SR(a), Argument::SR(b)) => a == b,
|
||||||
|
(Argument::SPR(a), Argument::SPR(b)) => a == b,
|
||||||
|
(Argument::CRField(a), Argument::CRField(b)) => a == b,
|
||||||
|
(Argument::CRBit(a), Argument::CRBit(b)) => a == b,
|
||||||
|
(Argument::GQR(a), Argument::GQR(b)) => a == b,
|
||||||
|
(Argument::Uimm(a), Argument::Uimm(b)) => a == b,
|
||||||
|
(Argument::Simm(a), Argument::Simm(b)) => a == b,
|
||||||
|
(Argument::Offset(a), Argument::Offset(b)) => a == b,
|
||||||
|
(Argument::BranchDest(a), Argument::BranchDest(b)) => a == b,
|
||||||
|
(Argument::Bit(a), Argument::Bit(b)) => a == b,
|
||||||
|
(Argument::OpaqueU(a), Argument::OpaqueU(b)) => a == b,
|
||||||
|
(_, _) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(ObjInsArg::MipsArg(a), ObjInsArg::MipsArg(b)) => a == b,
|
||||||
|
(ObjInsArg::MipsArgWithBase(a), ObjInsArg::MipsArgWithBase(b)) => a == b,
|
||||||
|
(ObjInsArg::Reloc, ObjInsArg::Reloc) => true,
|
||||||
|
(ObjInsArg::RelocWithBase, ObjInsArg::RelocWithBase) => true,
|
||||||
|
(ObjInsArg::BranchOffset(a), ObjInsArg::BranchOffset(b)) => a == b,
|
||||||
|
(_, _) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct ObjInsArgDiff {
|
pub struct ObjInsArgDiff {
|
||||||
/// Incrementing index for coloring
|
/// Incrementing index for coloring
|
||||||
@@ -86,6 +121,8 @@ pub struct ObjIns {
|
|||||||
pub branch_dest: Option<u32>,
|
pub branch_dest: Option<u32>,
|
||||||
/// Line info
|
/// Line info
|
||||||
pub line: Option<u32>,
|
pub line: Option<u32>,
|
||||||
|
/// Original (unsimplified) instruction
|
||||||
|
pub orig: Option<String>,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ObjInsDiff {
|
pub struct ObjInsDiff {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user