SHARE
TWEET

Untitled

a guest Feb 12th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pub fn unprotect(address: winapi::LPVOID, size: winapi::SIZE_T)
  2. {
  3.     let mut oldprot = 0;
  4.     unsafe { kernel32::VirtualProtect(address, size, 0x40, &mut oldprot); }
  5. }
  6.  
  7. pub unsafe fn mem_set(dst: &mut [u8], value: u8)
  8. {
  9.     std::ptr::write_bytes(dst.as_mut_ptr(), value, dst.len());
  10. }
  11.  
  12. pub fn copy(src: &[u8], dst: &mut [u8]) {
  13.     assert!(dst.len() >= src.len());
  14.     unsafe {
  15.         std::ptr::copy_nonoverlapping(src.as_ptr(), dst.as_mut_ptr(), src.len());
  16.     }
  17. }
  18.  
  19. #[macro_export]
  20. macro_rules! mem_put_fast {
  21.     ($address:expr, $type:ty) => {
  22.         *($address as *mut $type)
  23.     };
  24. }
  25.  
  26. /*
  27. //NOT WORK, TODO
  28. pub unsafe fn mem_put(ptr: *mut u8, value: &mut [u8])
  29. {
  30.     if ptr != value
  31.     {
  32.         copy(ptr, value);
  33.     }
  34. }
  35.  
  36.  
  37.  
  38. pub fn create_jump(from: winapi::DWORD, to: winapi::DWORD, array: &mut [u8]) -> &mut [u8]
  39. {
  40.     array[0] = 0xE9;
  41.     unsafe { mem_put_fast!(array[1], winapi::DWORD) = to - (from + 5) }
  42.     array
  43. }
  44.  
  45. pub fn install_hook(address: winapi::DWORD, handler: winapi::DWORD, size: u32) -> bool
  46. {
  47.     let mut jmp_bytes: [u8; 50];
  48.     std::ptr::write_bytes(jmp_bytes.as_mut_ptr(), 0x90, jmp_bytes.len());
  49.    
  50.     if create_jump(address, handler, &mut jmp_bytes).len() != 0
  51.     {
  52.         copy(address.as_mut_ptr(), &mut jmp_bytes);
  53.         true
  54.     }
  55.     else
  56.     {
  57.         false
  58.     }
  59. }
  60. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top