Skip to content

Latest commit

 

History

History
58 lines (44 loc) · 3.36 KB

README.md

File metadata and controls

58 lines (44 loc) · 3.36 KB

ARMoured_rust

GitHub Workflow Status codecov

Provides a convenient and performant API to produce arm64/Aarch64 instructions.

Instruction Support

The instruction implementations are indexed by Encoding.

Status Instruction Types Notes
SVE encodings -
Data Processing -- Immediate -
🚧 Branches, Exception Generating and System instructions -
Loads and Stores -
Data Processing -- Register -
Data Processing -- Scalar Floating-Point and Advanced SIMD -

Note: Status ❌ means "not yet supported"

Example

Here is an example usage of the McMemory and InstrStream. The McMemory (Machine Code Memory) allocates space for one page size, while the InstrStream generates and emits instruction to this memory.

fn main() {
    let mut mem = McMemory::new_pagesize();
    let mut stream = InstrStream::new(&mut mem);
    stream.mov_64_imm(1, 0x23);
    stream.add_64_imm(0, 1, 0x4);
    stream.ret();

    // print stream disassembly before patch
    println!("Disasm before patch: ");
    stream.print_disasm();

    // patch `stream.mov_64_imm(1, 0x23);` instruction
    stream.patch_at(stream.base_ptr(), |s| {
        s.movn_64_imm(1, 4);
    });

    // print stream disassembly after patch
    println!("Disasm after patch: ");
    stream.print_disasm();

    // get stream `fn() -> u64` pointer and make memory executable 
    let func = stream.nullary_fn_ptr();
    mem.make_executable();

    // call function and get result
    let res = unsafe { func() };
    println!("Called function with result: {res:#x}");
}