How to execute raw instructions from a memory buffer in Rust?

后端 未结 1 1936
囚心锁ツ
囚心锁ツ 2021-01-06 04:59

I\'m attempting to make a buffer of memory executable, then execute it in Rust. I\'ve gotten all the way until I need to cast the raw executable bytes as code/instructions.

1条回答
  •  独厮守ぢ
    2021-01-06 05:21

    Use mem::transmute to cast a raw pointer to a function pointer type.

    use std::mem;
    
    let func: unsafe extern "C" fn() = mem::transmute(map.data());
    func();
    

    0 讨论(0)
提交回复
热议问题