Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn unprotect(address: winapi::LPVOID, size: winapi::SIZE_T)
- {
- let mut oldprot = 0;
- unsafe { kernel32::VirtualProtect(address, size, 0x40, &mut oldprot); }
- }
- pub unsafe fn mem_set(dst: &mut [u8], value: u8)
- {
- std::ptr::write_bytes(dst.as_mut_ptr(), value, dst.len());
- }
- pub fn copy(src: &[u8], dst: &mut [u8]) {
- assert!(dst.len() >= src.len());
- unsafe {
- std::ptr::copy_nonoverlapping(src.as_ptr(), dst.as_mut_ptr(), src.len());
- }
- }
- #[macro_export]
- macro_rules! mem_put_fast {
- ($address:expr, $type:ty) => {
- *($address as *mut $type)
- };
- }
- /*
- //NOT WORK, TODO
- pub unsafe fn mem_put(ptr: *mut u8, value: &mut [u8])
- {
- if ptr != value
- {
- copy(ptr, value);
- }
- }
- pub fn create_jump(from: winapi::DWORD, to: winapi::DWORD, array: &mut [u8]) -> &mut [u8]
- {
- array[0] = 0xE9;
- unsafe { mem_put_fast!(array[1], winapi::DWORD) = to - (from + 5) }
- array
- }
- pub fn install_hook(address: winapi::DWORD, handler: winapi::DWORD, size: u32) -> bool
- {
- let mut jmp_bytes: [u8; 50];
- std::ptr::write_bytes(jmp_bytes.as_mut_ptr(), 0x90, jmp_bytes.len());
- if create_jump(address, handler, &mut jmp_bytes).len() != 0
- {
- copy(address.as_mut_ptr(), &mut jmp_bytes);
- true
- }
- else
- {
- false
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement