MCPcopy Create free account
hub / github.com/Kudaes/Fiber / nt_write_virtual_memory

Function nt_write_virtual_memory

loader/dinvoke/src/lib.rs:1017–1049  ·  view source on GitHub ↗

Dynamically calls NtWriteVirtualMemory. It will return the NTSTATUS value returned by the call.

(mut handle: HANDLE, base_address: PVOID, mut buffer: PVOID, mut size: usize, bytes_written: *mut usize)

Source from the content-addressed store, hash-verified

1015///
1016/// It will return the NTSTATUS value returned by the call.
1017pub fn nt_write_virtual_memory (mut handle: HANDLE, base_address: PVOID, mut buffer: PVOID, mut size: usize, bytes_written: *mut usize) -> i32 {
1018
1019 unsafe
1020 {
1021 let ret;
1022 let func_ptr: data::NtWriteVirtualMemory;
1023 let ntdll = get_module_base_address(&lc!("ntdll.dll"));
1024
1025 if HARDWARE_BREAKPOINTS
1026 {
1027 let addr = get_function_address(ntdll, &lc!("NtWriteVirtualMemory")) as usize;
1028 HARDWARE_EXCEPTION_FUNCTION = ExceptionHandleFunction::NtWriteVirtualMemory;
1029 NT_WRITE_VIRTUAL_MEMORY_ARGS.handle = handle;
1030 NT_WRITE_VIRTUAL_MEMORY_ARGS.base_address = base_address;
1031 NT_WRITE_VIRTUAL_MEMORY_ARGS.buffer = buffer;
1032 NT_WRITE_VIRTUAL_MEMORY_ARGS.size = size;
1033 set_hardware_breakpoint(find_syscall_address(addr));
1034
1035 handle = HANDLE {0: -1};
1036 let buff = vec![20];
1037 buffer = std::mem::transmute(buff.as_ptr());
1038 size = buff.len();
1039 }
1040
1041 dynamic_invoke!(ntdll,&lc!("NtWriteVirtualMemory"),func_ptr,ret,handle,base_address,buffer,size,bytes_written);
1042
1043 match ret {
1044 Some(x) => return x,
1045 None => return -1,
1046 }
1047 }
1048
1049}
1050
1051/// Dynamically calls NtAllocateVirtualMemory.
1052///

Callers 2

prepare_syscallFunction · 0.70
map_module_to_memoryFunction · 0.50

Calls 4

get_module_base_addressFunction · 0.70
get_function_addressFunction · 0.70
set_hardware_breakpointFunction · 0.70
find_syscall_addressFunction · 0.70

Tested by

no test coverage detected