summaryrefslogtreecommitdiff
path: root/rust/src/section.rs
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2023-01-05 17:29:14 -0500
committerKyleMiles <krm504@nyu.edu>2023-01-06 16:29:58 -0500
commita154e45cce79b0c2264c1e1cd37a3d1bf5bc6154 (patch)
tree11f436b720edfdf37819e9e83e7131d220687074 /rust/src/section.rs
parent52edc39a7081fd6662e14fbcd473adabbbc36c7a (diff)
Rust API: Lots and lots of clippy changes
Diffstat (limited to 'rust/src/section.rs')
-rw-r--r--rust/src/section.rs38
1 files changed, 26 insertions, 12 deletions
diff --git a/rust/src/section.rs b/rust/src/section.rs
index 4eb49e69..b73809c0 100644
--- a/rust/src/section.rs
+++ b/rust/src/section.rs
@@ -70,19 +70,14 @@ impl Section {
Self { handle: raw }
}
+ #[allow(clippy::new_ret_no_self)]
+ /// You need to create a section builder, customize that section, then add it to a binary view:
+ ///
+ /// ```
+ /// bv.add_section(Section::new().align(4).entry_size(4))
+ /// ```
pub fn new<S: BnStrCompatible>(name: S, range: Range<u64>) -> SectionBuilder<S> {
- SectionBuilder {
- is_auto: false,
- name: name,
- range: range,
- semantics: Semantics::DefaultSection,
- _ty: None,
- align: 1,
- entry_size: 1,
- linked_section: None,
- info_section: None,
- info_data: 0,
- }
+ SectionBuilder::new(name, range)
}
pub fn name(&self) -> BnString {
@@ -105,6 +100,10 @@ impl Section {
unsafe { BNSectionGetLength(self.handle) as usize }
}
+ pub fn is_empty(&self) -> bool {
+ unsafe { BNSectionGetLength(self.handle) as usize == 0 }
+ }
+
pub fn address_range(&self) -> Range<u64> {
self.start()..self.end()
}
@@ -204,6 +203,21 @@ pub struct SectionBuilder<S: BnStrCompatible> {
}
impl<S: BnStrCompatible> SectionBuilder<S> {
+ pub fn new(name: S, range: Range<u64>) -> Self {
+ SectionBuilder {
+ is_auto: false,
+ name,
+ range,
+ semantics: Semantics::DefaultSection,
+ _ty: None,
+ align: 1,
+ entry_size: 1,
+ linked_section: None,
+ info_section: None,
+ info_data: 0,
+ }
+ }
+
pub fn semantics(mut self, semantics: Semantics) -> Self {
self.semantics = semantics;
self