Skip to content

Commit c45f4bb

Browse files
committed
Diff schema updates & WASM updates
1 parent b0c5431 commit c45f4bb

File tree

8 files changed

+60
-22
lines changed

8 files changed

+60
-22
lines changed

objdiff-core/protos/diff.proto

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ enum SymbolFlag {
2121
SYMBOL_NONE = 0;
2222
SYMBOL_GLOBAL = 1;
2323
SYMBOL_LOCAL = 2;
24-
SYMBOL_WEAK = 3;
25-
SYMBOL_COMMON = 4;
26-
SYMBOL_HIDDEN = 5;
24+
SYMBOL_WEAK = 4;
25+
SYMBOL_COMMON = 8;
26+
SYMBOL_HIDDEN = 16;
2727
}
2828

2929
// A single parsed instruction
@@ -122,10 +122,17 @@ message InstructionBranchTo {
122122
uint32 branch_index = 2;
123123
}
124124

125-
message FunctionDiff {
125+
message SymbolRef {
126+
optional uint32 section_index = 1;
127+
uint32 symbol_index = 2;
128+
}
129+
130+
message SymbolDiff {
126131
Symbol symbol = 1;
127132
repeated InstructionDiff instructions = 2;
128133
optional float match_percent = 3;
134+
// The symbol ref in the _other_ object that this symbol was diffed against
135+
optional SymbolRef target = 5;
129136
}
130137

131138
message DataDiff {
@@ -140,7 +147,7 @@ message SectionDiff {
140147
SectionKind kind = 2;
141148
uint64 size = 3;
142149
uint64 address = 4;
143-
repeated FunctionDiff functions = 5;
150+
repeated SymbolDiff symbols = 5;
144151
repeated DataDiff data = 6;
145152
optional float match_percent = 7;
146153
}
479 Bytes
Binary file not shown.

objdiff-core/src/bindings/diff.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
ObjDataDiff, ObjDataDiffKind, ObjDiff, ObjInsArgDiff, ObjInsBranchFrom, ObjInsBranchTo,
55
ObjInsDiff, ObjInsDiffKind, ObjSectionDiff, ObjSymbolDiff,
66
},
7+
obj,
78
obj::{
89
ObjInfo, ObjIns, ObjInsArg, ObjInsArgValue, ObjReloc, ObjSectionKind, ObjSymbol,
910
ObjSymbolFlagSet, ObjSymbolFlags,
@@ -39,14 +40,14 @@ impl ObjectDiff {
3940
impl SectionDiff {
4041
pub fn new(obj: &ObjInfo, section_index: usize, section_diff: &ObjSectionDiff) -> Self {
4142
let section = &obj.sections[section_index];
42-
let functions = section_diff.symbols.iter().map(|d| FunctionDiff::new(obj, d)).collect();
43+
let symbols = section_diff.symbols.iter().map(|d| SymbolDiff::new(obj, d)).collect();
4344
let data = section_diff.data_diff.iter().map(|d| DataDiff::new(obj, d)).collect();
4445
Self {
4546
name: section.name.to_string(),
4647
kind: SectionKind::from(section.kind) as i32,
4748
size: section.size,
4849
address: section.address,
49-
functions,
50+
symbols,
5051
data,
5152
match_percent: section_diff.match_percent,
5253
}
@@ -64,23 +65,32 @@ impl From<ObjSectionKind> for SectionKind {
6465
}
6566
}
6667

67-
impl FunctionDiff {
68+
impl From<obj::SymbolRef> for SymbolRef {
69+
fn from(value: obj::SymbolRef) -> Self {
70+
Self {
71+
section_index: if value.section_idx == obj::SECTION_COMMON {
72+
None
73+
} else {
74+
Some(value.section_idx as u32)
75+
},
76+
symbol_index: value.symbol_idx as u32,
77+
}
78+
}
79+
}
80+
81+
impl SymbolDiff {
6882
pub fn new(object: &ObjInfo, symbol_diff: &ObjSymbolDiff) -> Self {
6983
let (_section, symbol) = object.section_symbol(symbol_diff.symbol_ref);
70-
// let diff_symbol = symbol_diff.diff_symbol.map(|symbol_ref| {
71-
// let (_section, symbol) = object.section_symbol(symbol_ref);
72-
// Symbol::from(symbol)
73-
// });
7484
let instructions = symbol_diff
7585
.instructions
7686
.iter()
7787
.map(|ins_diff| InstructionDiff::new(object, ins_diff))
7888
.collect();
7989
Self {
8090
symbol: Some(Symbol::new(symbol)),
81-
// diff_symbol,
8291
instructions,
8392
match_percent: symbol_diff.match_percent,
93+
target: symbol_diff.target_symbol.map(SymbolRef::from),
8494
}
8595
}
8696
}
@@ -110,7 +120,7 @@ impl Symbol {
110120
fn symbol_flags(value: ObjSymbolFlagSet) -> u32 {
111121
let mut flags = 0u32;
112122
if value.0.contains(ObjSymbolFlags::Global) {
113-
flags |= SymbolFlag::SymbolNone as u32;
123+
flags |= SymbolFlag::SymbolGlobal as u32;
114124
}
115125
if value.0.contains(ObjSymbolFlags::Local) {
116126
flags |= SymbolFlag::SymbolLocal as u32;

objdiff-core/src/config/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use std::{
66
};
77

88
use anyhow::{anyhow, Context, Result};
9-
use bimap::BiBTreeMap;
109
use filetime::FileTime;
1110
use globset::{Glob, GlobSet, GlobSetBuilder};
1211

1312
#[derive(Default, Clone, serde::Serialize, serde::Deserialize)]
13+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify), tsify(from_wasm_abi))]
1414
pub struct ProjectConfig {
1515
#[serde(default, skip_serializing_if = "Option::is_none")]
1616
pub min_version: Option<String>,
@@ -55,6 +55,7 @@ impl ProjectConfig {
5555
}
5656

5757
#[derive(Default, Clone, serde::Serialize, serde::Deserialize)]
58+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify), tsify(from_wasm_abi))]
5859
pub struct ProjectObject {
5960
#[serde(default, skip_serializing_if = "Option::is_none")]
6061
pub name: Option<String>,
@@ -78,9 +79,15 @@ pub struct ProjectObject {
7879
pub symbol_mappings: Option<SymbolMappings>,
7980
}
8081

81-
pub type SymbolMappings = BiBTreeMap<String, String>;
82+
#[cfg(feature = "wasm")]
83+
#[tsify_next::declare]
84+
pub type SymbolMappings = std::collections::BTreeMap<String, String>;
85+
86+
#[cfg(not(feature = "wasm"))]
87+
pub type SymbolMappings = bimap::BiBTreeMap<String, String>;
8288

8389
#[derive(Default, Clone, serde::Serialize, serde::Deserialize)]
90+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify), tsify(from_wasm_abi))]
8491
pub struct ProjectObjectMetadata {
8592
#[serde(default, skip_serializing_if = "Option::is_none")]
8693
pub complete: Option<bool>,
@@ -95,6 +102,7 @@ pub struct ProjectObjectMetadata {
95102
}
96103

97104
#[derive(Default, Clone, serde::Serialize, serde::Deserialize)]
105+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify), tsify(from_wasm_abi))]
98106
pub struct ProjectProgressCategory {
99107
#[serde(default)]
100108
pub id: String,
@@ -154,6 +162,7 @@ impl ProjectObject {
154162
}
155163

156164
#[derive(Default, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
165+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify), tsify(from_wasm_abi))]
157166
pub struct ScratchConfig {
158167
#[serde(default, skip_serializing_if = "Option::is_none")]
159168
pub platform: Option<String>,

objdiff-core/src/diff/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ pub enum ArmR9Usage {
155155
const fn default_true() -> bool { true }
156156

157157
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
158-
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
159-
#[cfg_attr(feature = "wasm", tsify(from_wasm_abi))]
158+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify), tsify(from_wasm_abi))]
160159
#[serde(default)]
161160
pub struct DiffObjConfig {
162161
pub relax_reloc_diffs: bool,
@@ -637,6 +636,7 @@ struct SectionMatch {
637636
}
638637

639638
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, serde::Deserialize, serde::Serialize)]
639+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify), tsify(from_wasm_abi))]
640640
pub struct MappingConfig {
641641
/// Manual symbol mappings
642642
pub mappings: SymbolMappings,

objdiff-wasm/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "objdiff-wasm",
3-
"version": "2.0.0",
3+
"version": "2.5.0",
44
"description": "A local diffing tool for decompilation projects.",
55
"author": {
66
"name": "Luke Street",
@@ -21,7 +21,7 @@
2121
"build": "tsup",
2222
"build:all": "npm run build:wasm && npm run build:proto && npm run build",
2323
"build:proto": "protoc --ts_out=gen --ts_opt add_pb_suffix,eslint_disable,ts_nocheck,use_proto_field_name --proto_path=../objdiff-core/protos ../objdiff-core/protos/*.proto",
24-
"build:wasm": "cd ../objdiff-core && wasm-pack build --out-dir ../objdiff-wasm/pkg --target web -- --features arm,dwarf,ppc,x86,wasm"
24+
"build:wasm": "cd ../objdiff-core && wasm-pack build --out-dir ../objdiff-wasm/pkg --target web -- --features arm,arm64,dwarf,config,ppc,x86,wasm"
2525
},
2626
"dependencies": {
2727
"@protobuf-ts/runtime": "^2.9.4"

objdiff-wasm/src/main.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,17 @@ export function displayDiff(diff: InstructionDiff, baseAddr: bigint, cb: (text:
194194
cb({type: 'spacing', count: 4});
195195
}
196196
cb({type: 'opcode', mnemonic: ins.mnemonic, opcode: ins.opcode});
197+
let arg_diff_idx = 0; // non-PlainText argument index
197198
for (let i = 0; i < ins.arguments.length; i++) {
198199
if (i === 0) {
199200
cb({type: 'spacing', count: 1});
200201
}
201202
const arg = ins.arguments[i].value;
202-
const diff_index = diff.arg_diff[i]?.diff_index;
203+
let diff_index: number | undefined;
204+
if (arg.oneofKind !== 'plain_text') {
205+
diff_index = diff.arg_diff[arg_diff_idx]?.diff_index;
206+
arg_diff_idx++;
207+
}
203208
switch (arg.oneofKind) {
204209
case "plain_text":
205210
cb({type: 'basic', text: arg.plain_text, diff_index});

objdiff-wasm/src/worker.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,19 @@ self.onmessage = (event: MessageEvent<InMessage>) => {
7373
const result = await handler(data as never);
7474
const end = performance.now();
7575
console.debug(`Worker message ${data.messageId} took ${end - start}ms`);
76+
let transfer: Transferable[] = [];
77+
if (result instanceof Uint8Array) {
78+
console.log("Transferring!", result.byteLength);
79+
transfer = [result.buffer];
80+
} else {
81+
console.log("Didn't transfer", typeof result);
82+
}
7683
self.postMessage({
7784
type: 'result',
7885
result: result,
7986
error: null,
8087
messageId,
81-
} as OutMessage);
88+
} as OutMessage, {transfer});
8289
} else {
8390
throw new Error(`No handler for ${data.type}`);
8491
}

0 commit comments

Comments
 (0)