Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. use ::std::{*,
  2. ops::Not,
  3. };
  4. use ::libc::{
  5. mmap,
  6. MAP_ANONYMOUS, MAP_PRIVATE,
  7. PROT_READ, PROT_WRITE, PROT_EXEC,
  8. };
  9.  
  10. #[cfg(target_os = "linux")]
  11. fn hello_world () -> !
  12. {
  13. static HELLO_WORLD: [u8; 38] =
  14. *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"
  15. ;
  16. unsafe {
  17. let addr = mmap(
  18. ptr::null_mut(),
  19. 0x1000,
  20. PROT_READ | PROT_WRITE | PROT_EXEC,
  21. MAP_ANONYMOUS | MAP_PRIVATE,
  22. -1,
  23. 0,
  24. ) as *mut u8;
  25. assert!(addr.is_null().not());
  26. ptr::copy_nonoverlapping(
  27. &HELLO_WORLD as *const u8,
  28. addr,
  29. HELLO_WORLD.len(),
  30. );
  31. mem::transmute::<_, fn() -> !>(addr)()
  32. }
  33. }
  34.  
  35. fn main ()
  36. {
  37. hello_world();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement