GithubHelp home page GithubHelp logo

unicorn-rs's Introduction

unicorn-rs

Rust bindings for the Unicorn emulator with utility functions.

An extended version for fuzzing with AFL++ support can be found in https://github.com/aflplusplus/unicornafl.

use unicorn::RegisterARM;
use unicorn::unicorn_const::{Arch, Mode, Protection, SECOND_SCALE};

fn main() {
    let arm_code32: Vec<u8> = vec![0x17, 0x00, 0x40, 0xe2]; // sub r0, #23

    let mut unicorn = unicorn::Unicorn::new(Arch::ARM, Mode::LITTLE_ENDIAN, 0).expect("failed to initialize Unicorn instance");
    let mut emu = unicorn.borrow();
    emu.mem_map(0x1000, 0x4000, Protection::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));
}

Further sample code can be found in tests/unicorn.rs.

In addition, the bindings offer some basic utility functionalities, such as a simple heap allocator utilizing Unicorn hooks for sanitization or easily accessible debug prints. These are WIP and only tested in ARM LITTLE_ENDIAN mode.

Installation

This project has been tested on Linux, OS X and Windows.

On Windows use vcpkg

Run cp ./vcpkg/* {PATH OF VCPKG}/ports/unicorn/ OR Manual copy overwrite

Run vcpkg.exe install unicorn:x64-windows-static-md

On Linux Or Macos

Refer to the unicorn documentation to compile.

For example, run UNICORN_STATIC=yes ./make.sh to generate a static library, and then run sudo ./make.sh install to install

To Use

To use unicorn-rs, simply add it as a dependency to the Cargo.toml of your program.

[dependencies]
unicorn = { git = "https://github.com/edsky/unicorn-rs.git", version="1.0" }

Acknowledgements

These bindings are based on Sébastien Duquette's (@ekse) unicorn-rs. We picked up the project, as it is no longer maintained. Thanks to all contributers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.