summaryrefslogtreecommitdiff
path: root/rust/src/binary_view/memory_map.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-07 23:23:44 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit067148afd1a8f9153bb5bfe6b5361b83e9f89ab6 (patch)
tree0745e9bb5f0ab51f83f76f79dfa9fbc97563cb02 /rust/src/binary_view/memory_map.rs
parent3992860ca7d636661d7b2671d5fe7cf028987be1 (diff)
[Rust] Improve `FileAccessor`
- Add unit tests - Expose read/write functionality - Add some much needed documentation when passing to memory map
Diffstat (limited to 'rust/src/binary_view/memory_map.rs')
-rw-r--r--rust/src/binary_view/memory_map.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/rust/src/binary_view/memory_map.rs b/rust/src/binary_view/memory_map.rs
index 28b52369..34ebd572 100644
--- a/rust/src/binary_view/memory_map.rs
+++ b/rust/src/binary_view/memory_map.rs
@@ -1,6 +1,6 @@
use crate::binary_view::BinaryView;
use crate::data_buffer::DataBuffer;
-use crate::file_accessor::FileAccessor;
+use crate::file_accessor::{Accessor, FileAccessor};
use crate::rc::Ref;
use crate::segment::SegmentFlags;
use crate::string::{BnString, IntoCStr};
@@ -59,6 +59,9 @@ impl MemoryMap {
}
}
+ /// Adds the memory region using a [`DataBuffer`].
+ ///
+ /// This will add the contents of the [`DataBuffer`] to the database.
pub fn add_data_memory_region(
&mut self,
name: &str,
@@ -78,11 +81,20 @@ impl MemoryMap {
}
}
- pub fn add_remote_memory_region(
+ // TODO: This really cant be safe until BNFileAccessor is ARC'd and can be freed. Probably need another thing
+ // TODO: Ontop of a file accessor in the core that would manage it. (I.e. BNFileAccessorHandle) or something.
+ /// Adds the memory region using a [`FileAccessor`].
+ ///
+ /// This does not add the region contents to the database, instead accesses to the contents
+ /// are done "remotely" to a [`FileAccessor`].
+ ///
+ /// NOTE: The [`FileAccessor`] MUST live as long as the region is available, currently there is no gurentee by
+ /// the type checker that the file accessor is tied to that of the memory region.
+ pub fn add_remote_memory_region<A: Accessor>(
&mut self,
name: &str,
start: u64,
- accessor: &mut FileAccessor,
+ accessor: &mut FileAccessor<A>,
segment_flags: Option<SegmentFlags>,
) -> bool {
let name_raw = name.to_cstr();
@@ -91,7 +103,7 @@ impl MemoryMap {
self.view.handle,
name_raw.as_ptr(),
start,
- &mut accessor.api_object,
+ &mut accessor.raw,
segment_flags.unwrap_or_default().into_raw(),
)
}