Skip to content

Commit 10a8f2b

Browse files
committed
rust bindings for uc_mem_read_virtual
1 parent 1a01276 commit 10a8f2b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

bindings/rust/src/ffi.rs

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ extern "C" {
4848
bytes: *mut u8,
4949
size: libc::size_t,
5050
) -> uc_error;
51+
pub fn uc_mem_read_virtual(
52+
engine: uc_handle,
53+
address: u64,
54+
prot: Permission,
55+
bytes: *mut u8,
56+
size: libc::size_t,
57+
) -> uc_error;
5158
pub fn uc_mem_map(engine: uc_handle, address: u64, size: libc::size_t, perms: u32) -> uc_error;
5259
pub fn uc_mem_map_ptr(
5360
engine: uc_handle,

bindings/rust/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,17 @@ impl<'a, D> Unicorn<'a, D> {
336336
unsafe { ffi::uc_mem_read(self.get_handle(), address, buf.as_mut_ptr(), size) }.and(Ok(buf))
337337
}
338338

339+
/// Read a range of bytes from memory at the specified emulated virtual address.
340+
pub fn mem_read_virtual(&self, address: u64, prot: Permission, buf: &mut [u8]) -> Result<(), uc_error> {
341+
unsafe { ffi::uc_mem_read_virtual(self.get_handle(), address, prot, buf.as_mut_ptr(), buf.len()) }.into()
342+
}
343+
344+
/// Return a range of bytes from memory at the specified emulated virtual address as vector.
345+
pub fn mem_read_virtual_as_vec(&self, address: u64, prot: Permission, buf: &mut [u8]) -> Result<Vec<u8>, uc_error> {
346+
let mut buf = vec![0; size];
347+
unsafe { ffi::uc_mem_read_virtual(self.get_handle(), address, prot, buf.as_mut_ptr(), buf.len()) }.and(Ok(buf))
348+
}
349+
339350
/// Write the data in `bytes` to the emulated physical address `address`
340351
pub fn mem_write(&mut self, address: u64, bytes: &[u8]) -> Result<(), uc_error> {
341352
unsafe { ffi::uc_mem_write(self.get_handle(), address, bytes.as_ptr(), bytes.len()) }.into()

0 commit comments

Comments
 (0)