|
1 | | -# Unicorn-engine |
2 | | - |
3 | | -Rust bindings for the [Unicorn](http://www.unicorn-engine.org/) emulator with utility functions. |
4 | | - |
5 | | -Checkout Unicorn2 source code at [dev branch](https://github.com/unicorn-engine/unicorn/tree/dev). |
6 | | - |
7 | | -```rust |
8 | | -use unicorn_engine::{Arch, Mode, Prot, SECOND_SCALE, Unicorn, RegisterARM}; |
9 | | - |
10 | | -fn main() { |
11 | | - let arm_code32: Vec<u8> = vec![0x17, 0x00, 0x40, 0xe2]; // sub r0, #23 |
12 | | - |
13 | | - let mut emu = Unicorn::new(Arch::ARM, Mode::LITTLE_ENDIAN).expect("failed to initialize Unicorn instance"); |
14 | | - emu.mem_map(0x1000, 0x4000, Prot::ALL).expect("failed to map code page"); |
15 | | - emu.mem_write(0x1000, &arm_code32).expect("failed to write instructions"); |
16 | | - |
17 | | - emu.reg_write(RegisterARM::R0, 123).expect("failed write R0"); |
18 | | - emu.reg_write(RegisterARM::R5, 1337).expect("failed write R5"); |
19 | | - |
20 | | - emu.emu_start(0x1000, (0x1000 + arm_code32.len()) as u64, 10 * SECOND_SCALE, 1000).expect("failed to start emulation"); |
21 | | - assert_eq!(emu.reg_read(RegisterARM::R0).unwrap(), 100); |
22 | | - assert_eq!(emu.reg_read(RegisterARM::R5).unwrap(), 1337); |
23 | | -} |
24 | | -``` |
25 | | - |
26 | | -Further sample code can be found in [tests](./src/tests). |
27 | | - |
28 | | -## Usage |
29 | | - |
30 | | -Add this to your `Cargo.toml`: |
31 | | - |
32 | | -``` |
33 | | -[dependencies] |
34 | | -unicorn-engine = "2" |
35 | | -``` |
36 | | - |
37 | | -## Acknowledgements |
38 | | - |
39 | | -These bindings were once based on Sébastien Duquette's (@ekse) [unicorn-rs](https://github.com/unicorn-rs/unicorn-rs). We picked up the project, as it is no longer maintained. Thanks to all contributors. |
40 | | - |
| 1 | +See [Readme](https://github.com/unicorn-engine/unicorn-engine-rs/blob/main/Readme.md). |
0 commit comments