Merge pull request #1569 from AfoHT/rustbindreadme
Fix Rust bindings readme example code
This commit is contained in:
@@ -12,7 +12,7 @@ fn main() {
|
|||||||
let arm_code32: Vec<u8> = vec![0x17, 0x00, 0x40, 0xe2]; // sub r0, #23
|
let arm_code32: Vec<u8> = vec![0x17, 0x00, 0x40, 0xe2]; // sub r0, #23
|
||||||
|
|
||||||
let mut unicorn = Unicorn::new(Arch::ARM, Mode::LITTLE_ENDIAN).expect("failed to initialize Unicorn instance");
|
let mut unicorn = Unicorn::new(Arch::ARM, Mode::LITTLE_ENDIAN).expect("failed to initialize Unicorn instance");
|
||||||
let mut emu = unicorn.borrow();
|
let emu = &mut unicorn;
|
||||||
emu.mem_map(0x1000, 0x4000, Permission::ALL).expect("failed to map code page");
|
emu.mem_map(0x1000, 0x4000, Permission::ALL).expect("failed to map code page");
|
||||||
emu.mem_write(0x1000, &arm_code32).expect("failed to write instructions");
|
emu.mem_write(0x1000, &arm_code32).expect("failed to write instructions");
|
||||||
|
|
||||||
@@ -20,8 +20,8 @@ fn main() {
|
|||||||
emu.reg_write(RegisterARM::R5, 1337).expect("failed write R5");
|
emu.reg_write(RegisterARM::R5, 1337).expect("failed write R5");
|
||||||
|
|
||||||
let _ = emu.emu_start(0x1000, (0x1000 + arm_code32.len()) as u64, 10 * SECOND_SCALE, 1000);
|
let _ = emu.emu_start(0x1000, (0x1000 + arm_code32.len()) as u64, 10 * SECOND_SCALE, 1000);
|
||||||
assert_eq!(emu.reg_read(RegisterARM::R0, Ok(100));
|
assert_eq!(emu.reg_read(RegisterARM::R0), Ok(100));
|
||||||
assert_eq!(emu.reg_read(RegisterARM::R5, Ok(1337));
|
assert_eq!(emu.reg_read(RegisterARM::R5), Ok(1337));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Further sample code can be found in ```tests/unicorn.rs```.
|
Further sample code can be found in ```tests/unicorn.rs```.
|
||||||
|
|||||||
Reference in New Issue
Block a user