From 074ace03bf11aea9d78f01789c1a7ab569406067 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 7 May 2025 23:21:06 -0400 Subject: [Rust] Correct impls for `Section` Previously we were comparing the section raw pointer and hashing it --- rust/src/section.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'rust/src') diff --git a/rust/src/section.rs b/rust/src/section.rs index 77e40232..edf19582 100644 --- a/rust/src/section.rs +++ b/rust/src/section.rs @@ -15,6 +15,7 @@ //! Sections are [crate::segment::Segment]s that are loaded into memory at run time use std::fmt; +use std::hash::{Hash, Hasher}; use std::ops::Range; use binaryninjacore_sys::*; @@ -61,7 +62,6 @@ impl From for BNSectionSemantics { } } -#[derive(PartialEq, Eq, Hash)] pub struct Section { handle: *mut BNSection, } @@ -161,6 +161,30 @@ impl fmt::Debug for Section { } } +impl PartialEq for Section { + fn eq(&self, other: &Self) -> bool { + // TODO: Do we want to make this complete match like this? + self.name() == other.name() + && self.address_range() == other.address_range() + && self.semantics() == other.semantics() + && self.linked_section() == other.linked_section() + && self.info_section() == other.info_section() + && self.info_data() == other.info_data() + && self.align() == other.align() + && self.entry_size() == other.entry_size() + && self.auto_defined() == other.auto_defined() + } +} + +impl Eq for Section {} + +impl Hash for Section { + fn hash(&self, state: &mut H) { + self.name().hash(state); + self.address_range().hash(state); + } +} + impl ToOwned for Section { type Owned = Ref; -- cgit v1.3.1