Skip to content

Commit 261d217

Browse files
committed
Correct impls for Section in Rust API
Previously we were comparing the section raw pointer and hashing it
1 parent 52a5482 commit 261d217

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

rust/src/section.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! Sections are [crate::segment::Segment]s that are loaded into memory at run time
1616
1717
use std::fmt;
18+
use std::hash::{Hash, Hasher};
1819
use std::ops::Range;
1920

2021
use binaryninjacore_sys::*;
@@ -61,7 +62,6 @@ impl From<Semantics> for BNSectionSemantics {
6162
}
6263
}
6364

64-
#[derive(PartialEq, Eq, Hash)]
6565
pub struct Section {
6666
handle: *mut BNSection,
6767
}
@@ -161,6 +161,30 @@ impl fmt::Debug for Section {
161161
}
162162
}
163163

164+
impl PartialEq for Section {
165+
fn eq(&self, other: &Self) -> bool {
166+
// TODO: Do we want to make this complete match like this?
167+
self.name() == other.name()
168+
&& self.address_range() == other.address_range()
169+
&& self.semantics() == other.semantics()
170+
&& self.linked_section() == other.linked_section()
171+
&& self.info_section() == other.info_section()
172+
&& self.info_data() == other.info_data()
173+
&& self.align() == other.align()
174+
&& self.entry_size() == other.entry_size()
175+
&& self.auto_defined() == other.auto_defined()
176+
}
177+
}
178+
179+
impl Eq for Section {}
180+
181+
impl Hash for Section {
182+
fn hash<H: Hasher>(&self, state: &mut H) {
183+
self.name().hash(state);
184+
self.address_range().hash(state);
185+
}
186+
}
187+
164188
impl ToOwned for Section {
165189
type Owned = Ref<Self>;
166190

0 commit comments

Comments
 (0)