Improve formatting

svn path=/trunk/; revision=56457
This commit is contained in:
Timo Kreuzer 2012-05-01 09:26:45 +00:00
parent 2ab0757b32
commit bb3050e722

View file

@ -14,74 +14,85 @@
/*
* @implemented
*/
PVOID APIENTRY
EngAllocMem(ULONG Flags,
ULONG MemSize,
ULONG Tag)
PVOID
APIENTRY
EngAllocMem(
ULONG Flags,
ULONG cjMemSize,
ULONG ulTag)
{
PVOID newMem;
PVOID pvBaseAddress;
newMem = ExAllocatePoolWithTag((Flags & FL_NONPAGED_MEMORY) ? NonPagedPool : PagedPool,
MemSize,
Tag);
pvBaseAddress = ExAllocatePoolWithTag((Flags & FL_NONPAGED_MEMORY) ?
NonPagedPool : PagedPool,
cjMemSize,
ulTag);
if (newMem == NULL)
if (pvBaseAddress == NULL)
return NULL;
if (Flags & FL_ZERO_MEMORY)
RtlZeroMemory(newMem, MemSize);
RtlZeroMemory(pvBaseAddress, cjMemSize);
return newMem;
return pvBaseAddress;
}
/*
* @implemented
*/
VOID APIENTRY
EngFreeMem(PVOID Mem)
VOID
APIENTRY
EngFreeMem(PVOID pvBaseAddress)
{
ExFreePool(Mem);
ExFreePool(pvBaseAddress);
}
/*
* @implemented
*/
PVOID APIENTRY
EngAllocUserMem(SIZE_T cj, ULONG Tag)
PVOID
APIENTRY
EngAllocUserMem(SIZE_T cjSize, ULONG ulTag)
{
PVOID NewMem = NULL;
PVOID pvBaseAddress = NULL;
NTSTATUS Status;
SIZE_T MemSize = cj;
Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &NewMem, 0, &MemSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
&pvBaseAddress,
0,
&cjSize,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
if (! NT_SUCCESS(Status))
if (!NT_SUCCESS(Status))
{
return NULL;
}
/* TODO: Add allocation info to AVL tree (stored inside W32PROCESS structure) */
//hSecure = EngSecureMem(NewMem, cj);
//hSecure = EngSecureMem(pvBaseAddress, cj);
return NewMem;
return pvBaseAddress;
}
/*
* @implemented
*/
VOID APIENTRY
EngFreeUserMem(PVOID pv)
VOID
APIENTRY
EngFreeUserMem(PVOID pvBaseAddress)
{
PVOID BaseAddress = pv;
SIZE_T MemSize = 0;
SIZE_T cjSize = 0;
ZwFreeVirtualMemory(NtCurrentProcess(), &BaseAddress, &MemSize, MEM_RELEASE);
ZwFreeVirtualMemory(NtCurrentProcess(),
&pvBaseAddress,
&cjSize,
MEM_RELEASE);
/* TODO: Remove allocation info from AVL tree */
}
PVOID
APIENTRY
HackSecureVirtualMemory(
@ -91,22 +102,22 @@ HackSecureVirtualMemory(
OUT PVOID *SafeAddress)
{
NTSTATUS Status = STATUS_SUCCESS;
PMDL mdl;
PMDL pmdl;
LOCK_OPERATION Operation;
if (ProbeMode == PAGE_READONLY) Operation = IoReadAccess;
else if (ProbeMode == PAGE_READWRITE) Operation = IoModifyAccess;
else return NULL;
mdl = IoAllocateMdl(Address, Size, FALSE, TRUE, NULL);
if (mdl == NULL)
pmdl = IoAllocateMdl(Address, Size, FALSE, TRUE, NULL);
if (pmdl == NULL)
{
return NULL;
}
_SEH2_TRY
{
MmProbeAndLockPages(mdl, UserMode, Operation);
MmProbeAndLockPages(pmdl, UserMode, Operation);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@ -116,20 +127,20 @@ HackSecureVirtualMemory(
if (!NT_SUCCESS(Status))
{
IoFreeMdl(mdl);
IoFreeMdl(pmdl);
return NULL;
}
*SafeAddress = MmGetSystemAddressForMdlSafe(mdl, NormalPagePriority);
*SafeAddress = MmGetSystemAddressForMdlSafe(pmdl, NormalPagePriority);
if(!*SafeAddress)
{
MmUnlockPages(mdl);
IoFreeMdl(mdl);
MmUnlockPages(pmdl);
IoFreeMdl(pmdl);
return NULL;
}
return mdl;
return pmdl;
}
VOID
@ -137,10 +148,10 @@ APIENTRY
HackUnsecureVirtualMemory(
IN PVOID SecureHandle)
{
PMDL mdl = (PMDL)SecureHandle;
PMDL pmdl = (PMDL)SecureHandle;
MmUnlockPages(mdl);
IoFreeMdl(mdl);
MmUnlockPages(pmdl);
IoFreeMdl(pmdl);
}
/*