Skip to content

Instantly share code, notes, and snippets.

@hfiref0x
Last active April 18, 2023 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hfiref0x/75b8c5093e19511e2248fbda4c4af2f8 to your computer and use it in GitHub Desktop.
Save hfiref0x/75b8c5093e19511e2248fbda4c4af2f8 to your computer and use it in GitHub Desktop.
void __fastcall Func007(
int IoControlCode,
MEMOP *InputBuffer,
__int64 InputBufferLength,
MEMOP *OutputBuffer,
int OutputBufferLength,
_DWORD *StatusInformation)
{
PHYSICAL_ADDRESS PhysicalAddress;
PMDL MemoryDescriptorList;
PVOID BaseAddress;
PVOID MappedSystemVa;
*StatusInformation = OutputBufferLength;
if ( IoControlCode == 0x81000000 )
{
MemoryDescriptorList = IoAllocateMdl(InputBuffer->VirtualAddress, InputBuffer->Length, 0, 1u, 0i64);
if ( MemoryDescriptorList )
{
MmProbeAndLockPages(MemoryDescriptorList, 1, IoReadAccess);
if ( (MemoryDescriptorList->MdlFlags & 5) != 0 )
MappedSystemVa = MemoryDescriptorList->MappedSystemVa;
else
MappedSystemVa = MmMapLockedPagesSpecifyCache(MemoryDescriptorList, 0, MmCached, 0i64, 0, 0x10u);
if ( MappedSystemVa )
{
if ( (PhysicalAddress = MmGetPhysicalAddress(InputBuffer->BaseAddress)
&& PhysicalAddress.LowPart
|| PhysicalAddress.HighPart > 0 )
{
BaseAddress = MmMapIoSpace(PhysicalAddress, LODWORD(InputBuffer->Length), MmNonCached);
if ( BaseAddress )
{
qmemcpy(BaseAddress, MappedSystemVa, LODWORD(InputBuffer->Length));
MmUnmapIoSpace(BaseAddress, LODWORD(InputBuffer->Length));
}
}
}
MmUnlockPages(MemoryDescriptorList);
IoFreeMdl(MemoryDescriptorList);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment