HyperDbg Debugger
Loading...
Searching...
No Matches
Mem.c File Reference

Implementation of cross APIs for different platforms for memory allocation. More...

#include "pch.h"

Functions

PVOID PlatformMemAllocateContiguousZeroedMemory (SIZE_T NumberOfBytes)
 Allocate a contiguous zeroed memory.
 
PVOID PlatformMemAllocateNonPagedPool (SIZE_T NumberOfBytes)
 Allocate a non-paged buffer.
 
PVOID PlatformMemAllocateNonPagedPoolWithQuota (SIZE_T NumberOfBytes)
 Allocate a non-paged buffer (use QUOTA)
 
PVOID PlatformMemAllocateZeroedNonPagedPool (SIZE_T NumberOfBytes)
 Allocate a non-paged buffer (zeroed)
 
VOID PlatformMemFreePool (PVOID BufferAddress)
 Free (dellocate) a non-paged buffer.
 

Detailed Description

Implementation of cross APIs for different platforms for memory allocation.

Author
Behrooz Abbassi (Behro.nosp@m.ozAb.nosp@m.bassi.nosp@m.@hyp.nosp@m.erdbg.nosp@m..org)
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2022-01-17

Function Documentation

◆ PlatformMemAllocateContiguousZeroedMemory()

PVOID PlatformMemAllocateContiguousZeroedMemory ( SIZE_T NumberOfBytes)

Allocate a contiguous zeroed memory.

Parameters
NumberOfBytes
Returns
PVOID
23{
24 PVOID Result = NULL;
25 PHYSICAL_ADDRESS MaxPhysicalAddr = {.QuadPart = MAXULONG64};
26
27 Result = MmAllocateContiguousMemory(NumberOfBytes, MaxPhysicalAddr);
28 if (Result != NULL)
29 RtlSecureZeroMemory(Result, NumberOfBytes);
30
31 return Result;
32}
POOL_TYPE SIZE_T NumberOfBytes
Definition Hooks.h:167
NULL()
Definition test-case-generator.py:530

◆ PlatformMemAllocateNonPagedPool()

PVOID PlatformMemAllocateNonPagedPool ( SIZE_T NumberOfBytes)

Allocate a non-paged buffer.

Parameters
NumberOfBytes
Returns
PVOID
42{
43 PVOID Result = ExAllocatePoolWithTag(NonPagedPool, NumberOfBytes, POOLTAG);
44
45 return Result;
46}
#define POOLTAG
Pool tag.
Definition Constants.h:417

◆ PlatformMemAllocateNonPagedPoolWithQuota()

PVOID PlatformMemAllocateNonPagedPoolWithQuota ( SIZE_T NumberOfBytes)

Allocate a non-paged buffer (use QUOTA)

Parameters
NumberOfBytes
Returns
PVOID
56{
57 PVOID Result = ExAllocatePool2(POOL_FLAG_NON_PAGED | POOL_FLAG_USE_QUOTA, NumberOfBytes, POOLTAG);
58
59 return Result;
60}

◆ PlatformMemAllocateZeroedNonPagedPool()

PVOID PlatformMemAllocateZeroedNonPagedPool ( SIZE_T NumberOfBytes)

Allocate a non-paged buffer (zeroed)

Parameters
NumberOfBytes
Returns
PVOID
70{
71 PVOID Result = ExAllocatePoolWithTag(NonPagedPool, NumberOfBytes, POOLTAG);
72
73 if (Result != NULL)
74 RtlSecureZeroMemory(Result, NumberOfBytes);
75
76 return Result;
77}

◆ PlatformMemFreePool()

VOID PlatformMemFreePool ( PVOID BufferAddress)

Free (dellocate) a non-paged buffer.

Parameters
BufferAddress
Returns
VOID
87{
88 ExFreePoolWithTag(BufferAddress, POOLTAG);
89}
UINT64 BOOLEAN PVOID BufferAddress
Definition HyperDbgScriptImports.h:67