Skip to content

Commit 7219e72

Browse files
committed
Version 0.2.2
- Add application icon - Fixes for objects containing multiple sections with the same name
1 parent d1d6f11 commit 7219e72

File tree

12 files changed

+92
-38
lines changed

12 files changed

+92
-38
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "objdiff"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
edition = "2021"
55
rust-version = "1.62"
66
authors = ["Luke Street <[email protected]>"]
@@ -18,6 +18,7 @@ strip = "debuginfo"
1818

1919
[dependencies]
2020
anyhow = "1.0.66"
21+
bytes = "1.3.0"
2122
cfg-if = "1.0.0"
2223
const_format = "0.2.30"
2324
cwdemangle = { git = "https://github.com/encounter/cwdemangle", rev = "286f3d1d29ee2457db89043782725631845c3e4c" }
@@ -29,22 +30,26 @@ log = "0.4.17"
2930
memmap2 = "0.5.8"
3031
notify = "5.0.0"
3132
object = { version = "0.30.0", features = ["read_core", "std", "elf"], default-features = false }
33+
png = "0.17.7"
3234
ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "aa631a33de7882c679afca89350898b87cb3ba3f" }
3335
rabbitizer = { git = "https://github.com/encounter/rabbitizer-rs", rev = "10c279b2ef251c62885b1dcdcfe740b0db8e9956" }
36+
reqwest = "0.11.13"
3437
rfd = { version = "0.10.0" } # , default-features = false, features = ['xdg-portal']
3538
self_update = "0.32.0"
3639
serde = { version = "1", features = ["derive"] }
40+
tempfile = "3.3.0"
3741
thiserror = "1.0.37"
3842
time = { version = "0.3.17", features = ["formatting", "local-offset"] }
3943
toml = "0.5.9"
4044
twox-hash = "1.6.3"
41-
tempfile = "3.3.0"
42-
reqwest = "0.11.13"
4345

4446
[target.'cfg(windows)'.dependencies]
4547
path-slash = "0.2.1"
4648
winapi = "0.3.9"
4749

50+
[target.'cfg(windows)'.build-dependencies]
51+
winres = "0.1.12"
52+
4853
[target.'cfg(unix)'.dependencies]
4954
exec = "0.3.1"
5055

assets/icon.ico

35.8 KB
Binary file not shown.

assets/icon.png

11.5 KB
Loading

assets/icon_64.png

8.89 KB
Loading

build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
use anyhow::Result;
22
use vergen::{vergen, Config};
33

4-
fn main() -> Result<()> { vergen(Config::default()) }
4+
fn main() -> Result<()> {
5+
#[cfg(windows)]
6+
{
7+
winres::WindowsResource::new().set_icon("assets/icon.ico").compile()?;
8+
}
9+
vergen(Config::default())
10+
}

src/app.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ impl Default for ViewConfig {
7979
}
8080
}
8181

