Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use ::std::{*,
- ops::Not,
- };
- use ::libc::{
- mmap,
- MAP_ANONYMOUS, MAP_PRIVATE,
- PROT_READ, PROT_WRITE, PROT_EXEC,
- };
- #[cfg(target_os = "linux")]
- fn hello_world () -> !
- {
- static HELLO_WORLD: [u8; 38] =
- *b"\x6a\x01\x5f\x89\xf8\x6a\x0d\x5a\xeb\x0a\x5e\x0f\x05\x6a\x3c\x58\xff\xcf\x0f\x05\xe8\xf1\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64\x21\x0a"
- ;
- unsafe {
- let addr = mmap(
- ptr::null_mut(),
- 0x1000,
- PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_ANONYMOUS | MAP_PRIVATE,
- -1,
- 0,
- ) as *mut u8;
- assert!(addr.is_null().not());
- ptr::copy_nonoverlapping(
- &HELLO_WORLD as *const u8,
- addr,
- HELLO_WORLD.len(),
- );
- mem::transmute::<_, fn() -> !>(addr)()
- }
- }
- fn main ()
- {
- hello_world();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement