mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-14 07:36:17 +00:00
Compare commits
5 Commits
a0371dd110
...
v0.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
| e2fde3dbce | |||
| 613e84ecf2 | |||
| 7219e72acf | |||
| d1d6f1101b | |||
| bc7cce7226 |
14
Cargo.lock
generated
14
Cargo.lock
generated
@@ -1926,9 +1926,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "objdiff"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
"cfg-if",
|
||||
"console_error_panic_hook",
|
||||
"const_format",
|
||||
@@ -1943,6 +1944,7 @@ dependencies = [
|
||||
"notify",
|
||||
"object",
|
||||
"path-slash",
|
||||
"png",
|
||||
"ppc750cl",
|
||||
"rabbitizer",
|
||||
"reqwest",
|
||||
@@ -1958,6 +1960,7 @@ dependencies = [
|
||||
"twox-hash",
|
||||
"vergen",
|
||||
"winapi",
|
||||
"winres",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3520,6 +3523,15 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winres"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c"
|
||||
dependencies = [
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wio"
|
||||
version = "0.2.2"
|
||||
|
||||
11
Cargo.toml
11
Cargo.toml
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "objdiff"
|
||||
version = "0.2.0"
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
rust-version = "1.62"
|
||||
authors = ["Luke Street <luke@street.dev>"]
|
||||
@@ -18,6 +18,7 @@ strip = "debuginfo"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.66"
|
||||
bytes = "1.3.0"
|
||||
cfg-if = "1.0.0"
|
||||
const_format = "0.2.30"
|
||||
cwdemangle = { git = "https://github.com/encounter/cwdemangle", rev = "286f3d1d29ee2457db89043782725631845c3e4c" }
|
||||
@@ -29,22 +30,26 @@ log = "0.4.17"
|
||||
memmap2 = "0.5.8"
|
||||
notify = "5.0.0"
|
||||
object = { version = "0.30.0", features = ["read_core", "std", "elf"], default-features = false }
|
||||
png = "0.17.7"
|
||||
ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "aa631a33de7882c679afca89350898b87cb3ba3f" }
|
||||
rabbitizer = { git = "https://github.com/encounter/rabbitizer-rs", rev = "10c279b2ef251c62885b1dcdcfe740b0db8e9956" }
|
||||
reqwest = "0.11.13"
|
||||
rfd = { version = "0.10.0" } # , default-features = false, features = ['xdg-portal']
|
||||
self_update = "0.32.0"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
tempfile = "3.3.0"
|
||||
thiserror = "1.0.37"
|
||||
time = { version = "0.3.17", features = ["formatting", "local-offset"] }
|
||||
toml = "0.5.9"
|
||||
twox-hash = "1.6.3"
|
||||
tempfile = "3.3.0"
|
||||
reqwest = "0.11.13"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
path-slash = "0.2.1"
|
||||
winapi = "0.3.9"
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
winres = "0.1.12"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
exec = "0.3.1"
|
||||
|
||||
|
||||
BIN
assets/icon.ico
Normal file
BIN
assets/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
assets/icon_64.png
Normal file
BIN
assets/icon_64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.9 KiB |
8
build.rs
8
build.rs
@@ -1,4 +1,10 @@
|
||||
use anyhow::Result;
|
||||
use vergen::{vergen, Config};
|
||||
|
||||
fn main() -> Result<()> { vergen(Config::default()) }
|
||||
fn main() -> Result<()> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
winres::WindowsResource::new().set_icon("assets/icon.ico").compile()?;
|
||||
}
|
||||
vergen(Config::default())
|
||||
}
|
||||
|
||||
@@ -79,6 +79,11 @@ impl Default for ViewConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SymbolReference {
|
||||
pub symbol_name: String,
|
||||
pub section_name: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct ViewState {
|
||||
@@ -89,7 +94,7 @@ pub struct ViewState {
|
||||
#[serde(skip)]
|
||||
pub highlighted_symbol: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub selected_symbol: Option<String>,
|
||||
pub selected_symbol: Option<SymbolReference>,
|
||||
#[serde(skip)]
|
||||
pub current_view: View,
|
||||
#[serde(skip)]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::{
|
||||
env::{current_dir, current_exe},
|
||||
fs,
|
||||
fs::File,
|
||||
path::PathBuf,
|
||||
sync::mpsc::Receiver,
|
||||
@@ -44,7 +43,7 @@ fn run_update(status: &Status, cancel: Receiver<()>) -> Result<Box<UpdateResult>
|
||||
.to_dest(&target_file)?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::{fs, os::unix::fs::PermissionsExt};
|
||||
let mut perms = fs::metadata(&target_file)?.permissions();
|
||||
perms.set_mode(0o755);
|
||||
fs::set_permissions(&target_file, perms)?;
|
||||
|
||||
28
src/main.rs
28
src/main.rs
@@ -3,9 +3,27 @@
|
||||
|
||||
use std::{path::PathBuf, rc::Rc, sync::Mutex};
|
||||
|
||||
use anyhow::{Error, Result};
|
||||
use cfg_if::cfg_if;
|
||||
use eframe::IconData;
|
||||
use time::UtcOffset;
|
||||
|
||||
fn load_icon() -> Result<IconData> {
|
||||
use bytes::Buf;
|
||||
let decoder = png::Decoder::new(include_bytes!("../assets/icon_64.png").reader());
|
||||
let mut reader = decoder.read_info()?;
|
||||
let mut buf = vec![0; reader.output_buffer_size()];
|
||||
let info = reader.next_frame(&mut buf)?;
|
||||
if info.bit_depth != png::BitDepth::Eight {
|
||||
return Err(Error::msg("Invalid bit depth"));
|
||||
}
|
||||
if info.color_type != png::ColorType::Rgba {
|
||||
return Err(Error::msg("Invalid color type"));
|
||||
}
|
||||
buf.truncate(info.buffer_size());
|
||||
Ok(IconData { rgba: buf, width: info.width, height: info.height })
|
||||
}
|
||||
|
||||
// When compiling natively:
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn main() {
|
||||
@@ -19,7 +37,15 @@ fn main() {
|
||||
|
||||
let exec_path: Rc<Mutex<Option<PathBuf>>> = Rc::new(Mutex::new(None));
|
||||
let exec_path_clone = exec_path.clone();
|
||||
let native_options = eframe::NativeOptions::default();
|
||||
let mut native_options = eframe::NativeOptions::default();
|
||||
match load_icon() {
|
||||
Ok(data) => {
|
||||
native_options.icon_data = Some(data);
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Failed to load application icon: {}", e);
|
||||
}
|
||||
}
|
||||
// native_options.renderer = eframe::Renderer::Wgpu;
|
||||
eframe::run_native(
|
||||
"objdiff",
|
||||
|
||||
@@ -9,7 +9,7 @@ use object::{
|
||||
R_PPC_EMB_SDA21, R_PPC_REL14, R_PPC_REL24,
|
||||
},
|
||||
Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget,
|
||||
SectionKind, Symbol, SymbolKind, SymbolSection,
|
||||
SectionIndex, SectionKind, Symbol, SymbolKind, SymbolSection,
|
||||
};
|
||||
|
||||
use crate::obj::{
|
||||
@@ -192,9 +192,7 @@ fn relocations_by_section(
|
||||
obj_file: &File<'_>,
|
||||
section: &mut ObjSection,
|
||||
) -> Result<Vec<ObjReloc>> {
|
||||
let obj_section = obj_file
|
||||
.section_by_name(§ion.name)
|
||||
.ok_or_else(|| anyhow::Error::msg("Failed to locate section"))?;
|
||||
let obj_section = obj_file.section_by_index(SectionIndex(section.index))?;
|
||||
let mut relocations = Vec::<ObjReloc>::new();
|
||||
for (address, reloc) in obj_section.relocations() {
|
||||
let symbol = match reloc.target() {
|
||||
|
||||
@@ -81,12 +81,14 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
|
||||
if state.update_available {
|
||||
ui.colored_label(Color32::LIGHT_GREEN, "Update available");
|
||||
ui.horizontal(|ui| {
|
||||
if state.found_binary && ui
|
||||
if state.found_binary
|
||||
&& ui
|
||||
.button("Automatic")
|
||||
.on_hover_text_at_pointer(
|
||||
"Automatically download and replace the current build",
|
||||
)
|
||||
.clicked() {
|
||||
.clicked()
|
||||
{
|
||||
view_state.jobs.push(queue_update());
|
||||
}
|
||||
if ui
|
||||
@@ -183,20 +185,18 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
|
||||
ui.separator();
|
||||
}
|
||||
|
||||
if let Some(base_dir) = base_obj_dir {
|
||||
if let (Some(base_dir), Some(target_dir)) = (base_obj_dir, target_obj_dir) {
|
||||
if ui.button("Select obj").clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new()
|
||||
.set_directory(&base_dir)
|
||||
.set_directory(&target_dir)
|
||||
.add_filter("Object file", &["o", "elf"])
|
||||
.pick_file()
|
||||
{
|
||||
let mut new_build_obj: Option<String> = None;
|
||||
if let Ok(obj_path) = path.strip_prefix(&base_dir) {
|
||||
new_build_obj = Some(obj_path.display().to_string());
|
||||
} else if let Some(build_asm_dir) = target_obj_dir {
|
||||
if let Ok(obj_path) = path.strip_prefix(&build_asm_dir) {
|
||||
new_build_obj = Some(obj_path.display().to_string());
|
||||
}
|
||||
} else if let Ok(obj_path) = path.strip_prefix(&target_dir) {
|
||||
new_build_obj = Some(obj_path.display().to_string());
|
||||
}
|
||||
if let Some(new_build_obj) = new_build_obj {
|
||||
*obj_path = Some(new_build_obj);
|
||||
|
||||
@@ -5,7 +5,7 @@ use egui_extras::{Size, StripBuilder, TableBuilder};
|
||||
use time::format_description;
|
||||
|
||||
use crate::{
|
||||
app::{View, ViewConfig, ViewState},
|
||||
app::{SymbolReference, View, ViewConfig, ViewState},
|
||||
jobs::Job,
|
||||
obj::{ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjSection},
|
||||
views::{write_text, COLOR_RED},
|
||||
@@ -13,8 +13,10 @@ use crate::{
|
||||
|
||||
const BYTES_PER_ROW: usize = 16;
|
||||
|
||||
fn find_section<'a>(obj: &'a ObjInfo, section_name: &str) -> Option<&'a ObjSection> {
|
||||
obj.sections.iter().find(|s| s.name == section_name)
|
||||
fn find_section<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSection> {
|
||||
obj.sections.iter().find(|section| {
|
||||
section.symbols.iter().any(|symbol| symbol.name == selected_symbol.symbol_name)
|
||||
})
|
||||
}
|
||||
|
||||
fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config: &ViewConfig) {
|
||||
@@ -132,11 +134,11 @@ fn data_table_ui(
|
||||
table: TableBuilder<'_>,
|
||||
left_obj: &ObjInfo,
|
||||
right_obj: &ObjInfo,
|
||||
section_name: &str,
|
||||
selected_symbol: &SymbolReference,
|
||||
config: &ViewConfig,
|
||||
) -> Option<()> {
|
||||
let left_section = find_section(left_obj, section_name)?;
|
||||
let right_section = find_section(right_obj, section_name)?;
|
||||
let left_section = find_section(left_obj, selected_symbol)?;
|
||||
let right_section = find_section(right_obj, selected_symbol)?;
|
||||
|
||||
let total_bytes = left_section.data_diff.iter().fold(0usize, |accum, item| accum + item.len);
|
||||
if total_bytes == 0 {
|
||||
@@ -219,7 +221,7 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
||||
ui.style_mut().override_text_style =
|
||||
Some(egui::TextStyle::Monospace);
|
||||
ui.style_mut().wrap = Some(false);
|
||||
ui.colored_label(Color32::WHITE, selected_symbol);
|
||||
ui.colored_label(Color32::WHITE, &selected_symbol.symbol_name);
|
||||
ui.label("Diff target:");
|
||||
ui.separator();
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ use ppc750cl::Argument;
|
||||
use time::format_description;
|
||||
|
||||
use crate::{
|
||||
app::{View, ViewConfig, ViewState},
|
||||
app::{SymbolReference, View, ViewConfig, ViewState},
|
||||
jobs::Job,
|
||||
obj::{
|
||||
ObjInfo, ObjIns, ObjInsArg, ObjInsArgDiff, ObjInsDiff, ObjInsDiffKind, ObjReloc,
|
||||
@@ -240,9 +240,10 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
|
||||
});
|
||||
}
|
||||
|
||||
fn find_symbol<'a>(obj: &'a ObjInfo, section_name: &str, name: &str) -> Option<&'a ObjSymbol> {
|
||||
let section = obj.sections.iter().find(|s| s.name == section_name)?;
|
||||
section.symbols.iter().find(|s| s.name == name)
|
||||
fn find_symbol<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSymbol> {
|
||||
obj.sections.iter().find_map(|section| {
|
||||
section.symbols.iter().find(|symbol| symbol.name == selected_symbol.symbol_name)
|
||||
})
|
||||
}
|
||||
|
||||
fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, config: &ViewConfig) {
|
||||
@@ -296,11 +297,11 @@ fn asm_table_ui(
|
||||
table: TableBuilder<'_>,
|
||||
left_obj: &ObjInfo,
|
||||
right_obj: &ObjInfo,
|
||||
fn_name: &str,
|
||||
selected_symbol: &SymbolReference,
|
||||
config: &ViewConfig,
|
||||
) -> Option<()> {
|
||||
let left_symbol = find_symbol(left_obj, ".text", fn_name);
|
||||
let right_symbol = find_symbol(right_obj, ".text", fn_name);
|
||||
let left_symbol = find_symbol(left_obj, selected_symbol);
|
||||
let right_symbol = find_symbol(right_obj, selected_symbol);
|
||||
let instructions_len = left_symbol.or(right_symbol).map(|s| s.instructions.len())?;
|
||||
table.body(|body| {
|
||||
body.rows(config.code_font.size, instructions_len, |row_index, mut row| {
|
||||
@@ -372,7 +373,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
||||
});
|
||||
strip.strip(|builder| {
|
||||
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
|
||||
let demangled = demangle(selected_symbol, &Default::default());
|
||||
let demangled = demangle(&selected_symbol.symbol_name, &Default::default());
|
||||
strip.cell(|ui| {
|
||||
ui.scope(|ui| {
|
||||
ui.style_mut().override_text_style =
|
||||
@@ -380,7 +381,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
||||
ui.style_mut().wrap = Some(false);
|
||||
ui.colored_label(
|
||||
Color32::WHITE,
|
||||
demangled.as_ref().unwrap_or(selected_symbol),
|
||||
demangled.as_ref().unwrap_or(&selected_symbol.symbol_name),
|
||||
);
|
||||
ui.label("Diff target:");
|
||||
ui.separator();
|
||||
@@ -394,7 +395,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
|
||||
if let Some(match_percent) = result
|
||||
.second_obj
|
||||
.as_ref()
|
||||
.and_then(|obj| find_symbol(obj, ".text", selected_symbol))
|
||||
.and_then(|obj| find_symbol(obj, selected_symbol))
|
||||
.and_then(|symbol| symbol.match_percent)
|
||||
{
|
||||
ui.colored_label(
|
||||
|
||||
@@ -4,7 +4,7 @@ use egui::{
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
|
||||
use crate::{
|
||||
app::{View, ViewConfig, ViewState},
|
||||
app::{SymbolReference, View, ViewConfig, ViewState},
|
||||
jobs::objdiff::BuildStatus,
|
||||
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
|
||||
views::write_text,
|
||||
@@ -58,7 +58,7 @@ fn symbol_ui(
|
||||
symbol: &ObjSymbol,
|
||||
section: Option<&ObjSection>,
|
||||
highlighted_symbol: &mut Option<String>,
|
||||
selected_symbol: &mut Option<String>,
|
||||
selected_symbol: &mut Option<SymbolReference>,
|
||||
current_view: &mut View,
|
||||
config: &ViewConfig,
|
||||
) {
|
||||
@@ -99,10 +99,16 @@ fn symbol_ui(
|
||||
if response.clicked() {
|
||||
if let Some(section) = section {
|
||||
if section.kind == ObjSectionKind::Code {
|
||||
*selected_symbol = Some(symbol.name.clone());
|
||||
*selected_symbol = Some(SymbolReference {
|
||||
symbol_name: symbol.name.clone(),
|
||||
section_name: section.name.clone(),
|
||||
});
|
||||
*current_view = View::FunctionDiff;
|
||||
} else if section.kind == ObjSectionKind::Data {
|
||||
*selected_symbol = Some(section.name.clone());
|
||||
*selected_symbol = Some(SymbolReference {
|
||||
symbol_name: section.name.clone(),
|
||||
section_name: section.name.clone(),
|
||||
});
|
||||
*current_view = View::DataDiff;
|
||||
}
|
||||
}
|
||||
@@ -126,7 +132,7 @@ fn symbol_list_ui(
|
||||
ui: &mut Ui,
|
||||
obj: &ObjInfo,
|
||||
highlighted_symbol: &mut Option<String>,
|
||||
selected_symbol: &mut Option<String>,
|
||||
selected_symbol: &mut Option<SymbolReference>,
|
||||
current_view: &mut View,
|
||||
reverse_function_order: bool,
|
||||
search: &mut String,
|
||||
@@ -160,7 +166,7 @@ fn symbol_list_ui(
|
||||
CollapsingHeader::new(format!("{} ({:x})", section.name, section.size))
|
||||
.default_open(true)
|
||||
.show(ui, |ui| {
|
||||
if section.name == ".text" && reverse_function_order {
|
||||
if section.kind == ObjSectionKind::Code && reverse_function_order {
|
||||
for symbol in section.symbols.iter().rev() {
|
||||
if !symbol_matches_search(symbol, &lower_search) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user