NTSTATUS
PsLookupProcessByProcessId(
IN HANDLE ProcessId,
OUT PEPROCESS *Process
)
{
.........................
CidEntry = ExMapHandleToPointer(PspCidTable, ProcessId);
.........................
}
NTKERNELAPI
PHANDLE_TABLE_ENTRY
ExMapHandleToPointer (
IN PHANDLE_TABLE HandleTable,
IN HANDLE Handle
)
{
EXHANDLE LocalHandle;
PHANDLE_TABLE_ENTRY HandleTableEntry;
PAGED_CODE();
LocalHandle.GenericHandleOverlay = Handle;
//
// Translate the input handle to a handle table entry and make
// sure it is a valid handle.
//
HandleTableEntry = ExpLookupHandleTableEntry( HandleTable,
LocalHandle );
.....................
}
PHANDLE_TABLE_ENTRY
ExpLookupHandleTableEntry (
IN PHANDLE_TABLE HandleTable,
IN EXHANDLE Handle
)
{
ULONG i,j,k,l;
PAGED_CODE();
//
// Decode the handle index into its separate table indicies
//
l = (Handle.Index >> 24) & 255;
i = (Handle.Index >> 16) & 255;
j = (Handle.Index >> 8) & 255;
k = (Handle.Index) & 255;
//
// The last bits should be 0 into a valid handle. If a function calls
// ExpLookupHandleTableEntry for a kernel handle, it should decode the handle
// before.
//
if ( l != 0 ) {
//
// Invalid handle. Return a NULL table entry.
//
return NULL;
}
//
// Check that the top level table is present
//
if (HandleTable->Table[i] == NULL) {
return NULL;
}
........................................
}
//
// The Ex/Ob handle table package uses a common handle definition. The actual
// type definition for a handle is a pvoid and is declared in sdk/inc. This
// package uses only the low 32 bits of the pvoid pointer.
//
// For simplicity we declare a new typedef called an exhandle
//
// The 2 bits of an EXHANDLE is available to the application and is
// ignored by the system. The next 24 bits store the handle table entry
// index and is used to refer to a particular entry in a handle table.
//
// Note that this format is immutable because there are outside programs with
// hardwired code that already assumes the format of a handle.
//
typedef struct _EXHANDLE {
union {
struct {
//
// Application available tag bits
//
ULONG TagBits : 2;
//
// The handle table entry index
//
ULONG Index : 30;
};
HANDLE GenericHandleOverlay;
};
} EXHANDLE, *PEXHANDLE;
DWORD dwProcessId --------> HANDLE -------> EXHANDLE
EXHANDLE -----> TarBits 是没有使用的
所以 :4 5 6 7 都应该是 system进程 的进程ID (例子) .