Skip to content

Commit adca0fc

Browse files
committed
add vmem_write
1 parent f7d5b1b commit adca0fc

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

crates/unicorn/src/ffi.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ extern "C" {
6161
prot: u32,
6262
paddr: *mut u64,
6363
) -> uc_error;
64+
pub fn uc_vmem_write(
65+
ungine: uc_handle,
66+
address: u64,
67+
prot: u32,
68+
bytes: *const u8,
69+
size: u64,
70+
) -> uc_error;
6471
pub fn uc_mem_map(engine: uc_handle, address: u64, size: u64, perms: u32) -> uc_error;
6572
pub fn uc_mem_map_ptr(
6673
engine: uc_handle,

crates/unicorn/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,20 @@ impl<'a, D> Unicorn<'a, D> {
375375
.into()
376376
}
377377

378+
/// Write the data in `bytes` to the emulated virtual address
379+
pub fn vmem_write(&mut self, address: u64, prot: Prot, bytes: &[u8]) -> Result<(), uc_error> {
380+
unsafe {
381+
uc_vmem_write(
382+
self.get_handle(),
383+
address,
384+
prot,
385+
bytes.as_ptr().cast(),
386+
bytes.len().try_into().unwrap(),
387+
)
388+
}
389+
.into()
390+
}
391+
378392
/// translate virtual to physical address
379393
pub fn vmem_translate(&mut self, address: u64, prot: Prot) -> Result<u64, uc_error> {
380394
let mut physical: u64 = 0;

0 commit comments

Comments
 (0)