libmwemu 0.25.2

x86 32/64bits and system internals emulator, for securely emulating malware and other stuff.
Documentation
use crate::tests::helpers;
use crate::winapi::winapi64;
use crate::windows::constants;
use crate::*;

#[test]
// test 64bits allocators
pub fn allocator64_test() {
    helpers::setup();

    let mut emu = emu64();
    emu.cfg.maps_folder = helpers::win64_maps_folder();
    emu.init_win32(false, false);

    assert_eq!(emu.maps.exists_mapname("notexist"), false);
    assert_eq!(emu.maps.get_map_by_name("notexist").is_some(), false);

    for _ in 0..700 {
        assert_eq!(emu.maps.alloc(1024).is_some(), true);
        assert_eq!(emu.maps.lib64_alloc(1024).is_some(), true);
    }

    assert_eq!(emu.maps.mem_test(), true);

    emu.maps.clear();

    // VirtualAlloc(addr, sz, flAllocationType, flProtect)
    let p = helpers::call_winapi64(
        &mut emu,
        winapi64::kernel32::VirtualAlloc,
        &[0, 1024, constants::MEM_RESERVE as u64, 0x40],
    );
    assert_eq!(emu.maps.is_allocated(p), true);

    helpers::call_winapi64(
        &mut emu,
        winapi64::kernel32::VirtualAlloc,
        &[
            0x30000000,
            1024,
            (constants::MEM_RESERVE | constants::MEM_COMMIT) as u64,
            0x40,
        ],
    );

    let committed = helpers::call_winapi64(
        &mut emu,
        winapi64::kernel32::VirtualAlloc,
        &[0x30000000, 1024, constants::MEM_COMMIT as u64, 0x40],
    );
    assert_eq!(committed, 0x30000000);

    assert_eq!(emu.maps.is_allocated(0x30000000), true);
    assert_eq!(emu.maps.mem_test(), true);
}