Implemented NtQueryVirtualMemory

This commit is contained in:
wszechpolak 2014-08-15 08:14:57 +02:00
parent b618f38e62
commit 50684f8f0d
4 changed files with 24 additions and 8 deletions

View File

@ -55,6 +55,7 @@ class Memory {
uint32_t alignment = 0x20) = 0; uint32_t alignment = 0x20) = 0;
virtual int HeapFree(uint64_t address, size_t size) = 0; virtual int HeapFree(uint64_t address, size_t size) = 0;
virtual size_t QueryInformation(uint64_t base_address, MEMORY_BASIC_INFORMATION mem_info) = 0;
virtual size_t QuerySize(uint64_t base_address) = 0; virtual size_t QuerySize(uint64_t base_address) = 0;
virtual int Protect(uint64_t address, size_t size, uint32_t access) = 0; virtual int Protect(uint64_t address, size_t size, uint32_t access) = 0;

View File

@ -415,6 +415,12 @@ int XenonMemory::HeapFree(uint64_t address, size_t size) {
} }
} }
size_t XenonMemory::QueryInformation(uint64_t base_address, MEMORY_BASIC_INFORMATION mem_info) {
uint8_t* p = Translate(base_address);
return VirtualQuery(p, &mem_info, sizeof(mem_info));
}
size_t XenonMemory::QuerySize(uint64_t base_address) { size_t XenonMemory::QuerySize(uint64_t base_address) {
if (base_address >= XENON_MEMORY_VIRTUAL_HEAP_LOW && if (base_address >= XENON_MEMORY_VIRTUAL_HEAP_LOW &&
base_address < XENON_MEMORY_VIRTUAL_HEAP_HIGH) { base_address < XENON_MEMORY_VIRTUAL_HEAP_HIGH) {

View File

@ -54,6 +54,7 @@ public:
uint32_t alignment = 0x20) override; uint32_t alignment = 0x20) override;
int HeapFree(uint64_t address, size_t size) override; int HeapFree(uint64_t address, size_t size) override;
size_t QueryInformation(uint64_t base_address, MEMORY_BASIC_INFORMATION mem_info) override;
size_t QuerySize(uint64_t base_address) override; size_t QuerySize(uint64_t base_address) override;
int Protect(uint64_t address, size_t size, uint32_t access) override; int Protect(uint64_t address, size_t size, uint32_t access) override;

View File

@ -191,15 +191,23 @@ SHIM_CALL NtFreeVirtualMemory_shim(
X_STATUS xeNtQueryVirtualMemory( X_STATUS xeNtQueryVirtualMemory(
uint32_t base_address, X_MEMORY_BASIC_INFORMATION *memory_basic_information, bool swap) { uint32_t base_address, X_MEMORY_BASIC_INFORMATION *memory_basic_information, bool swap) {
KernelState* state = shared_kernel_state_;
assert_not_null(state);
// Just pretend that there is no virtual address allocated at given base address MEMORY_BASIC_INFORMATION mem_info;
memory_basic_information->base_address = XEROUNDUP(base_address, 4096); size_t result = state->memory()->QueryInformation(base_address, mem_info);
memory_basic_information->allocation_base = NULL;
memory_basic_information->allocation_protect = 0; if (!result) {
memory_basic_information->region_size = 0; return STATUS_INVALID_PARAMETER;
memory_basic_information->state = X_MEM_FREE; }
memory_basic_information->protect = X_PAGE_NOACCESS;
memory_basic_information->type = 0; memory_basic_information->base_address = (uint32_t) mem_info.BaseAddress;
memory_basic_information->allocation_base = (uint32_t) mem_info.AllocationBase;
memory_basic_information->allocation_protect = mem_info.AllocationProtect;
memory_basic_information->region_size = mem_info.RegionSize;
memory_basic_information->state = mem_info.State;
memory_basic_information->protect = mem_info.Protect;
memory_basic_information->type = mem_info.Type;
if (swap) { if (swap) {
memory_basic_information->base_address = poly::byte_swap(memory_basic_information->base_address); memory_basic_information->base_address = poly::byte_swap(memory_basic_information->base_address);