1个稳定版本
1.0.0 | 2021年11月5日 |
---|
#4 in #emu
76KB
2.5K SLoC
Qnicorn-engine
Rust的Qnicorn模拟器绑定,包含实用函数。
在 dev分支 中查看Unicorn2源代码。
use qnicorn::RegisterARM;
use qnicorn::qnicorn_const::{Arch, Mode, Permission, SECOND_SCALE};
fn main() {
let arm_code32: Vec<u8> = vec![0x17, 0x00, 0x40, 0xe2]; // sub r0, #23
let mut qnicorn = qnicorn-engine::Qnicorn::new(Arch::ARM, Mode::LITTLE_ENDIAN).expect("failed to initialize Qnicorn instance");
let mut emu = qnicorn.borrow();
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.reg_write(RegisterARM::R0 as i32, 123).expect("failed write R0");
emu.reg_write(RegisterARM::R5 as i32, 1337).expect("failed write R5");
let _ = emu.emu_start(0x1000, (0x1000 + arm_code32.len()) as u64, 10 * SECOND_SCALE, 1000);
assert_eq!(emu.reg_read(RegisterARM::R0 as i32), Ok(100));
assert_eq!(emu.reg_read(RegisterARM::R5 as i32), Ok(1337));
}
更多示例代码可以在 tests/qnicorn.rs
中找到。
用法
将此内容添加到您的 Cargo.toml
[dependencies]
qnicorn = "1.0.0"
致谢
这些绑定基于 Sébastien Duquette (@ekse) 的 unicorn-rs。由于该项目不再维护,我们将其接手。感谢所有贡献者。
依赖项
~0–2MB
~32K SLoC