コード例 #1
0
VOID
NTAPI
ExpFreeHandleTableEntry(IN PHANDLE_TABLE HandleTable,
                        IN EXHANDLE Handle,
                        IN PHANDLE_TABLE_ENTRY HandleTableEntry)
{
    ULONG OldValue, NewValue, *Free;
    ULONG i;
    PAGED_CODE();

    /* Sanity checks */
    ASSERT(HandleTableEntry->Object == NULL);
    ASSERT(HandleTableEntry == ExpLookupHandleTableEntry(HandleTable, Handle));

    /* Decrement the handle count */
    InterlockedDecrement(&HandleTable->HandleCount);

    /* Mark the handle as free */
    NewValue = (ULONG)Handle.Value & ~(SizeOfHandle(1) - 1);

    /* Check if we're FIFO */
    if (!HandleTable->StrictFIFO)
    {
        /* Select a lock index */
        i = (NewValue >> 2) % 4;

        /* Select which entry to use */
        Free = (HandleTable->HandleTableLock[i].Locked) ?
                &HandleTable->FirstFree : &HandleTable->LastFree;
    }
コード例 #2
0
ファイル: Routines.c プロジェクト: CodeBlueDev/Blackbone
/// <summary>
/// Change handle granted access
/// </summary>
/// <param name="pAccess">Request params</param>
/// <returns>Status code</returns>
NTSTATUS BBGrantAccess( IN PHANDLE_GRANT_ACCESS pAccess )
{
    NTSTATUS  status = STATUS_SUCCESS;
    PEPROCESS pProcess = NULL;
    PHANDLE_TABLE pTable = NULL;
    PHANDLE_TABLE_ENTRY pHandleEntry = NULL;
    EXHANDLE exHandle;

    // Validate dynamic offset
    if (dynData.ObjTable == 0)
    {
        DPRINT( "BlackBone: %s: Invalid ObjTable address\n", __FUNCTION__ );
        return STATUS_INVALID_ADDRESS;
    }

    status = PsLookupProcessByProcessId( (HANDLE)pAccess->pid, &pProcess );
    if (NT_SUCCESS( status ))
    {
        pTable = *(PHANDLE_TABLE*)((PUCHAR)pProcess + dynData.ObjTable);
        exHandle.Value = (ULONG_PTR)pAccess->handle;

        if (pTable)
            pHandleEntry = ExpLookupHandleTableEntry( pTable, exHandle );

        if (ExpIsValidObjectEntry( pHandleEntry ))
        {
            pHandleEntry->GrantedAccessBits = pAccess->access;
        }
        else
        {
            DPRINT( "BlackBone: %s: 0x%X:0x%X handle is invalid. HandleEntry = 0x%p\n", 
                    __FUNCTION__, pAccess->pid, pAccess->handle, pHandleEntry );

            status = STATUS_UNSUCCESSFUL;
        }
    }
    else
        DPRINT( "BlackBone: %s: PsLookupProcessByProcessId failed with status 0x%X\n", __FUNCTION__, status );

    if (pProcess)
        ObDereferenceObject( pProcess );

    return status;
}