@@ -336,11 +336,32 @@ impl<'a, D> Unicorn<'a, D> {
336
336
unsafe { ffi:: uc_mem_read ( self . get_handle ( ) , address, buf. as_mut_ptr ( ) , size) } . and ( Ok ( buf) )
337
337
}
338
338
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 , size : usize ) -> 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
+
339
350
/// Write the data in `bytes` to the emulated physical address `address`
340
351
pub fn mem_write ( & mut self , address : u64 , bytes : & [ u8 ] ) -> Result < ( ) , uc_error > {
341
352
unsafe { ffi:: uc_mem_write ( self . get_handle ( ) , address, bytes. as_ptr ( ) , bytes. len ( ) ) } . into ( )
342
353
}
343
354
355
+ /// translate virtual to physical address
356
+ pub fn virtual_to_physical ( & mut self , address : u64 , prot : Permission ) -> Result < u64 , uc_error > {
357
+ let mut physical: u64 = 0 ;
358
+ let err = unsafe { ffi:: uc_virtual_to_physical ( self . get_handle ( ) , address, prot, & mut physical) } ;
359
+ if err != uc_error:: OK {
360
+ return Err ( err) ;
361
+ }
362
+ return Ok ( physical) ;
363
+ }
364
+
344
365
/// Map an existing memory region in the emulator at the specified address.
345
366
///
346
367
/// # Safety
0 commit comments