summaryrefslogtreecommitdiff
path: root/plugins/svd/src
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-18 14:42:05 -0400
committerMason Reed <mason@vector35.com>2025-05-04 21:31:04 -0400
commit42bb3938df78686b6d1ceae003ce8c149f8dc9d8 (patch)
treecb3f66bc6e396cfd8f6d5c68b24a80f19fc51ead /plugins/svd/src
parent178887ba4d503838c444a0c976ac5538117fd2fb (diff)
Add a setting to disable creating a backing memory region for SVD regions
This is apart of https://github.com/Vector35/binaryninja-api/issues/6678
Diffstat (limited to 'plugins/svd/src')
-rw-r--r--plugins/svd/src/mapper.rs37
-rw-r--r--plugins/svd/src/settings.rs17
2 files changed, 38 insertions, 16 deletions
diff --git a/plugins/svd/src/mapper.rs b/plugins/svd/src/mapper.rs
index c0ca5e99..0a476481 100644
--- a/plugins/svd/src/mapper.rs
+++ b/plugins/svd/src/mapper.rs
@@ -163,24 +163,29 @@ impl DeviceMapper {
let memory_info =
self.peripheral_block_memory_info(peripheral, address_block, block_name.clone());
- // Add the block segment, section and backing memory.
- let data_memory = DataBuffer::new(&vec![0; address_block.size as usize]).unwrap();
- let added_memory = view.memory_map().add_data_memory_region(
- &block_name,
- block_addr,
- &data_memory,
- Some(memory_info.segment_flags),
- );
- view.add_segment(memory_info.segment);
- view.add_section(memory_info.section);
-
- if !added_memory {
- log::error!(
- "Failed to add memory for peripheral block! {} @ 0x{:x}",
- block_name,
- block_addr
+ // Add the block segment, section and backing memory (optional).
+ if self.settings.add_backing_regions {
+ // Because adding a memory region will add a possibly large memory buffer in the BNDB, this
+ // is optional. if a user disables this, they cannot write to the segment until they add a backing memory region.
+ let data_memory = DataBuffer::new(&vec![0; address_block.size as usize]).unwrap();
+ let added_memory = view.memory_map().add_data_memory_region(
+ &block_name,
+ block_addr,
+ &data_memory,
+ Some(memory_info.segment_flags),
);
+
+ if !added_memory {
+ log::error!(
+ "Failed to add memory for peripheral block! {} @ 0x{:x}",
+ block_name,
+ block_addr
+ );
+ }
}
+
+ view.add_segment(memory_info.segment);
+ view.add_section(memory_info.section);
// Handle usage specific stuff like adding registers.
match address_block.usage {
diff --git a/plugins/svd/src/settings.rs b/plugins/svd/src/settings.rs
index ca6df47f..9b4a9e07 100644
--- a/plugins/svd/src/settings.rs
+++ b/plugins/svd/src/settings.rs
@@ -5,12 +5,15 @@ use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct LoadSettings {
+ pub add_backing_regions: bool,
pub add_bitfields: bool,
pub add_comments: bool,
pub auto_load_file: Option<PathBuf>,
}
impl LoadSettings {
+ pub const ADD_BACKING_REGIONS_DEFAULT: bool = true;
+ pub const ADD_BACKING_REGIONS_SETTING: &'static str = "analysis.svd.addBackingRegions";
pub const ADD_BITFIELDS_DEFAULT: bool = true;
pub const ADD_BITFIELDS_SETTING: &'static str = "analysis.svd.addBitfields";
pub const ADD_COMMENTS_DEFAULT: bool = true;
@@ -21,6 +24,15 @@ impl LoadSettings {
pub fn register() {
let bn_settings = Settings::new();
+ let add_backing_region_props = json!({
+ "title" : "Add Backing Regions",
+ "type" : "boolean",
+ "default" : Self::ADD_BACKING_REGIONS_DEFAULT,
+ "description" : "Whether to add backing regions. Backing regions allow you to write to the underlying memory of a view, but will take up space in the BNDB.",
+ });
+ bn_settings
+ .register_setting_json(Self::ADD_BACKING_REGIONS_SETTING, add_backing_region_props.to_string());
+
let add_bitfields_props = json!({
"title" : "Add Bitfields",
"type" : "boolean",
@@ -53,6 +65,10 @@ impl LoadSettings {
let mut load_settings = LoadSettings::default();
let settings = Settings::new();
let mut query_opts = QueryOptions::new_with_view(view);
+ if settings.contains(Self::ADD_BACKING_REGIONS_SETTING) {
+ load_settings.add_backing_regions =
+ settings.get_bool_with_opts(Self::ADD_BACKING_REGIONS_SETTING, &mut query_opts);
+ }
if settings.contains(Self::ADD_BITFIELDS_SETTING) {
load_settings.add_bitfields =
settings.get_bool_with_opts(Self::ADD_BITFIELDS_SETTING, &mut query_opts);
@@ -76,6 +92,7 @@ impl LoadSettings {
impl Default for LoadSettings {
fn default() -> Self {
Self {
+ add_backing_regions: Self::ADD_BACKING_REGIONS_DEFAULT,
add_bitfields: Self::ADD_BITFIELDS_DEFAULT,
add_comments: Self::ADD_COMMENTS_DEFAULT,
auto_load_file: None,