mirror of
https://github.com/encounter/objdiff.git
synced 2026-07-10 12:18:36 -07:00
Compare commits
68 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f599bea2b | |||
| 9927fc35b6 | |||
| 16fb6a491f | |||
| 2541aef71a | |||
| 7ad1f95bf7 | |||
| 66c879a95d | |||
| d53c358d2f | |||
| f24c017545 | |||
| 3b8603ab22 | |||
| 86b7d6b229 | |||
| 3f82781808 | |||
| 926dd06ce9 | |||
| de70b6fca0 | |||
| 79542a4725 | |||
| 0ebd2ae459 | |||
| 08ebea8bd2 | |||
| 46b8890159 | |||
| 8356fe670d | |||
| 7834185223 | |||
| 216dd70d5b | |||
| 976e629f08 | |||
| 67b28b7da1 | |||
| c0b9bfae21 | |||
| f3f4b0482a | |||
| 278683f103 | |||
| 6ad60de32a | |||
| 90c93164ab | |||
| c02eb31dbb | |||
| 86d92866aa | |||
| 51c3af2bbe | |||
| d0b8b449d9 | |||
| 32f5f202f7 | |||
| 481dbc185a | |||
| 26a4cc79cf | |||
| 5c96c2ee51 | |||
| d162fe847e | |||
| 2a24eb5aec | |||
| f7c291bd55 | |||
| 03a578c1bb | |||
| d09ef8e207 | |||
| 63552a58ae | |||
| 827f4a42bd | |||
| b2dcecc5d8 | |||
| 67b237eab6 | |||
| 66da80ff69 | |||
| 0a85f540f2 | |||
| d79b5b1233 | |||
| 8f5519cb6a | |||
| 19ec08be9a | |||
| 2ad0898efa | |||
| 03f2bcb8b1 | |||
| 781071761a | |||
| 572afa8551 | |||
| 90e81fad7e | |||
| 7a8efb4c88 | |||
| 56dac46280 | |||
| 1866158092 | |||
| fe8e7029f6 | |||
| e2c70342c9 | |||
| e6035b00df | |||
| 97bcfe23d4 | |||
| d684b622b5 | |||
| c698750068 | |||
| a06d3455ae | |||
| fbdaa89cc0 | |||
| f7cb494a62 | |||
| 7cc6ed2b43 | |||
| 532b684682 |
@@ -0,0 +1,44 @@
|
|||||||
|
# Repository Guidelines
|
||||||
|
|
||||||
|
## Project Structure & Module Organization
|
||||||
|
|
||||||
|
- `objdiff-core`: core library with diffing logic and shared components
|
||||||
|
- `objdiff-cli`: CLI/TUI with `ratatui`
|
||||||
|
- `objdiff-gui`: GUI with `eframe`/`egui`
|
||||||
|
- `objdiff-wasm`: WebAssembly bindings
|
||||||
|
|
||||||
|
objdiff has three main frontends: GUI, CLI/TUI, and [web](https://github.com/encounter/objdiff-web) (utilizing `objdiff-wasm`).
|
||||||
|
|
||||||
|
`objdiff-gui` is the most fully-featured and is the primary target for new features.
|
||||||
|
|
||||||
|
`objdiff-cli` has an interactive TUI `diff` mode (powered by `ratatui`) and a non-interactive `report` mode to generate detailed progress reports (e.g. for <https://decomp.dev>).
|
||||||
|
|
||||||
|
`objdiff-wasm` is compiled into a [WebAssembly Component](https://component-model.bytecodealliance.org/). The [API](objdiff-wasm/wit/objdiff.wit) is defined using [WIT](https://component-model.bytecodealliance.org/design/wit.html). The web interface is separate, but mirrors the GUI in functionality.
|
||||||
|
|
||||||
|
## Build, Test, and Development Commands
|
||||||
|
|
||||||
|
Run `cargo build` for a debug build and `cargo build --release` for an optimized build.
|
||||||
|
The CLI can be exercised with `cargo run --release --bin objdiff-cli -- --help`.
|
||||||
|
|
||||||
|
The WASM build is not included in the workspace by default due to differences in toolchain and target; build it with `npm -C objdiff-wasm run build`. (nightly required)
|
||||||
|
In general, do NOT use `--workspace`, as it will include the WASM crate and likely fail. Formatting and linting commands are exempt.
|
||||||
|
|
||||||
|
Pre-commit tasks:
|
||||||
|
|
||||||
|
- `cargo test` to run the test suite
|
||||||
|
- `cargo +nightly fmt --all` to format code (nightly required)
|
||||||
|
- `cargo +nightly clippy --all-targets --all-features --workspace -- -D warnings` to lint code (nightly required)
|
||||||
|
- `cargo deny check` (`cargo install --locked cargo-deny` if needed) if dependencies change
|
||||||
|
|
||||||
|
## Testing Guidelines
|
||||||
|
|
||||||
|
Favor focused unit tests adjacent to the code, and integration scenarios in `objdiff-core/tests`.
|
||||||
|
Integration tests utilize snapshots with the `insta` crate; run `curl -LsSf https://insta.rs/install.sh | sh` if needed.
|
||||||
|
To generate updated snapshots, use `cargo insta test`, review diffs manually, then accept changes with `cargo insta accept` (or simply `mv` to accept specific snapshots).
|
||||||
|
|
||||||
|
## Configuration Tips
|
||||||
|
|
||||||
|
- `config.schema.json`: JSON schema for the user-facing project config file (`objdiff.json`)
|
||||||
|
- `objdiff-core/config-schema.json`: Internal options schema to generate `DiffObjConfig` (see `objdiff-core/config_gen.rs`)
|
||||||
|
|
||||||
|
The project configuration (`objdiff.json`) is intended to be generated by the projects' build system. It includes paths to the target (expected) and base (current) object files, along with build commands and file watch patterns. See `README.md` for a summary of key options.
|
||||||
Generated
+934
-793
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -14,7 +14,7 @@ default-members = [
|
|||||||
resolver = "3"
|
resolver = "3"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "3.1.0"
|
version = "3.7.0"
|
||||||
authors = ["Luke Street <luke@street.dev>"]
|
authors = ["Luke Street <luke@street.dev>"]
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|||||||
@@ -111,6 +111,25 @@
|
|||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/$defs/progress_category"
|
"$ref": "#/$defs/progress_category"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Diff configuration options that should be applied automatically when the project is loaded.",
|
||||||
|
"additionalProperties": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"examples": [
|
||||||
|
{
|
||||||
|
"demangler": "gnu_legacy"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"$defs": {
|
"$defs": {
|
||||||
@@ -156,6 +175,20 @@
|
|||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Diff configuration options that should be applied when this unit is active.",
|
||||||
|
"additionalProperties": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ ignore = [
|
|||||||
#{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" },
|
#{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" },
|
||||||
{ id = "RUSTSEC-2024-0436", reason = "Unmaintained paste crate is an indirect dependency" },
|
{ id = "RUSTSEC-2024-0436", reason = "Unmaintained paste crate is an indirect dependency" },
|
||||||
{ id = "RUSTSEC-2025-0052", reason = "Unmaintained async-std crate is an indirect dependency" },
|
{ id = "RUSTSEC-2025-0052", reason = "Unmaintained async-std crate is an indirect dependency" },
|
||||||
|
{ id = "RUSTSEC-2025-0119", reason = "Unmaintained number_prefix crate is an indirect dependency" },
|
||||||
|
{ id = "RUSTSEC-2025-0134", reason = "Unmaintained rustls-pemfile crate is an indirect dependency" },
|
||||||
|
{ id = "RUSTSEC-2026-0002", reason = "Unsound advisory in lru indirect dependency" },
|
||||||
]
|
]
|
||||||
# If this is true, then cargo deny will use the git executable to fetch advisory database.
|
# If this is true, then cargo deny will use the git executable to fetch advisory database.
|
||||||
# If this is false, then it uses a built-in git library.
|
# If this is false, then it uses a built-in git library.
|
||||||
|
|||||||
@@ -16,19 +16,19 @@ publish = false
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
argp = "0.4"
|
argp = "0.4"
|
||||||
crossterm = "0.29"
|
crossterm = "0.29"
|
||||||
enable-ansi-support = "0.2"
|
enable-ansi-support = "0.3"
|
||||||
memmap2 = "0.9"
|
memmap2 = "0.9"
|
||||||
objdiff-core = { path = "../objdiff-core", features = ["all"] }
|
objdiff-core = { path = "../objdiff-core", features = ["all"] }
|
||||||
prost = "0.14"
|
prost = "0.14"
|
||||||
ratatui = "0.29"
|
ratatui = "0.29"
|
||||||
rayon = "1.10"
|
rayon = "1.11"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
supports-color = "3.0"
|
supports-color = "3.0"
|
||||||
time = { version = "0.3", features = ["formatting", "local-offset"] }
|
time = { version = "0.3", features = ["formatting", "local-offset"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
typed-path = "0.11"
|
typed-path = "0.12"
|
||||||
|
|
||||||
[target.'cfg(target_env = "musl")'.dependencies]
|
[target.'cfg(target_env = "musl")'.dependencies]
|
||||||
mimalloc = "0.1"
|
mimalloc = "0.1"
|
||||||
|
|||||||
+86
-43
@@ -19,15 +19,17 @@ use crossterm::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use objdiff_core::{
|
use objdiff_core::{
|
||||||
|
bindings::diff::DiffResult,
|
||||||
build::{
|
build::{
|
||||||
BuildConfig, BuildStatus,
|
BuildConfig, BuildStatus,
|
||||||
watcher::{Watcher, create_watcher},
|
watcher::{Watcher, create_watcher},
|
||||||
},
|
},
|
||||||
config::{
|
config::{
|
||||||
ProjectConfig, ProjectObject, ProjectObjectMetadata, build_globset,
|
ProjectConfig, ProjectObject, ProjectObjectMetadata, ProjectOptions, apply_project_options,
|
||||||
|
build_globset,
|
||||||
path::{check_path_buf, platform_path, platform_path_serde_option},
|
path::{check_path_buf, platform_path, platform_path_serde_option},
|
||||||
},
|
},
|
||||||
diff::{DiffObjConfig, MappingConfig, ObjectDiff},
|
diff::{self, DiffObjConfig, DiffSide, MappingConfig, ObjectDiff},
|
||||||
jobs::{
|
jobs::{
|
||||||
Job, JobQueue, JobResult,
|
Job, JobQueue, JobResult,
|
||||||
objdiff::{ObjDiffConfig, start_build},
|
objdiff::{ObjDiffConfig, start_build},
|
||||||
@@ -39,7 +41,10 @@ use typed_path::{Utf8PlatformPath, Utf8PlatformPathBuf};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cmd::apply_config_args,
|
cmd::apply_config_args,
|
||||||
util::term::crossterm_panic_handler,
|
util::{
|
||||||
|
output::{OutputFormat, write_output},
|
||||||
|
term::crossterm_panic_handler,
|
||||||
|
},
|
||||||
views::{EventControlFlow, EventResult, UiView, function_diff::FunctionDiffUi},
|
views::{EventControlFlow, EventResult, UiView, function_diff::FunctionDiffUi},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,29 +64,26 @@ pub struct Args {
|
|||||||
#[argp(option, short = 'u')]
|
#[argp(option, short = 'u')]
|
||||||
/// Unit name within project
|
/// Unit name within project
|
||||||
unit: Option<String>,
|
unit: Option<String>,
|
||||||
|
#[argp(option, short = 'o', from_str_fn(platform_path))]
|
||||||
|
/// Output file (one-shot mode) ("-" for stdout)
|
||||||
|
output: Option<Utf8PlatformPathBuf>,
|
||||||
|
#[argp(option)]
|
||||||
|
/// Output format (json, json-pretty, proto) (default: json)
|
||||||
|
format: Option<String>,
|
||||||
#[argp(positional)]
|
#[argp(positional)]
|
||||||
/// Function symbol to diff
|
/// Function symbol to diff
|
||||||
symbol: Option<String>,
|
symbol: Option<String>,
|
||||||
#[argp(option, short = 'c')]
|
#[argp(option, short = 'c')]
|
||||||
/// Configuration property (key=value)
|
/// Configuration property (key=value)
|
||||||
config: Vec<String>,
|
config: Vec<String>,
|
||||||
#[argp(option, short = 'm')]
|
|
||||||
/// Symbol mapping (target=base)
|
|
||||||
mapping: Vec<String>,
|
|
||||||
#[argp(option)]
|
|
||||||
/// Left symbol name for selection
|
|
||||||
selecting_left: Option<String>,
|
|
||||||
#[argp(option)]
|
|
||||||
/// Right symbol name for selection
|
|
||||||
selecting_right: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: Args) -> Result<()> {
|
pub fn run(args: Args) -> Result<()> {
|
||||||
let (target_path, base_path, project_config) =
|
let (target_path, base_path, project_config, unit_options) =
|
||||||
match (&args.target, &args.base, &args.project, &args.unit) {
|
match (&args.target, &args.base, &args.project, &args.unit) {
|
||||||
(Some(_), Some(_), None, None)
|
(Some(_), Some(_), None, None)
|
||||||
| (Some(_), None, None, None)
|
| (Some(_), None, None, None)
|
||||||
| (None, Some(_), None, None) => (args.target.clone(), args.base.clone(), None),
|
| (None, Some(_), None, None) => (args.target.clone(), args.base.clone(), None, None),
|
||||||
(None, None, p, u) => {
|
(None, None, p, u) => {
|
||||||
let project = match p {
|
let project = match p {
|
||||||
Some(project) => project.clone(),
|
Some(project) => project.clone(),
|
||||||
@@ -106,28 +108,32 @@ pub fn run(args: Args) -> Result<()> {
|
|||||||
.base_dir
|
.base_dir
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|p| project.join(p.with_platform_encoding()));
|
.map(|p| project.join(p.with_platform_encoding()));
|
||||||
let objects = project_config
|
let units = project_config.units.as_deref().unwrap_or_default();
|
||||||
.units
|
let objects = units
|
||||||
.iter()
|
.iter()
|
||||||
.flatten()
|
.enumerate()
|
||||||
.map(|o| {
|
.map(|(idx, o)| {
|
||||||
ObjectConfig::new(
|
(
|
||||||
o,
|
ObjectConfig::new(
|
||||||
&project,
|
o,
|
||||||
target_obj_dir.as_deref(),
|
&project,
|
||||||
base_obj_dir.as_deref(),
|
target_obj_dir.as_deref(),
|
||||||
|
base_obj_dir.as_deref(),
|
||||||
|
),
|
||||||
|
idx,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let object = if let Some(u) = u {
|
let (object, unit_idx) = if let Some(u) = u {
|
||||||
objects
|
objects
|
||||||
.iter()
|
.iter()
|
||||||
.find(|obj| obj.name == *u)
|
.find(|(obj, _)| obj.name == *u)
|
||||||
|
.map(|(obj, idx)| (obj, *idx))
|
||||||
.ok_or_else(|| anyhow!("Unit not found: {}", u))?
|
.ok_or_else(|| anyhow!("Unit not found: {}", u))?
|
||||||
} else if let Some(symbol_name) = &args.symbol {
|
} else if let Some(symbol_name) = &args.symbol {
|
||||||
let mut idx = None;
|
let mut idx = None;
|
||||||
let mut count = 0usize;
|
let mut count = 0usize;
|
||||||
for (i, obj) in objects.iter().enumerate() {
|
for (i, (obj, unit_idx)) in objects.iter().enumerate() {
|
||||||
if obj
|
if obj
|
||||||
.target_path
|
.target_path
|
||||||
.as_deref()
|
.as_deref()
|
||||||
@@ -135,7 +141,7 @@ pub fn run(args: Args) -> Result<()> {
|
|||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
idx = Some(i);
|
idx = Some((i, *unit_idx));
|
||||||
count += 1;
|
count += 1;
|
||||||
if count > 1 {
|
if count > 1 {
|
||||||
break;
|
break;
|
||||||
@@ -144,7 +150,7 @@ pub fn run(args: Args) -> Result<()> {
|
|||||||
}
|
}
|
||||||
match (count, idx) {
|
match (count, idx) {
|
||||||
(0, None) => bail!("Symbol not found: {}", symbol_name),
|
(0, None) => bail!("Symbol not found: {}", symbol_name),
|
||||||
(1, Some(i)) => &objects[i],
|
(1, Some((i, unit_idx))) => (&objects[i].0, unit_idx),
|
||||||
(2.., Some(_)) => bail!(
|
(2.., Some(_)) => bail!(
|
||||||
"Multiple instances of {} were found, try specifying a unit",
|
"Multiple instances of {} were found, try specifying a unit",
|
||||||
symbol_name
|
symbol_name
|
||||||
@@ -154,30 +160,65 @@ pub fn run(args: Args) -> Result<()> {
|
|||||||
} else {
|
} else {
|
||||||
bail!("Must specify one of: symbol, project and unit, target and base objects")
|
bail!("Must specify one of: symbol, project and unit, target and base objects")
|
||||||
};
|
};
|
||||||
|
let unit_options = units.get(unit_idx).and_then(|u| u.options().cloned());
|
||||||
let target_path = object.target_path.clone();
|
let target_path = object.target_path.clone();
|
||||||
let base_path = object.base_path.clone();
|
let base_path = object.base_path.clone();
|
||||||
(target_path, base_path, Some(project_config))
|
(target_path, base_path, Some(project_config), unit_options)
|
||||||
}
|
}
|
||||||
_ => bail!("Either target and base or project and unit must be specified"),
|
_ => bail!("Either target and base or project and unit must be specified"),
|
||||||
};
|
};
|
||||||
|
|
||||||
run_interactive(args, target_path, base_path, project_config)
|
if let Some(output) = &args.output {
|
||||||
|
run_oneshot(&args, output, target_path.as_deref(), base_path.as_deref(), unit_options)
|
||||||
|
} else {
|
||||||
|
run_interactive(args, target_path, base_path, project_config, unit_options)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_config_from_args(args: &Args) -> Result<(DiffObjConfig, MappingConfig)> {
|
fn run_oneshot(
|
||||||
|
args: &Args,
|
||||||
|
output: &Utf8PlatformPath,
|
||||||
|
target_path: Option<&Utf8PlatformPath>,
|
||||||
|
base_path: Option<&Utf8PlatformPath>,
|
||||||
|
unit_options: Option<ProjectOptions>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let output_format = OutputFormat::from_option(args.format.as_deref())?;
|
||||||
|
let (diff_config, mapping_config) = build_config_from_args(args, None, unit_options.as_ref())?;
|
||||||
|
let target = target_path
|
||||||
|
.map(|p| {
|
||||||
|
obj::read::read(p.as_ref(), &diff_config, DiffSide::Target)
|
||||||
|
.with_context(|| format!("Loading {p}"))
|
||||||
|
})
|
||||||
|
.transpose()?;
|
||||||
|
let base = base_path
|
||||||
|
.map(|p| {
|
||||||
|
obj::read::read(p.as_ref(), &diff_config, DiffSide::Base)
|
||||||
|
.with_context(|| format!("Loading {p}"))
|
||||||
|
})
|
||||||
|
.transpose()?;
|
||||||
|
let result =
|
||||||
|
diff::diff_objs(target.as_ref(), base.as_ref(), None, &diff_config, &mapping_config)?;
|
||||||
|
let left = target.as_ref().and_then(|o| result.left.as_ref().map(|d| (o, d)));
|
||||||
|
let right = base.as_ref().and_then(|o| result.right.as_ref().map(|d| (o, d)));
|
||||||
|
let diff_result = DiffResult::new(left, right, &diff_config)?;
|
||||||
|
write_output(&diff_result, Some(output), output_format)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_config_from_args(
|
||||||
|
args: &Args,
|
||||||
|
project_config: Option<&ProjectConfig>,
|
||||||
|
unit_options: Option<&ProjectOptions>,
|
||||||
|
) -> Result<(DiffObjConfig, MappingConfig)> {
|
||||||
let mut diff_config = DiffObjConfig::default();
|
let mut diff_config = DiffObjConfig::default();
|
||||||
apply_config_args(&mut diff_config, &args.config)?;
|
if let Some(options) = project_config.and_then(|config| config.options.as_ref()) {
|
||||||
let mut mapping_config = MappingConfig {
|
apply_project_options(&mut diff_config, options)?;
|
||||||
mappings: Default::default(),
|
|
||||||
selecting_left: args.selecting_left.clone(),
|
|
||||||
selecting_right: args.selecting_right.clone(),
|
|
||||||
};
|
|
||||||
for mapping in &args.mapping {
|
|
||||||
let (target, base) =
|
|
||||||
mapping.split_once('=').context("--mapping expects \"target=base\"")?;
|
|
||||||
mapping_config.mappings.insert(target.to_string(), base.to_string());
|
|
||||||
}
|
}
|
||||||
Ok((diff_config, mapping_config))
|
if let Some(options) = unit_options {
|
||||||
|
apply_project_options(&mut diff_config, options)?;
|
||||||
|
}
|
||||||
|
apply_config_args(&mut diff_config, &args.config)?;
|
||||||
|
Ok((diff_config, MappingConfig::default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
@@ -316,11 +357,13 @@ fn run_interactive(
|
|||||||
target_path: Option<Utf8PlatformPathBuf>,
|
target_path: Option<Utf8PlatformPathBuf>,
|
||||||
base_path: Option<Utf8PlatformPathBuf>,
|
base_path: Option<Utf8PlatformPathBuf>,
|
||||||
project_config: Option<ProjectConfig>,
|
project_config: Option<ProjectConfig>,
|
||||||
|
unit_options: Option<ProjectOptions>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let Some(symbol_name) = &args.symbol else { bail!("Interactive mode requires a symbol name") };
|
let Some(symbol_name) = &args.symbol else { bail!("Interactive mode requires a symbol name") };
|
||||||
let time_format = time::format_description::parse_borrowed::<2>("[hour]:[minute]:[second]")
|
let time_format = time::format_description::parse_borrowed::<2>("[hour]:[minute]:[second]")
|
||||||
.context("Failed to parse time format")?;
|
.context("Failed to parse time format")?;
|
||||||
let (diff_obj_config, mapping_config) = build_config_from_args(&args)?;
|
let (diff_obj_config, mapping_config) =
|
||||||
|
build_config_from_args(&args, project_config.as_ref(), unit_options.as_ref())?;
|
||||||
let mut state = AppState {
|
let mut state = AppState {
|
||||||
jobs: Default::default(),
|
jobs: Default::default(),
|
||||||
waker: Default::default(),
|
waker: Default::default(),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use objdiff_core::{
|
|||||||
ChangeItem, ChangeItemInfo, ChangeUnit, Changes, ChangesInput, Measures, REPORT_VERSION,
|
ChangeItem, ChangeItemInfo, ChangeUnit, Changes, ChangesInput, Measures, REPORT_VERSION,
|
||||||
Report, ReportCategory, ReportItem, ReportItemMetadata, ReportUnit, ReportUnitMetadata,
|
Report, ReportCategory, ReportItem, ReportItemMetadata, ReportUnit, ReportUnitMetadata,
|
||||||
},
|
},
|
||||||
config::path::platform_path,
|
config::{ProjectObject, ProjectOptions, apply_project_options, path::platform_path},
|
||||||
diff,
|
diff,
|
||||||
obj::{self, SectionKind, SymbolFlag, SymbolKind},
|
obj::{self, SectionKind, SymbolFlag, SymbolKind},
|
||||||
};
|
};
|
||||||
@@ -83,14 +83,13 @@ pub fn run(args: Args) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate(args: GenerateArgs) -> Result<()> {
|
fn generate(args: GenerateArgs) -> Result<()> {
|
||||||
let mut diff_config = diff::DiffObjConfig {
|
let base_diff_config = diff::DiffObjConfig {
|
||||||
function_reloc_diffs: diff::FunctionRelocDiffs::None,
|
function_reloc_diffs: diff::FunctionRelocDiffs::None,
|
||||||
combine_data_sections: true,
|
combine_data_sections: true,
|
||||||
combine_text_sections: true,
|
combine_text_sections: true,
|
||||||
ppc_calculate_pool_relocations: false,
|
ppc_calculate_pool_relocations: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
apply_config_args(&mut diff_config, &args.config)?;
|
|
||||||
|
|
||||||
let output_format = OutputFormat::from_option(args.format.as_deref())?;
|
let output_format = OutputFormat::from_option(args.format.as_deref())?;
|
||||||
let project_dir = args.project.as_deref().unwrap_or_else(|| Utf8PlatformPath::new("."));
|
let project_dir = args.project.as_deref().unwrap_or_else(|| Utf8PlatformPath::new("."));
|
||||||
@@ -101,31 +100,44 @@ fn generate(args: GenerateArgs) -> Result<()> {
|
|||||||
Some((Err(err), _)) => bail!("Failed to load project configuration: {}", err),
|
Some((Err(err), _)) => bail!("Failed to load project configuration: {}", err),
|
||||||
None => bail!("No project configuration found"),
|
None => bail!("No project configuration found"),
|
||||||
};
|
};
|
||||||
info!(
|
|
||||||
"Generating report for {} units (using {} threads)",
|
|
||||||
project.units().len(),
|
|
||||||
if args.deduplicate { 1 } else { rayon::current_num_threads() }
|
|
||||||
);
|
|
||||||
|
|
||||||
let target_obj_dir =
|
let target_obj_dir =
|
||||||
project.target_dir.as_ref().map(|p| project_dir.join(p.with_platform_encoding()));
|
project.target_dir.as_ref().map(|p| project_dir.join(p.with_platform_encoding()));
|
||||||
let base_obj_dir =
|
let base_obj_dir =
|
||||||
project.base_dir.as_ref().map(|p| project_dir.join(p.with_platform_encoding()));
|
project.base_dir.as_ref().map(|p| project_dir.join(p.with_platform_encoding()));
|
||||||
let objects = project
|
let project_units = project.units.as_deref().unwrap_or_default();
|
||||||
.units
|
let objects = project_units
|
||||||
.iter()
|
.iter()
|
||||||
.flatten()
|
.enumerate()
|
||||||
.map(|o| {
|
.map(|(idx, o)| {
|
||||||
ObjectConfig::new(o, project_dir, target_obj_dir.as_deref(), base_obj_dir.as_deref())
|
(
|
||||||
|
ObjectConfig::new(
|
||||||
|
o,
|
||||||
|
project_dir,
|
||||||
|
target_obj_dir.as_deref(),
|
||||||
|
base_obj_dir.as_deref(),
|
||||||
|
),
|
||||||
|
idx,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
info!(
|
||||||
|
"Generating report for {} units (using {} threads)",
|
||||||
|
objects.len(),
|
||||||
|
if args.deduplicate { 1 } else { rayon::current_num_threads() }
|
||||||
|
);
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut units = vec![];
|
let mut units = vec![];
|
||||||
let mut existing_functions: HashSet<String> = HashSet::new();
|
let mut existing_functions: HashSet<String> = HashSet::new();
|
||||||
if args.deduplicate {
|
if args.deduplicate {
|
||||||
// If deduplicating, we need to run single-threaded
|
// If deduplicating, we need to run single-threaded
|
||||||
for object in &objects {
|
for (object, unit_idx) in &objects {
|
||||||
|
let diff_config = build_unit_diff_config(
|
||||||
|
&base_diff_config,
|
||||||
|
project.options.as_ref(),
|
||||||
|
project_units.get(*unit_idx).and_then(ProjectObject::options),
|
||||||
|
&args.config,
|
||||||
|
)?;
|
||||||
if let Some(unit) = report_object(object, &diff_config, Some(&mut existing_functions))?
|
if let Some(unit) = report_object(object, &diff_config, Some(&mut existing_functions))?
|
||||||
{
|
{
|
||||||
units.push(unit);
|
units.push(unit);
|
||||||
@@ -134,7 +146,15 @@ fn generate(args: GenerateArgs) -> Result<()> {
|
|||||||
} else {
|
} else {
|
||||||
let vec = objects
|
let vec = objects
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|object| report_object(object, &diff_config, None))
|
.map(|(object, unit_idx)| {
|
||||||
|
let diff_config = build_unit_diff_config(
|
||||||
|
&base_diff_config,
|
||||||
|
project.options.as_ref(),
|
||||||
|
project_units.get(*unit_idx).and_then(ProjectObject::options),
|
||||||
|
&args.config,
|
||||||
|
)?;
|
||||||
|
report_object(object, &diff_config, None)
|
||||||
|
})
|
||||||
.collect::<Result<Vec<Option<ReportUnit>>>>()?;
|
.collect::<Result<Vec<Option<ReportUnit>>>>()?;
|
||||||
units = vec.into_iter().flatten().collect();
|
units = vec.into_iter().flatten().collect();
|
||||||
}
|
}
|
||||||
@@ -156,6 +176,24 @@ fn generate(args: GenerateArgs) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_unit_diff_config(
|
||||||
|
base: &diff::DiffObjConfig,
|
||||||
|
project_options: Option<&ProjectOptions>,
|
||||||
|
unit_options: Option<&ProjectOptions>,
|
||||||
|
cli_args: &[String],
|
||||||
|
) -> Result<diff::DiffObjConfig> {
|
||||||
|
let mut diff_config = base.clone();
|
||||||
|
if let Some(options) = project_options {
|
||||||
|
apply_project_options(&mut diff_config, options)?;
|
||||||
|
}
|
||||||
|
if let Some(options) = unit_options {
|
||||||
|
apply_project_options(&mut diff_config, options)?;
|
||||||
|
}
|
||||||
|
// CLI args override project and unit options
|
||||||
|
apply_config_args(&mut diff_config, cli_args)?;
|
||||||
|
Ok(diff_config)
|
||||||
|
}
|
||||||
|
|
||||||
fn report_object(
|
fn report_object(
|
||||||
object: &ObjectConfig,
|
object: &ObjectConfig,
|
||||||
diff_config: &diff::DiffObjConfig,
|
diff_config: &diff::DiffObjConfig,
|
||||||
|
|||||||
@@ -378,7 +378,6 @@ impl UiView for FunctionDiffUi {
|
|||||||
}
|
}
|
||||||
// Reload
|
// Reload
|
||||||
KeyCode::Char('r') => {
|
KeyCode::Char('r') => {
|
||||||
result.redraw = true;
|
|
||||||
return EventControlFlow::Reload;
|
return EventControlFlow::Reload;
|
||||||
}
|
}
|
||||||
// Scroll right
|
// Scroll right
|
||||||
@@ -400,7 +399,6 @@ impl UiView for FunctionDiffUi {
|
|||||||
FunctionRelocDiffs::DataValue => FunctionRelocDiffs::All,
|
FunctionRelocDiffs::DataValue => FunctionRelocDiffs::All,
|
||||||
FunctionRelocDiffs::All => FunctionRelocDiffs::None,
|
FunctionRelocDiffs::All => FunctionRelocDiffs::None,
|
||||||
};
|
};
|
||||||
result.redraw = true;
|
|
||||||
return EventControlFlow::Reload;
|
return EventControlFlow::Reload;
|
||||||
}
|
}
|
||||||
// Toggle three-way diff
|
// Toggle three-way diff
|
||||||
@@ -541,6 +539,7 @@ impl FunctionDiffUi {
|
|||||||
DiffText::Opcode(mnemonic, _op) => format!("{mnemonic} "),
|
DiffText::Opcode(mnemonic, _op) => format!("{mnemonic} "),
|
||||||
DiffText::Argument(arg) => arg.to_string(),
|
DiffText::Argument(arg) => arg.to_string(),
|
||||||
DiffText::BranchDest(addr) => format!("{addr:x}"),
|
DiffText::BranchDest(addr) => format!("{addr:x}"),
|
||||||
|
DiffText::BranchArrow(_) => " ~> ".to_string(),
|
||||||
DiffText::Symbol(sym) => {
|
DiffText::Symbol(sym) => {
|
||||||
sym.demangled_name.as_ref().unwrap_or(&sym.name).clone()
|
sym.demangled_name.as_ref().unwrap_or(&sym.name).clone()
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-18
@@ -41,7 +41,8 @@ any-arch = [
|
|||||||
"dep:regex",
|
"dep:regex",
|
||||||
"dep:similar",
|
"dep:similar",
|
||||||
"dep:syn",
|
"dep:syn",
|
||||||
"dep:encoding_rs"
|
"dep:encoding_rs",
|
||||||
|
"demangler",
|
||||||
]
|
]
|
||||||
bindings = [
|
bindings = [
|
||||||
"dep:prost",
|
"dep:prost",
|
||||||
@@ -88,38 +89,37 @@ std = [
|
|||||||
]
|
]
|
||||||
mips = [
|
mips = [
|
||||||
"any-arch",
|
"any-arch",
|
||||||
"dep:cpp_demangle",
|
|
||||||
"dep:cwdemangle",
|
|
||||||
"dep:rabbitizer",
|
"dep:rabbitizer",
|
||||||
]
|
]
|
||||||
ppc = [
|
ppc = [
|
||||||
"any-arch",
|
"any-arch",
|
||||||
"dep:cwdemangle",
|
|
||||||
"dep:cwextab",
|
"dep:cwextab",
|
||||||
"dep:powerpc",
|
"dep:powerpc",
|
||||||
"dep:rlwinmdec",
|
"dep:rlwinmdec",
|
||||||
]
|
]
|
||||||
x86 = [
|
x86 = [
|
||||||
"any-arch",
|
"any-arch",
|
||||||
"dep:cpp_demangle",
|
|
||||||
"dep:iced-x86",
|
"dep:iced-x86",
|
||||||
"dep:msvc-demangler",
|
|
||||||
]
|
]
|
||||||
arm = [
|
arm = [
|
||||||
"any-arch",
|
"any-arch",
|
||||||
"dep:arm-attr",
|
"dep:arm-attr",
|
||||||
"dep:cpp_demangle",
|
|
||||||
"dep:unarm",
|
"dep:unarm",
|
||||||
]
|
]
|
||||||
arm64 = [
|
arm64 = [
|
||||||
"any-arch",
|
"any-arch",
|
||||||
"dep:cpp_demangle",
|
|
||||||
"dep:yaxpeax-arch",
|
"dep:yaxpeax-arch",
|
||||||
"dep:yaxpeax-arm",
|
"dep:yaxpeax-arm",
|
||||||
]
|
]
|
||||||
superh = [
|
superh = [
|
||||||
"any-arch",
|
"any-arch",
|
||||||
]
|
]
|
||||||
|
demangler = [
|
||||||
|
"dep:cpp_demangle",
|
||||||
|
"dep:cwdemangle",
|
||||||
|
"dep:gnuv2_demangle",
|
||||||
|
"dep:msvc-demangler",
|
||||||
|
]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = ["all"]
|
features = ["all"]
|
||||||
@@ -135,10 +135,10 @@ num-traits = { version = "0.2", default-features = false, optional = true }
|
|||||||
object = { version = "0.37", default-features = false, features = ["read_core", "elf", "coff"] }
|
object = { version = "0.37", default-features = false, features = ["read_core", "elf", "coff"] }
|
||||||
pbjson = { version = "0.8", default-features = false, optional = true }
|
pbjson = { version = "0.8", default-features = false, optional = true }
|
||||||
prost = { version = "0.14", default-features = false, features = ["derive"], optional = true }
|
prost = { version = "0.14", default-features = false, features = ["derive"], optional = true }
|
||||||
regex = { version = "1.11", default-features = false, features = [], optional = true }
|
regex = { version = "1.12", default-features = false, features = [], optional = true }
|
||||||
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
|
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
|
||||||
similar = { git = "https://github.com/encounter/similar.git", branch = "no_std", default-features = false, features = ["hashbrown"], optional = true }
|
similar = { git = "https://github.com/encounter/similar.git", branch = "no_std", default-features = false, features = ["hashbrown"], optional = true }
|
||||||
typed-path = { version = "0.11", default-features = false, optional = true }
|
typed-path = { version = "0.12", default-features = false, optional = true }
|
||||||
|
|
||||||
# config
|
# config
|
||||||
globset = { version = "0.4", default-features = false, optional = true }
|
globset = { version = "0.4", default-features = false, optional = true }
|
||||||
@@ -150,21 +150,18 @@ gimli = { git = "https://github.com/gimli-rs/gimli", rev = "7335f00e7c39fd501511
|
|||||||
typed-arena = { version = "2.0", default-features = false, optional = true }
|
typed-arena = { version = "2.0", default-features = false, optional = true }
|
||||||
|
|
||||||
# ppc
|
# ppc
|
||||||
cwdemangle = { version = "1.0", optional = true }
|
|
||||||
cwextab = { version = "1.1", optional = true }
|
cwextab = { version = "1.1", optional = true }
|
||||||
powerpc = { version = "0.4", optional = true }
|
powerpc = { version = "0.4", optional = true }
|
||||||
rlwinmdec = { version = "1.1", optional = true }
|
rlwinmdec = { version = "1.1", optional = true }
|
||||||
|
|
||||||
# mips
|
# mips
|
||||||
rabbitizer = { version = "2.0.0-alpha.4", default-features = false, features = ["all_extensions"], optional = true }
|
rabbitizer = { version = "2.0.0-alpha.7", default-features = false, features = ["all_extensions"], optional = true }
|
||||||
|
|
||||||
# x86
|
# x86
|
||||||
cpp_demangle = { version = "0.4", default-features = false, features = ["alloc"], optional = true }
|
|
||||||
iced-x86 = { version = "1.21", default-features = false, features = ["decoder", "intel", "gas", "masm", "nasm", "exhaustive_enums", "no_std"], optional = true }
|
iced-x86 = { version = "1.21", default-features = false, features = ["decoder", "intel", "gas", "masm", "nasm", "exhaustive_enums", "no_std"], optional = true }
|
||||||
msvc-demangler = { version = "0.11", optional = true }
|
|
||||||
|
|
||||||
# arm
|
# arm
|
||||||
unarm = { version = "1.9", optional = true }
|
unarm = { version = "2.1", optional = true }
|
||||||
arm-attr = { version = "0.2", optional = true }
|
arm-attr = { version = "0.2", optional = true }
|
||||||
|
|
||||||
# arm64
|
# arm64
|
||||||
@@ -172,13 +169,19 @@ yaxpeax-arch = { version = "0.3", default-features = false, optional = true }
|
|||||||
yaxpeax-arm = { version = "0.3", default-features = false, optional = true }
|
yaxpeax-arm = { version = "0.3", default-features = false, optional = true }
|
||||||
|
|
||||||
# build
|
# build
|
||||||
notify = { version = "8.1.0", optional = true }
|
notify = { version = "8.2.0", optional = true }
|
||||||
notify-debouncer-full = { version = "0.5.0", optional = true }
|
notify-debouncer-full = { version = "0.6.0", optional = true }
|
||||||
shell-escape = { version = "0.1", optional = true }
|
shell-escape = { version = "0.1", optional = true }
|
||||||
tempfile = { version = "3.20", optional = true }
|
tempfile = { version = "3.23", optional = true }
|
||||||
time = { version = "0.3", optional = true }
|
time = { version = "0.3", optional = true }
|
||||||
encoding_rs = { version = "0.8.35", optional = true }
|
encoding_rs = { version = "0.8.35", optional = true }
|
||||||
|
|
||||||
|
# demangler
|
||||||
|
cpp_demangle = { version = "0.5", optional = true, default-features = false, features = ["alloc"] }
|
||||||
|
cwdemangle = { version = "1.0", optional = true }
|
||||||
|
gnuv2_demangle = { version = "0.4", optional = true }
|
||||||
|
msvc-demangler = { version = "0.11", optional = true }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3", optional = true, features = ["winbase"] }
|
winapi = { version = "0.3", optional = true, features = ["winbase"] }
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,42 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "demangler",
|
||||||
|
"type": "choice",
|
||||||
|
"default": "auto",
|
||||||
|
"name": "Demangler",
|
||||||
|
"description": "Which demangler should be used to demangle each symbol.",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"value": "auto",
|
||||||
|
"name": "Auto",
|
||||||
|
"description": "Try to automatically guess the mangling format."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "none",
|
||||||
|
"name": "None",
|
||||||
|
"description": "Disable demangling."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "codewarrior",
|
||||||
|
"name": "CodeWarrior"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "itanium",
|
||||||
|
"name": "Itanium"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "msvc",
|
||||||
|
"name": "MSVC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "gnu_legacy",
|
||||||
|
"name": "GNU g++ (Legacy)",
|
||||||
|
"description": "Use the old GNU mangling ABI. Used up to g++ 2.9.x"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "analyzeDataFlow",
|
"id": "analyzeDataFlow",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@@ -46,6 +82,27 @@
|
|||||||
"name": "Space between args",
|
"name": "Space between args",
|
||||||
"description": "Adds a space between arguments in the diff output."
|
"description": "Adds a space between arguments in the diff output."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "showSymbolSizes",
|
||||||
|
"type": "choice",
|
||||||
|
"default": "off",
|
||||||
|
"name": "Show symbol sizes",
|
||||||
|
"description": "Shows symbol sizes in the symbol view.",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"value": "off",
|
||||||
|
"name": "Off"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "hex",
|
||||||
|
"name": "Hex"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "decimal",
|
||||||
|
"name": "Decimal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "combineDataSections",
|
"id": "combineDataSections",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@@ -71,20 +128,43 @@
|
|||||||
"value": "auto",
|
"value": "auto",
|
||||||
"name": "Auto"
|
"name": "Auto"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"value": "v4",
|
||||||
|
"name": "ARMv4"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"value": "v4t",
|
"value": "v4t",
|
||||||
"name": "ARMv4T (GBA)"
|
"name": "ARMv4T (GBA)"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"value": "v5t",
|
||||||
|
"name": "ARMv5T"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"value": "v5te",
|
"value": "v5te",
|
||||||
"name": "ARMv5TE (DS)"
|
"name": "ARMv5TE (DS)"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"value": "v5tej",
|
||||||
|
"name": "ARMv5TEJ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "v6",
|
||||||
|
"name": "ARMv6"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"value": "v6k",
|
"value": "v6k",
|
||||||
"name": "ARMv6K (3DS)"
|
"name": "ARMv6K (3DS)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "arm.vfpV2",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"name": "VFPv2 instructions",
|
||||||
|
"description": "Adds floating-point instructions from VFPv2."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "arm.unifiedSyntax",
|
"id": "arm.unifiedSyntax",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@@ -158,6 +238,10 @@
|
|||||||
"value": "o32",
|
"value": "o32",
|
||||||
"name": "O32"
|
"name": "O32"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"value": "o64",
|
||||||
|
"name": "O64"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"value": "n32",
|
"value": "n32",
|
||||||
"name": "N32"
|
"name": "N32"
|
||||||
@@ -165,6 +249,14 @@
|
|||||||
{
|
{
|
||||||
"value": "n64",
|
"value": "n64",
|
||||||
"name": "N64"
|
"name": "N64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "eabi32",
|
||||||
|
"name": "eabi32"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": "eabi64",
|
||||||
|
"name": "eabi64"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -247,6 +339,8 @@
|
|||||||
"name": "General",
|
"name": "General",
|
||||||
"properties": [
|
"properties": [
|
||||||
"functionRelocDiffs",
|
"functionRelocDiffs",
|
||||||
|
"demangler",
|
||||||
|
"showSymbolSizes",
|
||||||
"spaceBetweenArgs",
|
"spaceBetweenArgs",
|
||||||
"combineDataSections",
|
"combineDataSections",
|
||||||
"combineTextSections"
|
"combineTextSections"
|
||||||
@@ -257,6 +351,7 @@
|
|||||||
"name": "ARM",
|
"name": "ARM",
|
||||||
"properties": [
|
"properties": [
|
||||||
"arm.archVersion",
|
"arm.archVersion",
|
||||||
|
"arm.vfpV2",
|
||||||
"arm.unifiedSyntax",
|
"arm.unifiedSyntax",
|
||||||
"arm.avRegisters",
|
"arm.avRegisters",
|
||||||
"arm.r9Usage",
|
"arm.r9Usage",
|
||||||
@@ -268,26 +363,17 @@
|
|||||||
{
|
{
|
||||||
"id": "mips",
|
"id": "mips",
|
||||||
"name": "MIPS",
|
"name": "MIPS",
|
||||||
"properties": [
|
"properties": ["mips.abi", "mips.instrCategory", "mips.registerPrefix"]
|
||||||
"mips.abi",
|
|
||||||
"mips.instrCategory",
|
|
||||||
"mips.registerPrefix"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "ppc",
|
"id": "ppc",
|
||||||
"name": "PowerPC",
|
"name": "PowerPC",
|
||||||
"properties": [
|
"properties": ["ppc.calculatePoolRelocations", "analyzeDataFlow"]
|
||||||
"ppc.calculatePoolRelocations",
|
|
||||||
"analyzeDataFlow"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "x86",
|
"id": "x86",
|
||||||
"name": "x86",
|
"name": "x86",
|
||||||
"properties": [
|
"properties": ["x86.formatter"]
|
||||||
"x86.formatter"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package objdiff.diff;
|
||||||
|
|
||||||
|
// Top-level diff result containing left and right object diffs
|
||||||
|
message DiffResult {
|
||||||
|
optional DiffObject left = 1;
|
||||||
|
optional DiffObject right = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Diff information for a single object file
|
||||||
|
message DiffObject {
|
||||||
|
repeated DiffSection sections = 1;
|
||||||
|
repeated DiffSymbol symbols = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Diff information for a section
|
||||||
|
message DiffSection {
|
||||||
|
string name = 1;
|
||||||
|
DiffSectionKind kind = 2;
|
||||||
|
uint64 size = 3;
|
||||||
|
uint64 address = 4;
|
||||||
|
optional float match_percent = 5;
|
||||||
|
repeated DiffDataSegment data_diff = 6;
|
||||||
|
repeated DiffDataRelocation reloc_diff = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DiffSectionKind {
|
||||||
|
SECTION_UNKNOWN = 0;
|
||||||
|
SECTION_CODE = 1;
|
||||||
|
SECTION_DATA = 2;
|
||||||
|
SECTION_BSS = 3;
|
||||||
|
SECTION_COMMON = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Symbol with diff information
|
||||||
|
message DiffSymbol {
|
||||||
|
string name = 1;
|
||||||
|
optional string demangled_name = 2;
|
||||||
|
uint64 address = 3;
|
||||||
|
uint64 size = 4;
|
||||||
|
DiffSymbolFlags flags = 5;
|
||||||
|
DiffSymbolKind kind = 10;
|
||||||
|
// The symbol index in the _other_ object that this symbol was diffed against
|
||||||
|
optional uint32 target_symbol = 6;
|
||||||
|
optional float match_percent = 7;
|
||||||
|
// Instruction diff rows (for code symbols)
|
||||||
|
repeated DiffInstructionRow instructions = 8;
|
||||||
|
// Data diff (for data symbols)
|
||||||
|
repeated DiffDataSegment data_diff = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum DiffSymbolKind {
|
||||||
|
SYMBOL_UNKNOWN = 0;
|
||||||
|
SYMBOL_FUNCTION = 1;
|
||||||
|
SYMBOL_OBJECT = 2;
|
||||||
|
SYMBOL_SECTION = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Symbol flags
|
||||||
|
message DiffSymbolFlags {
|
||||||
|
bool global = 1;
|
||||||
|
bool local = 2;
|
||||||
|
bool weak = 3;
|
||||||
|
bool common = 4;
|
||||||
|
bool hidden = 5;
|
||||||
|
bool ignored = 6;
|
||||||
|
bool size_inferred = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A single instruction diff row
|
||||||
|
message DiffInstructionRow {
|
||||||
|
DiffKind diff_kind = 1;
|
||||||
|
optional DiffInstruction instruction = 2;
|
||||||
|
repeated DiffInstructionArgDiff arg_diff = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parsed instruction information
|
||||||
|
message DiffInstruction {
|
||||||
|
uint64 address = 1;
|
||||||
|
uint32 size = 2;
|
||||||
|
// Formatted instruction string
|
||||||
|
string formatted = 3;
|
||||||
|
// Formatted instruction parts
|
||||||
|
repeated DiffInstructionPart parts = 4;
|
||||||
|
// Relocation information (if present)
|
||||||
|
optional DiffRelocation relocation = 5;
|
||||||
|
// Branch destination address
|
||||||
|
optional uint64 branch_dest = 6;
|
||||||
|
// Source line number (if present)
|
||||||
|
optional uint32 line_number = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// An instruction part
|
||||||
|
message DiffInstructionPart {
|
||||||
|
oneof part {
|
||||||
|
// Basic text (whitespace, punctuation, etc.)
|
||||||
|
string basic = 1;
|
||||||
|
// Opcode/mnemonic
|
||||||
|
DiffOpcode opcode = 2;
|
||||||
|
// Argument
|
||||||
|
DiffInstructionArg arg = 3;
|
||||||
|
// Separator between arguments (comma)
|
||||||
|
bool separator = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message DiffOpcode {
|
||||||
|
// Mnemonic string
|
||||||
|
string mnemonic = 1;
|
||||||
|
// Base opcode ID
|
||||||
|
uint32 opcode = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// An instruction argument
|
||||||
|
message DiffInstructionArg {
|
||||||
|
oneof arg {
|
||||||
|
// Signed immediate value
|
||||||
|
sint64 signed = 1;
|
||||||
|
// Unsigned immediate value
|
||||||
|
uint64 unsigned = 2;
|
||||||
|
// Opaque string value (register names, etc.)
|
||||||
|
string opaque = 3;
|
||||||
|
// Relocation
|
||||||
|
bool reloc = 4;
|
||||||
|
// Branch destination address
|
||||||
|
uint64 branch_dest = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Relocation information
|
||||||
|
message DiffRelocation {
|
||||||
|
uint32 type = 1;
|
||||||
|
string type_name = 2;
|
||||||
|
uint32 target_symbol = 3;
|
||||||
|
int64 addend = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Argument diff information
|
||||||
|
message DiffInstructionArgDiff {
|
||||||
|
// If set, this argument differs from the other side.
|
||||||
|
// The value is a rotating index for coloring.
|
||||||
|
optional uint32 diff_index = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Diff kind for instructions and data
|
||||||
|
enum DiffKind {
|
||||||
|
DIFF_NONE = 0;
|
||||||
|
DIFF_REPLACE = 1;
|
||||||
|
DIFF_DELETE = 2;
|
||||||
|
DIFF_INSERT = 3;
|
||||||
|
DIFF_OP_MISMATCH = 4;
|
||||||
|
DIFF_ARG_MISMATCH = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data diff segment
|
||||||
|
message DiffDataSegment {
|
||||||
|
DiffKind kind = 1;
|
||||||
|
bytes data = 2;
|
||||||
|
// Size may be larger than data length for BSS
|
||||||
|
uint64 size = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data relocation diff
|
||||||
|
message DiffDataRelocation {
|
||||||
|
DiffRelocation relocation = 1;
|
||||||
|
DiffKind kind = 2;
|
||||||
|
// Address range this relocation covers
|
||||||
|
uint64 start = 3;
|
||||||
|
uint64 end = 4;
|
||||||
|
}
|
||||||
Binary file not shown.
+269
-364
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,4 @@
|
|||||||
use alloc::{
|
use alloc::{format, string::ToString, vec::Vec};
|
||||||
format,
|
|
||||||
string::{String, ToString},
|
|
||||||
vec::Vec,
|
|
||||||
};
|
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@@ -14,7 +10,7 @@ use yaxpeax_arm::armv8::a64::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::Arch,
|
arch::{Arch, OPCODE_INVALID},
|
||||||
diff::{DiffObjConfig, display::InstructionPart},
|
diff::{DiffObjConfig, display::InstructionPart},
|
||||||
obj::{
|
obj::{
|
||||||
InstructionRef, Relocation, RelocationFlags, ResolvedInstructionRef, ResolvedRelocation,
|
InstructionRef, Relocation, RelocationFlags, ResolvedInstructionRef, ResolvedRelocation,
|
||||||
@@ -60,7 +56,7 @@ impl Arch for ArchArm64 {
|
|||||||
ops.push(InstructionRef {
|
ops.push(InstructionRef {
|
||||||
address,
|
address,
|
||||||
size: 4,
|
size: 4,
|
||||||
opcode: u16::MAX,
|
opcode: OPCODE_INVALID,
|
||||||
branch_dest: None,
|
branch_dest: None,
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
@@ -87,7 +83,7 @@ impl Arch for ArchArm64 {
|
|||||||
let decoder = InstDecoder::default();
|
let decoder = InstDecoder::default();
|
||||||
let mut ins = Instruction::default();
|
let mut ins = Instruction::default();
|
||||||
if decoder.decode_into(&mut ins, &mut reader).is_err() {
|
if decoder.decode_into(&mut ins, &mut reader).is_err() {
|
||||||
cb(InstructionPart::opcode("<invalid>", u16::MAX))?;
|
cb(InstructionPart::opcode("<invalid>", OPCODE_INVALID))?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,12 +104,6 @@ impl Arch for ArchArm64 {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn demangle(&self, name: &str) -> Option<String> {
|
|
||||||
cpp_demangle::Symbol::new(name)
|
|
||||||
.ok()
|
|
||||||
.and_then(|s| s.demangle(&cpp_demangle::DemangleOptions::default()).ok())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
||||||
match flags {
|
match flags {
|
||||||
RelocationFlags::Elf(r_type) => match r_type {
|
RelocationFlags::Elf(r_type) => match r_type {
|
||||||
@@ -2295,7 +2285,7 @@ where Cb: FnMut(InstructionPart<'static>) {
|
|||||||
// Opcode is #[repr(u16)], but the tuple variants negate that, so we have to do this instead.
|
// Opcode is #[repr(u16)], but the tuple variants negate that, so we have to do this instead.
|
||||||
const fn opcode_to_u16(opcode: Opcode) -> u16 {
|
const fn opcode_to_u16(opcode: Opcode) -> u16 {
|
||||||
match opcode {
|
match opcode {
|
||||||
Opcode::Invalid => u16::MAX,
|
Opcode::Invalid => OPCODE_INVALID,
|
||||||
Opcode::UDF => 0,
|
Opcode::UDF => 0,
|
||||||
Opcode::MOVN => 1,
|
Opcode::MOVN => 1,
|
||||||
Opcode::MOVK => 2,
|
Opcode::MOVK => 2,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use alloc::{
|
use alloc::{
|
||||||
collections::{BTreeMap, BTreeSet},
|
collections::{BTreeMap, BTreeSet},
|
||||||
string::{String, ToString},
|
string::ToString,
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -46,8 +46,11 @@ impl ArchMips {
|
|||||||
object::FileFlags::None => {}
|
object::FileFlags::None => {}
|
||||||
object::FileFlags::Elf { e_flags, .. } => {
|
object::FileFlags::Elf { e_flags, .. } => {
|
||||||
abi = match e_flags & EF_MIPS_ABI {
|
abi = match e_flags & EF_MIPS_ABI {
|
||||||
elf::EF_MIPS_ABI_O32 | elf::EF_MIPS_ABI_O64 => Abi::O32,
|
elf::EF_MIPS_ABI_O32 => Abi::O32,
|
||||||
elf::EF_MIPS_ABI_EABI32 | elf::EF_MIPS_ABI_EABI64 => Abi::N32,
|
elf::EF_MIPS_ABI_O64 if e_flags & elf::EF_MIPS_ABI2 != 0 => Abi::N64,
|
||||||
|
elf::EF_MIPS_ABI_O64 => Abi::O64,
|
||||||
|
elf::EF_MIPS_ABI_EABI32 => Abi::EABI32,
|
||||||
|
elf::EF_MIPS_ABI_EABI64 => Abi::EABI64,
|
||||||
_ => {
|
_ => {
|
||||||
if e_flags & elf::EF_MIPS_ABI2 != 0 {
|
if e_flags & elf::EF_MIPS_ABI2 != 0 {
|
||||||
Abi::N32
|
Abi::N32
|
||||||
@@ -170,8 +173,11 @@ impl ArchMips {
|
|||||||
.with_abi(match diff_config.mips_abi {
|
.with_abi(match diff_config.mips_abi {
|
||||||
MipsAbi::Auto => self.abi,
|
MipsAbi::Auto => self.abi,
|
||||||
MipsAbi::O32 => Abi::O32,
|
MipsAbi::O32 => Abi::O32,
|
||||||
|
MipsAbi::O64 => Abi::O64,
|
||||||
MipsAbi::N32 => Abi::N32,
|
MipsAbi::N32 => Abi::N32,
|
||||||
MipsAbi::N64 => Abi::N64,
|
MipsAbi::N64 => Abi::N64,
|
||||||
|
MipsAbi::Eabi32 => Abi::EABI32,
|
||||||
|
MipsAbi::Eabi64 => Abi::EABI64,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,6 +293,7 @@ impl Arch for ArchMips {
|
|||||||
}
|
}
|
||||||
elf::R_MIPS_PC16 => 0, // PC-relative relocation
|
elf::R_MIPS_PC16 => 0, // PC-relative relocation
|
||||||
R_MIPS15_S3 => ((code & 0x001FFFC0) >> 3) as i64,
|
R_MIPS15_S3 => ((code & 0x001FFFC0) >> 3) as i64,
|
||||||
|
elf::R_MIPS_GPREL32 => (code as i32 as i64) + self.ri_gp_value as i64,
|
||||||
flags => bail!("Unsupported MIPS implicit relocation {flags:?}"),
|
flags => bail!("Unsupported MIPS implicit relocation {flags:?}"),
|
||||||
};
|
};
|
||||||
Ok(Some(RelocationOverride { target: RelocationOverrideTarget::Keep, addend }))
|
Ok(Some(RelocationOverride { target: RelocationOverrideTarget::Keep, addend }))
|
||||||
@@ -298,13 +305,6 @@ impl Arch for ArchMips {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn demangle(&self, name: &str) -> Option<String> {
|
|
||||||
cpp_demangle::Symbol::new(name)
|
|
||||||
.ok()
|
|
||||||
.and_then(|s| s.demangle(&cpp_demangle::DemangleOptions::default()).ok())
|
|
||||||
.or_else(|| cwdemangle::demangle(name, &cwdemangle::DemangleOptions::default()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
||||||
match flags {
|
match flags {
|
||||||
RelocationFlags::Elf(r_type) => match r_type {
|
RelocationFlags::Elf(r_type) => match r_type {
|
||||||
@@ -319,6 +319,7 @@ impl Arch for ArchMips {
|
|||||||
elf::R_MIPS_GOT16 => Some("R_MIPS_GOT16"),
|
elf::R_MIPS_GOT16 => Some("R_MIPS_GOT16"),
|
||||||
elf::R_MIPS_PC16 => Some("R_MIPS_PC16"),
|
elf::R_MIPS_PC16 => Some("R_MIPS_PC16"),
|
||||||
elf::R_MIPS_CALL16 => Some("R_MIPS_CALL16"),
|
elf::R_MIPS_CALL16 => Some("R_MIPS_CALL16"),
|
||||||
|
elf::R_MIPS_GPREL32 => Some("R_MIPS_GPREL32"),
|
||||||
R_MIPS15_S3 => Some("R_MIPS15_S3"),
|
R_MIPS15_S3 => Some("R_MIPS15_S3"),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
@@ -356,6 +357,7 @@ impl Arch for ArchMips {
|
|||||||
while new_address >= symbol.address + 4
|
while new_address >= symbol.address + 4
|
||||||
&& let Some(data) = section.data_range(new_address - 4, 4)
|
&& let Some(data) = section.data_range(new_address - 4, 4)
|
||||||
&& data == [0u8; 4]
|
&& data == [0u8; 4]
|
||||||
|
&& section.relocation_at(next_address - 4, 4).is_none()
|
||||||
{
|
{
|
||||||
new_address -= 4;
|
new_address -= 4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,10 @@ use alloc::{
|
|||||||
};
|
};
|
||||||
use core::{
|
use core::{
|
||||||
any::Any,
|
any::Any,
|
||||||
ffi::CStr,
|
|
||||||
fmt::{self, Debug},
|
fmt::{self, Debug},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{Result, bail};
|
||||||
use encoding_rs::SHIFT_JIS;
|
|
||||||
use object::Endian as _;
|
use object::Endian as _;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -41,6 +39,19 @@ pub mod superh;
|
|||||||
#[cfg(feature = "x86")]
|
#[cfg(feature = "x86")]
|
||||||
pub mod x86;
|
pub mod x86;
|
||||||
|
|
||||||
|
pub const OPCODE_INVALID: u16 = u16::MAX;
|
||||||
|
pub const OPCODE_DATA: u16 = u16::MAX - 1;
|
||||||
|
|
||||||
|
const SUPPORTED_ENCODINGS: [(&encoding_rs::Encoding, &str); 7] = [
|
||||||
|
(encoding_rs::UTF_8, "UTF-8"),
|
||||||
|
(encoding_rs::SHIFT_JIS, "Shift JIS"),
|
||||||
|
(encoding_rs::UTF_16BE, "UTF-16BE"),
|
||||||
|
(encoding_rs::UTF_16LE, "UTF-16LE"),
|
||||||
|
(encoding_rs::WINDOWS_1252, "Windows-1252"),
|
||||||
|
(encoding_rs::EUC_JP, "EUC-JP"),
|
||||||
|
(encoding_rs::BIG5, "Big5"),
|
||||||
|
];
|
||||||
|
|
||||||
/// Represents the type of data associated with an instruction
|
/// Represents the type of data associated with an instruction
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub enum DataType {
|
pub enum DataType {
|
||||||
@@ -72,9 +83,9 @@ impl fmt::Display for DataType {
|
|||||||
impl DataType {
|
impl DataType {
|
||||||
pub fn display_labels(&self, endian: object::Endianness, bytes: &[u8]) -> Vec<String> {
|
pub fn display_labels(&self, endian: object::Endianness, bytes: &[u8]) -> Vec<String> {
|
||||||
let mut strs = Vec::new();
|
let mut strs = Vec::new();
|
||||||
for (literal, label_override) in self.display_literals(endian, bytes) {
|
for (literal, label_override, _) in self.display_literals(endian, bytes) {
|
||||||
let label = label_override.unwrap_or_else(|| self.to_string());
|
let label = label_override.unwrap_or_else(|| self.to_string());
|
||||||
strs.push(format!("{label}: {literal}"))
|
strs.push(format!("{label}: {literal:?}"))
|
||||||
}
|
}
|
||||||
strs
|
strs
|
||||||
}
|
}
|
||||||
@@ -83,7 +94,7 @@ impl DataType {
|
|||||||
&self,
|
&self,
|
||||||
endian: object::Endianness,
|
endian: object::Endianness,
|
||||||
bytes: &[u8],
|
bytes: &[u8],
|
||||||
) -> Vec<(String, Option<String>)> {
|
) -> Vec<(String, Option<String>, Option<String>)> {
|
||||||
let mut strs = Vec::new();
|
let mut strs = Vec::new();
|
||||||
if self.required_len().is_some_and(|l| bytes.len() < l) {
|
if self.required_len().is_some_and(|l| bytes.len() < l) {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
@@ -107,34 +118,34 @@ impl DataType {
|
|||||||
match self {
|
match self {
|
||||||
DataType::Int8 => {
|
DataType::Int8 => {
|
||||||
let i = i8::from_ne_bytes(bytes.try_into().unwrap());
|
let i = i8::from_ne_bytes(bytes.try_into().unwrap());
|
||||||
strs.push((format!("{i:#x}"), None));
|
strs.push((format!("{i:#x}"), None, None));
|
||||||
|
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
strs.push((format!("{:#x}", ReallySigned(i)), None));
|
strs.push((format!("{:#x}", ReallySigned(i)), None, None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataType::Int16 => {
|
DataType::Int16 => {
|
||||||
let i = endian.read_i16_bytes(bytes.try_into().unwrap());
|
let i = endian.read_i16_bytes(bytes.try_into().unwrap());
|
||||||
strs.push((format!("{i:#x}"), None));
|
strs.push((format!("{i:#x}"), None, None));
|
||||||
|
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
strs.push((format!("{:#x}", ReallySigned(i)), None));
|
strs.push((format!("{:#x}", ReallySigned(i)), None, None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataType::Int32 => {
|
DataType::Int32 => {
|
||||||
let i = endian.read_i32_bytes(bytes.try_into().unwrap());
|
let i = endian.read_i32_bytes(bytes.try_into().unwrap());
|
||||||
strs.push((format!("{i:#x}"), None));
|
strs.push((format!("{i:#x}"), None, None));
|
||||||
|
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
strs.push((format!("{:#x}", ReallySigned(i)), None));
|
strs.push((format!("{:#x}", ReallySigned(i)), None, None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataType::Int64 => {
|
DataType::Int64 => {
|
||||||
let i = endian.read_i64_bytes(bytes.try_into().unwrap());
|
let i = endian.read_i64_bytes(bytes.try_into().unwrap());
|
||||||
strs.push((format!("{i:#x}"), None));
|
strs.push((format!("{i:#x}"), None, None));
|
||||||
|
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
strs.push((format!("{:#x}", ReallySigned(i)), None));
|
strs.push((format!("{:#x}", ReallySigned(i)), None, None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataType::Float => {
|
DataType::Float => {
|
||||||
@@ -145,6 +156,7 @@ impl DataType {
|
|||||||
object::Endianness::Big => f32::from_be_bytes(bytes),
|
object::Endianness::Big => f32::from_be_bytes(bytes),
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
DataType::Double => {
|
DataType::Double => {
|
||||||
@@ -155,23 +167,43 @@ impl DataType {
|
|||||||
object::Endianness::Big => f64::from_be_bytes(bytes),
|
object::Endianness::Big => f64::from_be_bytes(bytes),
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
DataType::Bytes => {
|
DataType::Bytes => {
|
||||||
strs.push((format!("{bytes:#?}"), None));
|
strs.push((format!("{bytes:#?}"), None, None));
|
||||||
}
|
}
|
||||||
DataType::String => {
|
DataType::String => {
|
||||||
if let Ok(cstr) = CStr::from_bytes_until_nul(bytes) {
|
// Special case to display (ASCII) as the label for ASCII-only strings.
|
||||||
strs.push((format!("{cstr:?}"), None));
|
let mut is_ascii = false;
|
||||||
|
if bytes.is_ascii()
|
||||||
|
&& let Ok(str) = str::from_utf8(bytes)
|
||||||
|
{
|
||||||
|
let trimmed = str.trim_end_matches('\0');
|
||||||
|
if !trimmed.is_empty() {
|
||||||
|
let copy_string = escape_special_ascii_characters(trimmed);
|
||||||
|
strs.push((trimmed.to_string(), Some("ASCII".into()), Some(copy_string)));
|
||||||
|
is_ascii = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(nul_idx) = bytes.iter().position(|&c| c == b'\0') {
|
|
||||||
let (cow, _, had_errors) = SHIFT_JIS.decode(&bytes[..nul_idx]);
|
for (encoding, encoding_name) in SUPPORTED_ENCODINGS {
|
||||||
if !had_errors {
|
// Avoid showing ASCII-only strings more than once if the encoding is ASCII-compatible.
|
||||||
let str = format!("{cow:?}");
|
if is_ascii && encoding.is_ascii_compatible() {
|
||||||
// Only add the Shift JIS string if it's different from the ASCII string.
|
continue;
|
||||||
if !strs.iter().any(|x| x.0 == str) {
|
}
|
||||||
strs.push((str, Some("Shift JIS".into())));
|
let (cow, _, had_errors) = encoding.decode(bytes);
|
||||||
}
|
if had_errors {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let trimmed = cow.trim_end_matches('\0');
|
||||||
|
if !trimmed.is_empty() {
|
||||||
|
let copy_string = escape_special_ascii_characters(trimmed);
|
||||||
|
strs.push((
|
||||||
|
trimmed.to_string(),
|
||||||
|
Some(encoding_name.into()),
|
||||||
|
Some(copy_string),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,8 +400,6 @@ pub trait Arch: Any + Debug + Send + Sync {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn demangle(&self, _name: &str) -> Option<String> { None }
|
|
||||||
|
|
||||||
fn reloc_name(&self, _flags: RelocationFlags) -> Option<&'static str> { None }
|
fn reloc_name(&self, _flags: RelocationFlags) -> Option<&'static str> { None }
|
||||||
|
|
||||||
fn data_reloc_size(&self, flags: RelocationFlags) -> usize;
|
fn data_reloc_size(&self, flags: RelocationFlags) -> usize;
|
||||||
@@ -488,3 +518,21 @@ pub struct RelocationOverride {
|
|||||||
pub target: RelocationOverrideTarget,
|
pub target: RelocationOverrideTarget,
|
||||||
pub addend: i64,
|
pub addend: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Escape ASCII characters such as \n or \t, but not Unicode characters such as \u{3000}.
|
||||||
|
/// Suitable for copying to clipboard.
|
||||||
|
fn escape_special_ascii_characters(value: &str) -> String {
|
||||||
|
let mut escaped = String::new();
|
||||||
|
escaped.push('"');
|
||||||
|
for c in value.chars() {
|
||||||
|
if c.is_ascii() {
|
||||||
|
for e in c.escape_default() {
|
||||||
|
escaped.push(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
escaped.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
escaped.push('"');
|
||||||
|
escaped
|
||||||
|
}
|
||||||
|
|||||||
@@ -238,9 +238,9 @@ impl Arch for ArchPpc {
|
|||||||
addend: 0,
|
addend: 0,
|
||||||
})),
|
})),
|
||||||
|(_, reloc)| match reloc.target() {
|
|(_, reloc)| match reloc.target() {
|
||||||
object::RelocationTarget::Symbol(index) => Ok(Some(RelocationOverride {
|
object::RelocationTarget::Symbol(_) => Ok(Some(RelocationOverride {
|
||||||
target: RelocationOverrideTarget::Keep,
|
target: RelocationOverrideTarget::Keep,
|
||||||
addend: index.0 as u16 as i16 as i64,
|
addend: 0,
|
||||||
})),
|
})),
|
||||||
target => Err(anyhow!("Unsupported IMAGE_REL_PPC_PAIR target {target:?}")),
|
target => Err(anyhow!("Unsupported IMAGE_REL_PPC_PAIR target {target:?}")),
|
||||||
},
|
},
|
||||||
@@ -308,18 +308,6 @@ impl Arch for ArchPpc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn demangle(&self, mut name: &str) -> Option<String> {
|
|
||||||
if name.starts_with('?') {
|
|
||||||
msvc_demangler::demangle(name, msvc_demangler::DemangleFlags::llvm()).ok()
|
|
||||||
} else {
|
|
||||||
name = name.trim_start_matches('.');
|
|
||||||
cpp_demangle::Symbol::new(name)
|
|
||||||
.ok()
|
|
||||||
.and_then(|s| s.demangle(&cpp_demangle::DemangleOptions::default()).ok())
|
|
||||||
.or_else(|| cwdemangle::demangle(name, &cwdemangle::DemangleOptions::default()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
||||||
match flags {
|
match flags {
|
||||||
RelocationFlags::Elf(r_type) => match r_type {
|
RelocationFlags::Elf(r_type) => match r_type {
|
||||||
@@ -354,7 +342,10 @@ impl Arch for ArchPpc {
|
|||||||
elf::R_PPC_UADDR32 => 4,
|
elf::R_PPC_UADDR32 => 4,
|
||||||
_ => 1,
|
_ => 1,
|
||||||
},
|
},
|
||||||
_ => 1,
|
RelocationFlags::Coff(r_type) => match r_type {
|
||||||
|
pe::IMAGE_REL_PPC_ADDR32 => 4,
|
||||||
|
_ => 1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,7 +358,9 @@ impl Arch for ArchPpc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn guess_data_type(&self, resolved: ResolvedInstructionRef, bytes: &[u8]) -> Option<DataType> {
|
fn guess_data_type(&self, resolved: ResolvedInstructionRef, bytes: &[u8]) -> Option<DataType> {
|
||||||
if resolved.relocation.is_some_and(|r| r.symbol.name.starts_with("@stringBase")) {
|
if resolved.relocation.is_some_and(|r| {
|
||||||
|
r.symbol.name.starts_with("@stringBase") || r.symbol.name.starts_with("$SG")
|
||||||
|
}) {
|
||||||
// Pooled string.
|
// Pooled string.
|
||||||
return Some(DataType::String);
|
return Some(DataType::String);
|
||||||
}
|
}
|
||||||
@@ -452,9 +445,13 @@ impl Arch for ArchPpc {
|
|||||||
let simplified = ins.simplified().to_string();
|
let simplified = ins.simplified().to_string();
|
||||||
let show_orig = orig != simplified;
|
let show_orig = orig != simplified;
|
||||||
let mut out = Vec::with_capacity(2);
|
let mut out = Vec::with_capacity(2);
|
||||||
out.push(ContextItem::Copy { value: simplified, label: None });
|
out.push(ContextItem::Copy { value: simplified, label: None, copy_string: None });
|
||||||
if show_orig {
|
if show_orig {
|
||||||
out.push(ContextItem::Copy { value: orig, label: Some("original".to_string()) });
|
out.push(ContextItem::Copy {
|
||||||
|
value: orig,
|
||||||
|
label: Some("original".to_string()),
|
||||||
|
copy_string: None,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
@@ -469,6 +466,7 @@ impl Arch for ArchPpc {
|
|||||||
while next_address >= symbol.address + 4
|
while next_address >= symbol.address + 4
|
||||||
&& let Some(data) = section.data_range(next_address - 4, 4)
|
&& let Some(data) = section.data_range(next_address - 4, 4)
|
||||||
&& data == [0u8; 4]
|
&& data == [0u8; 4]
|
||||||
|
&& section.relocation_at(next_address - 4, 4).is_none()
|
||||||
{
|
{
|
||||||
next_address -= 4;
|
next_address -= 4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use alloc::{collections::BTreeMap, format, string::String, vec, vec::Vec};
|
use alloc::{collections::BTreeMap, format, vec, vec::Vec};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use object::elf;
|
use object::elf;
|
||||||
@@ -132,12 +132,6 @@ impl Arch for ArchSuperH {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn demangle(&self, name: &str) -> Option<String> {
|
|
||||||
cpp_demangle::Symbol::new(name)
|
|
||||||
.ok()
|
|
||||||
.and_then(|s| s.demangle(&cpp_demangle::DemangleOptions::default()).ok())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
||||||
match flags {
|
match flags {
|
||||||
RelocationFlags::Elf(r_type) => match r_type {
|
RelocationFlags::Elf(r_type) => match r_type {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use alloc::{boxed::Box, format, string::String, vec::Vec};
|
use alloc::{boxed::Box, format, vec::Vec};
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
|
|
||||||
use anyhow::{Context, Result, anyhow, bail};
|
use anyhow::{Context, Result, anyhow, bail};
|
||||||
@@ -9,7 +9,7 @@ use iced_x86::{
|
|||||||
use object::{Endian as _, Object as _, ObjectSection as _, elf, pe};
|
use object::{Endian as _, Object as _, ObjectSection as _, elf, pe};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::{Arch, RelocationOverride, RelocationOverrideTarget},
|
arch::{Arch, OPCODE_DATA, RelocationOverride, RelocationOverrideTarget},
|
||||||
diff::{DiffObjConfig, X86Formatter, display::InstructionPart},
|
diff::{DiffObjConfig, X86Formatter, display::InstructionPart},
|
||||||
obj::{InstructionRef, Relocation, RelocationFlags, ResolvedInstructionRef, Section, Symbol},
|
obj::{InstructionRef, Relocation, RelocationFlags, ResolvedInstructionRef, Section, Symbol},
|
||||||
};
|
};
|
||||||
@@ -68,7 +68,12 @@ impl ArchX86 {
|
|||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
RelocationFlags::Elf(typ) => match typ {
|
RelocationFlags::Elf(typ) => match typ {
|
||||||
elf::R_386_32 | elf::R_386_PC32 => Some(4),
|
elf::R_386_32
|
||||||
|
| elf::R_386_PC32
|
||||||
|
| elf::R_386_GOT32
|
||||||
|
| elf::R_386_PLT32
|
||||||
|
| elf::R_386_GOTOFF
|
||||||
|
| elf::R_386_GOTPC => Some(4),
|
||||||
elf::R_386_16 => Some(2),
|
elf::R_386_16 => Some(2),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
@@ -89,8 +94,6 @@ impl ArchX86 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DATA_OPCODE: u16 = u16::MAX - 1;
|
|
||||||
|
|
||||||
impl Arch for ArchX86 {
|
impl Arch for ArchX86 {
|
||||||
fn scan_instructions_internal(
|
fn scan_instructions_internal(
|
||||||
&self,
|
&self,
|
||||||
@@ -121,10 +124,43 @@ impl Arch for ArchX86 {
|
|||||||
out.push(InstructionRef {
|
out.push(InstructionRef {
|
||||||
address,
|
address,
|
||||||
size: size as u8,
|
size: size as u8,
|
||||||
opcode: DATA_OPCODE,
|
opcode: OPCODE_DATA,
|
||||||
branch_dest: None,
|
branch_dest: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
reloc_iter.next();
|
reloc_iter.next();
|
||||||
|
|
||||||
|
// support .byte arrays after jump tables (they're typically known as indirect tables)
|
||||||
|
|
||||||
|
let indirect_array_address = address.wrapping_add(size as u64);
|
||||||
|
let indirect_array_pos = decoder.position();
|
||||||
|
|
||||||
|
let max_size = code.len().saturating_sub(indirect_array_pos);
|
||||||
|
|
||||||
|
let indirect_array_size = reloc_iter
|
||||||
|
.peek()
|
||||||
|
.map(|next_reloc| {
|
||||||
|
next_reloc.address.saturating_sub(indirect_array_address)
|
||||||
|
as usize
|
||||||
|
})
|
||||||
|
.unwrap_or(max_size)
|
||||||
|
.min(max_size);
|
||||||
|
|
||||||
|
if indirect_array_size > 0 {
|
||||||
|
for i in 0..indirect_array_size {
|
||||||
|
out.push(InstructionRef {
|
||||||
|
address: indirect_array_address + i as u64,
|
||||||
|
size: 1,
|
||||||
|
opcode: OPCODE_DATA,
|
||||||
|
branch_dest: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// move decoder to after the array (there can be multiple jump+indirect tables in one function)
|
||||||
|
let _ =
|
||||||
|
decoder.set_position(indirect_array_pos + indirect_array_size);
|
||||||
|
decoder.set_ip(indirect_array_address + indirect_array_size as u64);
|
||||||
|
}
|
||||||
|
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,13 +190,14 @@ impl Arch for ArchX86 {
|
|||||||
diff_config: &DiffObjConfig,
|
diff_config: &DiffObjConfig,
|
||||||
cb: &mut dyn FnMut(InstructionPart) -> Result<()>,
|
cb: &mut dyn FnMut(InstructionPart) -> Result<()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if resolved.ins_ref.opcode == DATA_OPCODE {
|
if resolved.ins_ref.opcode == OPCODE_DATA {
|
||||||
let (mnemonic, imm) = match resolved.ins_ref.size {
|
let (mnemonic, imm) = match resolved.ins_ref.size {
|
||||||
|
1 => (".byte", resolved.code[0] as u64),
|
||||||
2 => (".word", self.endianness.read_u16_bytes(resolved.code.try_into()?) as u64),
|
2 => (".word", self.endianness.read_u16_bytes(resolved.code.try_into()?) as u64),
|
||||||
4 => (".dword", self.endianness.read_u32_bytes(resolved.code.try_into()?) as u64),
|
4 => (".dword", self.endianness.read_u32_bytes(resolved.code.try_into()?) as u64),
|
||||||
_ => bail!("Unsupported x86 inline data size {}", resolved.ins_ref.size),
|
_ => bail!("Unsupported x86 inline data size {}", resolved.ins_ref.size),
|
||||||
};
|
};
|
||||||
cb(InstructionPart::opcode(mnemonic, DATA_OPCODE))?;
|
cb(InstructionPart::opcode(mnemonic, OPCODE_DATA))?;
|
||||||
if resolved.relocation.is_some() {
|
if resolved.relocation.is_some() {
|
||||||
cb(InstructionPart::reloc())?;
|
cb(InstructionPart::reloc())?;
|
||||||
} else {
|
} else {
|
||||||
@@ -240,7 +277,15 @@ impl Arch for ArchX86 {
|
|||||||
object::RelocationFlags::Coff {
|
object::RelocationFlags::Coff {
|
||||||
typ: pe::IMAGE_REL_I386_DIR32 | pe::IMAGE_REL_I386_REL32,
|
typ: pe::IMAGE_REL_I386_DIR32 | pe::IMAGE_REL_I386_REL32,
|
||||||
}
|
}
|
||||||
| object::RelocationFlags::Elf { r_type: elf::R_386_32 | elf::R_386_PC32 } => {
|
| object::RelocationFlags::Elf {
|
||||||
|
r_type:
|
||||||
|
elf::R_386_32
|
||||||
|
| elf::R_386_PC32
|
||||||
|
| elf::R_386_GOT32
|
||||||
|
| elf::R_386_PLT32
|
||||||
|
| elf::R_386_GOTOFF
|
||||||
|
| elf::R_386_GOTPC,
|
||||||
|
} => {
|
||||||
let data =
|
let data =
|
||||||
section.data()?[address as usize..address as usize + 4].try_into()?;
|
section.data()?[address as usize..address as usize + 4].try_into()?;
|
||||||
self.endianness.read_i32_bytes(data) as i64
|
self.endianness.read_i32_bytes(data) as i64
|
||||||
@@ -268,16 +313,6 @@ impl Arch for ArchX86 {
|
|||||||
Ok(Some(RelocationOverride { target: RelocationOverrideTarget::Keep, addend }))
|
Ok(Some(RelocationOverride { target: RelocationOverrideTarget::Keep, addend }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn demangle(&self, name: &str) -> Option<String> {
|
|
||||||
if name.starts_with('?') {
|
|
||||||
msvc_demangler::demangle(name, msvc_demangler::DemangleFlags::llvm()).ok()
|
|
||||||
} else {
|
|
||||||
cpp_demangle::Symbol::new(name)
|
|
||||||
.ok()
|
|
||||||
.and_then(|s| s.demangle(&cpp_demangle::DemangleOptions::default()).ok())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
fn reloc_name(&self, flags: RelocationFlags) -> Option<&'static str> {
|
||||||
match self.arch {
|
match self.arch {
|
||||||
Architecture::X86 => match flags {
|
Architecture::X86 => match flags {
|
||||||
@@ -286,7 +321,16 @@ impl Arch for ArchX86 {
|
|||||||
pe::IMAGE_REL_I386_REL32 => Some("IMAGE_REL_I386_REL32"),
|
pe::IMAGE_REL_I386_REL32 => Some("IMAGE_REL_I386_REL32"),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => None,
|
RelocationFlags::Elf(typ) => match typ {
|
||||||
|
elf::R_386_32 => Some("R_386_32"),
|
||||||
|
elf::R_386_PC32 => Some("R_386_PC32"),
|
||||||
|
elf::R_386_GOT32 => Some("R_386_GOT32"),
|
||||||
|
elf::R_386_PLT32 => Some("R_386_PLT32"),
|
||||||
|
elf::R_386_GOTOFF => Some("R_386_GOTOFF"),
|
||||||
|
elf::R_386_GOTPC => Some("R_386_GOTPC"),
|
||||||
|
elf::R_386_16 => Some("R_386_16"),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Architecture::X86_64 => match flags {
|
Architecture::X86_64 => match flags {
|
||||||
RelocationFlags::Coff(typ) => match typ {
|
RelocationFlags::Coff(typ) => match typ {
|
||||||
@@ -791,4 +835,33 @@ mod test {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(parts, &[InstructionPart::opcode("call", opcode), InstructionPart::reloc()]);
|
assert_eq!(parts, &[InstructionPart::opcode("call", opcode), InstructionPart::reloc()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_display_1_byte_inline_data() {
|
||||||
|
let arch = ArchX86 { arch: Architecture::X86, endianness: object::Endianness::Little };
|
||||||
|
let code = [0xAB];
|
||||||
|
let mut parts = Vec::new();
|
||||||
|
arch.display_instruction(
|
||||||
|
ResolvedInstructionRef {
|
||||||
|
ins_ref: InstructionRef {
|
||||||
|
address: 0x1234,
|
||||||
|
size: 1,
|
||||||
|
opcode: OPCODE_DATA,
|
||||||
|
branch_dest: None,
|
||||||
|
},
|
||||||
|
code: &code,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
&DiffObjConfig::default(),
|
||||||
|
&mut |part| {
|
||||||
|
parts.push(part.into_static());
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(parts, &[
|
||||||
|
InstructionPart::opcode(".byte", OPCODE_DATA),
|
||||||
|
InstructionPart::unsigned(0xABu64),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user