83 lines
1.6 KiB
C++
83 lines
1.6 KiB
C++
/* __ __ __ __ _
|
|
* | \/ |___ _ __ ___ _ _ _ _ | \/ |__ _ _ _ __ _ __ _ ___ _ __ ___ _ _| |_
|
|
* | |\/| / -_) ' \/ _ \ '_| || | | |\/| / _` | ' \/ _` / _` / -_) ' \/ -_) ' \ _|
|
|
* |_| |_\___|_|_|_\___/_| \_, | |_| |_\__,_|_||_\__,_\__, \___|_|_|_\___|_||_\__|
|
|
* |__/ |___/
|
|
*/
|
|
|
|
#include "Domito.Internal.h"
|
|
|
|
|
|
static PVOID NTAPI DomitoDefaultMalloc(size_t s)
|
|
{
|
|
#pragma warning(disable:4996)
|
|
const PVOID mem = ExAllocatePoolWithTag(PagedPool, s, DOMITO_POOL_TAG);
|
|
if (mem)
|
|
{
|
|
RtlZeroMemory(mem, s);
|
|
}
|
|
return mem;
|
|
#pragma warning(default:4996)
|
|
}
|
|
|
|
static void NTAPI DomitoDefaultFree(PVOID p)
|
|
{
|
|
ExFreePoolWithTag(p, DOMITO_POOL_TAG);
|
|
}
|
|
|
|
DOMITO_MEMORY G_Memory = {
|
|
DomitoDefaultMalloc,
|
|
DomitoDefaultFree
|
|
};
|
|
|
|
void
|
|
DomitoGetOriginalMemoryFunctions(
|
|
_Out_opt_ PFN_DOMITO_ALLOCATE_ROUTINE* Allocator,
|
|
_Out_opt_ PFN_DOMITO_FREE_ROUTINE* Free
|
|
)
|
|
{
|
|
if (Allocator)
|
|
{
|
|
*Allocator = DomitoDefaultMalloc;
|
|
}
|
|
|
|
if (Free)
|
|
{
|
|
*Free = DomitoDefaultFree;
|
|
}
|
|
}
|
|
|
|
void
|
|
DomitoGetMemoryFunctions(
|
|
_Out_opt_ PFN_DOMITO_ALLOCATE_ROUTINE* Allocator,
|
|
_Out_opt_ PFN_DOMITO_FREE_ROUTINE* Free
|
|
)
|
|
{
|
|
if (Allocator)
|
|
{
|
|
*Allocator = G_Memory.Allocate;
|
|
}
|
|
|
|
if (Free)
|
|
{
|
|
*Free = G_Memory.Free;
|
|
}
|
|
}
|
|
|
|
void
|
|
DomitoSetMemoryFunctions(
|
|
_In_opt_ PFN_DOMITO_ALLOCATE_ROUTINE Allocator,
|
|
_In_opt_ PFN_DOMITO_FREE_ROUTINE Free
|
|
)
|
|
{
|
|
if (Allocator)
|
|
{
|
|
G_Memory.Allocate = Allocator;
|
|
}
|
|
|
|
if (Free)
|
|
{
|
|
G_Memory.Free = Free;
|
|
}
|
|
}
|