summaryrefslogtreecommitdiff
path: root/rust/src/section.rs
diff options
context:
space:
mode:
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