Instantly share code, notes, and snippets.

@yardenshafir yardenshafir/ExRegisterHost.c Secret
Last active Dec 27, 2018

Embed
What would you like to do?
NTSTATUS ExRegisterHost(_Out_ PHOST_LIST_ENTRY ExtensionHost, _In_ ULONG Unused, _In_ PHOST_INFORMATION HostInformation)
{
NTSTATUS Status = STATUS_SUCCESS;
// Allocate memory for a new HOST_LIST_ENTRY
PHOST_LIST_ENTRY p = ExAllocatePoolWithTag(HostInformation->PoolType, 0x60, 'HExE');
if (p == nullptr)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
//
// Initialize a new HOST_LIST_ENTRY
//
p->Flags &= 0xFE;
p->RefCount = 1;
p->FunctionTable = 0;
p->ExtensionId = HostInformation->ExtensionId;
p->ExtensionVersion = HostInformation->ExtensionVersion;
p->hostInterface = HostInformation->hostInterface;
p->FunctionAddress = HostInformation->FunctionAddress;
p->ArgForFunction = HostInformation->ArgForFunction;
p->Lock = 0;
p->RundownRef = 0;
// Search for an existing listEntry with the same version and id.
PHOST_LIST_ENTRY listEntry = ExpFindHost(HostInformation->ExtensionId, HostInformation->ExtensionVersion);
if (listEntry)
{
Status = STATUS_OBJECT_NAME_COLLISION;
ExpDereferenceHost(p);
ExpDereferenceHost(listEntry);
}
else
{
// Insert the new HOST_LIST_ENTRY to the end of ExpHostList.
if ( *lastHostListEntry != &firstHostListEntry )
{
__fastfail();
}
firstHostListEntry->Prev = &p;
p->Next = firstHostListEntry;
lastHostListEntry = p;
ExtensionHost = p;
}
return Status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment