sam 0.3.0

A compile time instruction assembler.
docs.rs failed to build sam-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: sam-0.2.0

sam

Foo

What is this?

I'm currently working on many assembly related projects. Most of them are written in Rust. Since inline assembly is ugly (atleast in my opinion), I work mostly with writable memory pages. This means that I have to assemble my instructions to the proper architecture via a tool (for example sam-web). This work is really boring and repetetive, also it makes it hard to trace bugs in your assembly if you only have the opcodes laying in front of you.
Therefore I decided to make a macro which utilizes kstool to create the opcodes out of a string containing your assembly. There will also be a full native solution as soon as I created the needed bindings for Keystone.

TLDR This is a macro which converts an assembly string to a Vec<u8> at compile time.

Setup

If you're Windows user, you can just skip this part, because everything is done via Powershell.
If you're on Mac OS X make sure Homebrew is installed!
If you're on Linux you have to run cargo build as root user (sudo). To do that you have to use this command:

sudo env "PATH=$PATH" cargo build

On Linux and Mac OS X, the script will install these dependencies:

  • CMake
  • Git

Keep in mind that you only need to do these steps if you're running it for the first time. After successfully installing the dependencies the script will clone Keystone, build it and install it. On Windows, the script will just download prebuilt binaries.

You can also do all of this manually, just make sure that kstool is available in your PATH!

Modes

Supported modes are (all with NASM syntax):

x64
x86

Example

#[macro_use]
extern crate sam;

fn main() {
  let asm: Vec<u8> = sam!(x64 => "mov rax, 0x1337");
  println!("{:?}", asm);
}