#bindings #assembly #latest-version

sys keystone-engine

Rust bindings for the Keystone Engine assembler library

1 unstable release

0.1.0 Nov 14, 2022

#77 in #latest-version

Download history 7/week @ 2024-02-18 26/week @ 2024-02-25 12/week @ 2024-03-03 21/week @ 2024-03-10 5/week @ 2024-03-17

64 downloads per month
Used in hyperpom

GPL-2.0 license

22MB
308K SLoC

Bitbake 226K SLoC // 0.0% comments C++ 64K SLoC // 0.1% comments OCaml 7K SLoC // 0.1% comments C 3K SLoC // 0.2% comments Python 3K SLoC // 0.3% comments Java 587 SLoC // 0.6% comments C# 575 SLoC // 0.2% comments VB6 540 SLoC // 0.3% comments Rust 454 SLoC // 0.1% comments Go 323 SLoC // 0.1% comments Shell 280 SLoC // 0.2% comments Assembly 271 SLoC // 0.1% comments PowerShell 237 SLoC // 0.3% comments JavaScript 222 SLoC // 0.1% comments Visual Studio Project 182 SLoC Ruby 180 SLoC // 0.1% comments Haskell 139 SLoC // 0.3% comments Visual Studio Solution 70 SLoC Batch 58 SLoC // 0.2% comments Cabal 34 SLoC // 0.1% comments Forge Config 4 SLoC

Contains (static library, 4KB) keystone/bindings/vb6/keystone.lib

KEYSTONE-ENGINE BINDINGS
Unofficial Rust bindings for the Keystone Engine


shields.io license shields.io version shields.io supported keystone version
shields.io crates.io shields.io crates.io


These Rust bindings are an alternative to the ones available in the official repository and support version 0.9.2 of the Keystone Engine.

Why Release New Bindings If Official Ones Exist?

To publish a crate on crates.io, all its dependencies must also come from crates.io. There is already a crate providing bindings for Keystone. However, the latest version it supports, is version 0.9.0 of Keystone. This version has bugs, which, fortunately, are fixed in version 0.9.2. For this reason, and because the current crate of Keystone has not been updated for years, these bindings can be used instead.

These bindings are heavily inspired from the official ones and do not alter the API too much compared to the original.

Example

This example, taken from the official repo, should work out of the box.

Add the following dependency to Cargo.toml:

keystone_engine = { version = "0.1.0", features = ["build-from-src"] }

Note: You can use either build-from-src to build the Keystone Engine or use-system-lib if you have already installed the Keystone library on your system.

You should now be able to run the following code:

use keystone_engine::*;

fn main() {
    let engine =
        Keystone::new(Arch::X86, Mode::MODE_32).expect("Could not initialize Keystone engine");

    engine
        .option(OptionType::SYNTAX, OptionValue::SYNTAX_NASM)
        .expect("Could not set option to nasm syntax");

    let result = engine
        .asm("mov ah, 0x80".to_string(), 0)
        .expect("Could not assemble");

    println!("ASM result: {}", result);

    if let Err(err) = engine.asm("INVALID".to_string(), 0) {
        println!("Error: {}", err);
    }
}

Credits

Dependencies