82+
pub struct SymbolReference {
83+
pub symbol_name: String,
84+
pub section_index: usize,
85+
}
86+
8287
#[derive(serde::Deserialize, serde::Serialize)]
8388
#[serde(default)]
8489
pub struct ViewState {
@@ -89,7 +94,7 @@ pub struct ViewState {
8994
#[serde(skip)]
9095
pub highlighted_symbol: Option<String>,
9196
#[serde(skip)]
92-
pub selected_symbol: Option<String>,
97+
pub selected_symbol: Option<SymbolReference>,
9398
#[serde(skip)]
9499
pub current_view: View,
95100
#[serde(skip)]

src/main.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,27 @@
33

44
use std::{path::PathBuf, rc::Rc, sync::Mutex};
55

6+
use anyhow::{Error, Result};
67
use cfg_if::cfg_if;
8+
use eframe::IconData;
79
use time::UtcOffset;
810

11+
fn load_icon() -> Result<IconData> {
12+
use bytes::Buf;
13+
let decoder = png::Decoder::new(include_bytes!("../assets/icon_64.png").reader());
14+
let mut reader = decoder.read_info()?;
15+
let mut buf = vec![0; reader.output_buffer_size()];
16+
let info = reader.next_frame(&mut buf)?;
17+
if info.bit_depth != png::BitDepth::Eight {
18+
return Err(Error::msg("Invalid bit depth"));
19+
}
20+
if info.color_type != png::ColorType::Rgba {
21+
return Err(Error::msg("Invalid color type"));
22+
}
23+
buf.truncate(info.buffer_size());
24+
Ok(IconData { rgba: buf, width: info.width, height: info.height })
25+
}
26+
927
// When compiling natively:
1028
#[cfg(not(target_arch = "wasm32"))]
1129
fn main() {
@@ -19,7 +37,15 @@ fn main() {
1937

2038
let exec_path: Rc<Mutex<Option<PathBuf>>> = Rc::new(Mutex::new(None));
2139
let exec_path_clone = exec_path.clone();
22-
let native_options = eframe::NativeOptions::default();
40+
let mut native_options = eframe::NativeOptions::default();
41+
match load_icon() {
42+
Ok(data) => {
43+
native_options.icon_data = Some(data);
44+
}
45+
Err(e) => {
46+
log::warn!("Failed to load application icon: {}", e);
47+
}
48+
}
2349
// native_options.renderer = eframe::Renderer::Wgpu;
2450
eframe::run_native(
2551
"objdiff",

src/obj/elf.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use object::{
99
R_PPC_EMB_SDA21, R_PPC_REL14, R_PPC_REL24,
1010
},
1111
Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget,
12-
SectionKind, Symbol, SymbolKind, SymbolSection,
12+
SectionIndex, SectionKind, Symbol, SymbolKind, SymbolSection,
1313
};
1414

1515
use crate::obj::{
@@ -192,9 +192,7 @@ fn relocations_by_section(
192192
obj_file: &File<'_>,
193193
section: &mut ObjSection,
194194
) -> Result<Vec<ObjReloc>> {
195-
let obj_section = obj_file
196-
.section_by_name(&section.name)
197-
.ok_or_else(|| anyhow::Error::msg("Failed to locate section"))?;
195+
let obj_section = obj_file.section_by_index(SectionIndex(section.index))?;
198196
let mut relocations = Vec::<ObjReloc>::new();
199197
for (address, reloc) in obj_section.relocations() {
200198
let symbol = match reloc.target() {

src/views/data_diff.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ use egui_extras::{Size, StripBuilder, TableBuilder};
55
use time::format_description;
66

77
use crate::{
8-
app::{View, ViewConfig, ViewState},
8+
app::{SymbolReference, View, ViewConfig, ViewState},
99
jobs::Job,
1010
obj::{ObjDataDiff, ObjDataDiffKind, ObjInfo, ObjSection},
1111
views::{write_text, COLOR_RED},
1212
};
1313

1414
const BYTES_PER_ROW: usize = 16;
1515

16-
fn find_section<'a>(obj: &'a ObjInfo, section_name: &str) -> Option<&'a ObjSection> {
17-
obj.sections.iter().find(|s| s.name == section_name)
16+
fn find_section<'a>(obj: &'a ObjInfo, selected_symbol: &SymbolReference) -> Option<&'a ObjSection> {
17+
obj.sections.get(selected_symbol.section_index)
1818
}
1919

2020
fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config: &ViewConfig) {
@@ -132,11 +132,11 @@ fn data_table_ui(
132132
table: TableBuilder<'_>,
133133
left_obj: &ObjInfo,
134134
right_obj: &ObjInfo,
135-
section_name: &str,
135+
selected_symbol: &SymbolReference,
136136
config: &ViewConfig,
137137
) -> Option<()> {
138-
let left_section = find_section(left_obj, section_name)?;
139-
let right_section = find_section(right_obj, section_name)?;
138+
let left_section = find_section(left_obj, selected_symbol)?;
139+
let right_section = find_section(right_obj, selected_symbol)?;
140140

141141
let total_bytes = left_section.data_diff.iter().fold(0usize, |accum, item| accum + item.len);
142142
if total_bytes == 0 {
@@ -219,7 +219,7 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
219219
ui.style_mut().override_text_style =
220220
Some(egui::TextStyle::Monospace);
221221
ui.style_mut().wrap = Some(false);
222-
ui.colored_label(Color32::WHITE, selected_symbol);
222+
ui.colored_label(Color32::WHITE, &selected_symbol.symbol_name);
223223
ui.label("Diff target:");
224224
ui.separator();
225225
});

0 commit comments

Comments
 (0)