Advertisement
Guest User

t,t

a guest
Jul 8th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.91 KB | None | 0 0
  1. ...
  2. use winapi::minwindef::{LPVOID, DWORD, PDWORD};
  3.  
  4. fn main() {
  5.     let address = 0xDEADBEEF; // in practice i know the address is right ok, just trust me.
  6.     let old_protect: DWORD = 0;
  7.     let t = unsafe { kernel32::VirtualProtect(address as LPVOID, 1, 0x40, old_protect as PDWORD) };
  8.     println!("results: {}, {}", old_protect, t); // "t" returns 0, but I don't know why t.t
  9. }
  10.  
  11. /*
  12. I'm suspecting something is wrong with how I did things regarding old_protect.
  13. I know that address is valid (checked it multiple times!) and that the other args (1, 0x40) are valid as I have equivalent C++ code that works fine.
  14. VirtualProtect returns 0 when it fails - GetLastError() tells me the error is 0x3E6, which is ERROR_NOACCESS "Invalid access to memory location."
  15. VirtualProtect takes (LPVOID, DWORD, DWORD, PDWORD),
  16. LPVOID = *mut std::os::raw::c_void
  17. DWORD = u32
  18. PDWORD = *mut u32
  19.  
  20. I have no idea how to fix this :/
  21. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement