Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object Manager Plus #2197

Open
wants to merge 85 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
2463e2c
Implement properties support for Object Manager
DartVanya Sep 10, 2024
6df0062
Enhanced Object Manager
DartVanya Sep 11, 2024
0d69a76
Merge branch 'winsiderss:master' into ObjManagerPlus
DartVanya Sep 11, 2024
726209f
Fix bug
DartVanya Sep 11, 2024
7d56d32
Center properties window to ObjMgr window
DartVanya Sep 11, 2024
0f62519
Merge branch 'winsiderss:master' into ObjManagerPlus
DartVanya Sep 12, 2024
535512f
Defied WinObj: search, statusbar, refresh
DartVanya Sep 12, 2024
2a5be4c
Merge branch 'winsiderss:master' into ObjManagerPlus
DartVanya Sep 12, 2024
9ef7295
Fix memory leaks and violations + other improvements
DartVanya Sep 13, 2024
a56cead
Merge branch 'winsiderss:master' into ObjManagerPlus
DartVanya Sep 13, 2024
7a8d222
Fix directory security bug
DartVanya Sep 13, 2024
07d02b7
Merge branch 'master' into ObjManagerPlus
DartVanya Sep 13, 2024
6129939
Fix directory security bug
DartVanya Sep 13, 2024
61ee5dc
Merge branch 'ObjManagerPlus' of https://github.com/DartVanya/systemi…
DartVanya Sep 13, 2024
3f0fcb6
Speedup search
DartVanya Sep 13, 2024
64ca49c
Merge branch 'master' into ObjManagerPlus
dmex Sep 14, 2024
de9c45d
Show File info for Device and FilterConnectionPort
DartVanya Sep 14, 2024
d32789f
Merge branch 'ObjManagerPlus' of https://github.com/DartVanya/systemi…
DartVanya Sep 14, 2024
d3717d1
Fix pool table auto refresh
DartVanya Sep 14, 2024
5d0ccff
Minor refresh fixes
DartVanya Sep 14, 2024
c6443fe
Add target resolving for Device and ALPC port
DartVanya Sep 15, 2024
2f1f76a
Merge branch 'master' into ObjManagerPlus
DartVanya Sep 15, 2024
8dbe1a7
Add target resolving for Mutant, fix search
DartVanya Sep 16, 2024
d01f1be
Merge branch 'master' into ObjManagerPlus
DartVanya Sep 16, 2024
9d5e5b6
Create resolver thread by NtCreateThreadEx
DartVanya Sep 16, 2024
e430722
Support for open symlink target in explorer
DartVanya Sep 16, 2024
c4cd9db
Merge branch 'master' into ObjManagerPlus
DartVanya Sep 16, 2024
2e873d6
Show Job process list in target column
DartVanya Sep 16, 2024
40c73c0
Fix TriState sort, add "Reset sort" context menu
DartVanya Sep 17, 2024
d241e11
Add CpuPartition type support and icons for more types
DartVanya Sep 18, 2024
39fe831
Merge branch 'winsiderss:master' into ObjManagerPlus
DartVanya Sep 18, 2024
8efc05b
Fix open of Device object in root directory
DartVanya Sep 18, 2024
d0969ea
Add MemoryPartition icon
DartVanya Sep 19, 2024
b36c721
New Object Handles page in properties
DartVanya Sep 21, 2024
636fe14
[SI] Advanced options - add menu Reset
DartVanya Sep 21, 2024
85b0bca
Add PhOpenDevice. ObjMgr Plus FINAL
DartVanya Sep 22, 2024
40df499
Merge branch 'winsiderss:master' into ObjManagerPlus
DartVanya Sep 22, 2024
117433b
Fix build
DartVanya Sep 22, 2024
523ee43
Fixed Ctrl+K to search box in PE VIew
DartVanya Sep 22, 2024
63a4e21
Open more object types when driver is disabled
DartVanya Sep 24, 2024
d1fc7bc
Support for multiple non-modal object properties windows
DartVanya Sep 24, 2024
2f12ae5
Add KphOpenObjectByTypeIndex
DartVanya Sep 25, 2024
20aadaa
Handles page: add menu - properties, menu - close
DartVanya Sep 26, 2024
521daf7
Show extended Type information in properties (works also without KSI)
DartVanya Sep 26, 2024
090eafc
Fixed closing modeless property sheet from taskbar
DartVanya Sep 27, 2024
6a54450
Update SDK
DartVanya Sep 28, 2024
90918e7
[ET] Add Desktops page to WindowStation properties
DartVanya Sep 28, 2024
28672d2
Improve object handles enumeration without KSI
DartVanya Sep 29, 2024
d2dde14
General improve of resolver speed via worker queue
DartVanya Sep 29, 2024
65047f5
Fix theme for plugins' pages trees
DartVanya Sep 30, 2024
97126e7
Merge branch 'master' into ObjManagerPlus
DartVanya Sep 30, 2024
178cfd6
Fix bug
DartVanya Sep 30, 2024
9e82cd2
Show Original name in Object prop -> Handles -> Prop window
DartVanya Oct 2, 2024
b33af14
WindowStation - Desktops page - add menu - Security
DartVanya Oct 3, 2024
2a633f4
Bring back OK button in service properties
DartVanya Oct 5, 2024
bfeaca9
Bring back OK button in service properties
DartVanya Oct 5, 2024
df35cfa
Merge branch 'ObjManagerPlus' of https://github.com/DartVanya/systemi…
DartVanya Oct 5, 2024
881c3bf
Theme fixes and enhancements
DartVanya Oct 7, 2024
fc395e6
Full DarkMode support for TaskDialog
DartVanya Oct 9, 2024
69992cc
Minor fixes
DartVanya Oct 11, 2024
ced53e6
Merge branch 'master' into master-dm
DartVanya Oct 11, 2024
b6a0d64
Merge remote-tracking branch 'upstream/master' into ObjManagerPlus
DartVanya Oct 11, 2024
bbc49c1
Merge branch 'master-dm' into ObjManagerPlus
DartVanya Oct 11, 2024
0d532c5
Security page CHECKLIST_ACLUI checks theme support
DartVanya Oct 11, 2024
4e99970
Transit from PhShow(Error|Warning|Information) to PhShow(Error|Warnin…
DartVanya Oct 12, 2024
fc988a2
Public PhThemeWindowDrawButton: tristate checkbox, radio, multiline
DartVanya Oct 12, 2024
52a5063
Merge remote-tracking branch 'upstream/master' into master-dm
DartVanya Oct 12, 2024
4b385f2
Merge branch 'master-dm' into ObjManagerPlus
DartVanya Oct 12, 2024
77db313
Better ListView theme (OpenNcThemeData hook)
DartVanya Oct 16, 2024
a42066a
Merge branch 'master-dm' into ObjManagerPlus
DartVanya Oct 22, 2024
048fb5a
Merge remote-tracking branch 'upstream/master' into master-dm
DartVanya Oct 30, 2024
f906b11
New SysLink coloring method via IAT hook
DartVanya Oct 30, 2024
9320999
Merge branch 'master-dm' into ObjManagerPlus
DartVanya Oct 30, 2024
17e3d0c
Merge branch 'master' into master-dm
jxy-s Oct 31, 2024
7934455
Small fixes
DartVanya Nov 1, 2024
5fe9630
Merge remote-tracking branch 'upstream/master' into master-dm
DartVanya Nov 1, 2024
f402c50
Merge branch 'master-dm' into ObjManagerPlus
DartVanya Nov 1, 2024
1cd222d
Merge branch 'master' into master-dm
dmex Nov 3, 2024
aecb9f9
Requested changes
DartVanya Nov 3, 2024
fb32568
Merge remote-tracking branch 'upstream/master' into ObjManagerPlus
DartVanya Nov 3, 2024
828ee39
Merge branch 'master' into master-dm
DartVanya Nov 3, 2024
ce9ebf9
Requested changes
DartVanya Nov 5, 2024
3d3a1f7
Merge branch 'master' into master-dm
DartVanya Nov 5, 2024
11f2c6f
Fix SysLink theme support on Windows 10
DartVanya Nov 5, 2024
d75dcb2
Merge branch 'master-dm' into ObjManagerPlus
DartVanya Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions KSystemInformer/comms_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ KPHM_DEFINE_HANDLER(KphpCommsQueryInformationObject);
KPHM_DEFINE_HANDLER(KphpCommsSetInformationObject);
KPHM_DEFINE_HANDLER(KphpCommsOpenDriver);
KPHM_DEFINE_HANDLER(KphpCommsQueryInformationDriver);
KPHM_DEFINE_HANDLER(KphpCommsOpenDevice);
KPHM_DEFINE_HANDLER(KphpCommsOpenObjectByTypeIndex);
KPHM_DEFINE_HANDLER(KphpCommsQueryInformationProcess);
KPHM_DEFINE_HANDLER(KphpCommsSetInformationProcess);
KPHM_DEFINE_HANDLER(KphpCommsSetInformationThread);
Expand Down Expand Up @@ -117,6 +119,8 @@ const KPH_MESSAGE_HANDLER KphCommsMessageHandlers[] =
{ KphMsgStripProtectedProcessMasks, KphpCommsStripProtectedProcessMasks, KphpCommsRequireMaximum },
{ KphMsgQueryVirtualMemory, KphpCommsQueryVirtualMemory, KphpCommsQueryVirtualMemoryRequires },
{ KphMsgQueryHashInformationFile, KphpCommsQueryHashInformationFile, KphpCommsRequireMaximum },
{ KphMsgOpenDevice, KphpCommsOpenDevice, KphpCommsRequireMaximum },
{ KphMsgOpenObjectByTypeIndex, KphpCommsOpenObjectByTypeIndex, KphpCommsRequireMaximum }
};
const ULONG KphCommsMessageHandlerCount = ARRAYSIZE(KphCommsMessageHandlers);
C_ASSERT(ARRAYSIZE(KphCommsMessageHandlers) == MaxKphMsgClient);
Expand Down Expand Up @@ -705,6 +709,61 @@ NTSTATUS KSIAPI KphpCommsQueryInformationDriver(
return STATUS_SUCCESS;
}

_Function_class_(KPHM_HANDLER)
_IRQL_requires_max_(PASSIVE_LEVEL)
_Must_inspect_result_
NTSTATUS KSIAPI KphpCommsOpenDevice(
_In_ PKPH_CLIENT Client,
_Inout_ PKPH_MESSAGE Message
)
{
PKPHM_OPEN_DEVICE msg;

KPH_PAGED_CODE_PASSIVE();
NT_ASSERT(ExGetPreviousMode() == UserMode);
NT_ASSERT(Message->Header.MessageId == KphMsgOpenDevice);

UNREFERENCED_PARAMETER(Client);

msg = &Message->User.OpenDevice;

msg->Status = KphOpenDevice(msg->DeviceHandle,
msg->DriverHandle,
msg->DesiredAccess,
msg->ObjectName,
msg->OpenLowest,
UserMode);

return STATUS_SUCCESS;
}

_Function_class_(KPHM_HANDLER)
_IRQL_requires_max_(PASSIVE_LEVEL)
_Must_inspect_result_
NTSTATUS KSIAPI KphpCommsOpenObjectByTypeIndex(
_In_ PKPH_CLIENT Client,
_Inout_ PKPH_MESSAGE Message
)
{
PKPHM_OPEN_OBJECT msg;

KPH_PAGED_CODE_PASSIVE();
NT_ASSERT(ExGetPreviousMode() == UserMode);
NT_ASSERT(Message->Header.MessageId == KphMsgOpenObjectByTypeIndex);

UNREFERENCED_PARAMETER(Client);

msg = &Message->User.OpenObject;

msg->Status = KphOpenObjectByTypeIndex(msg->ObjectHandle,
msg->DesiredAccess,
msg->ObjectAttributes,
msg->TypeIndex,
UserMode);

return STATUS_SUCCESS;
}

_Function_class_(KPHM_REQUIRED_STATE)
_IRQL_requires_max_(PASSIVE_LEVEL)
_Must_inspect_result_
Expand Down
41 changes: 41 additions & 0 deletions KSystemInformer/dynimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ PSE_UNREGISTER_IMAGE_VERIFICATION_CALLBACK KphSeUnregisterImageVerificationCallb
PCI_VALIDATE_FILE_OBJECT KphDynCiValidateFileObject = NULL;
PCI_FREE_POLICY_INFO KphDynCiFreePolicyInfo = NULL;
PLXP_THREAD_GET_CURRENT KphDynLxpThreadGetCurrent = NULL;
POBJECT_TYPE* KphDynObTypeIndexTable = NULL;
KPH_PROTECTED_DATA_SECTION_POP();

KPH_PAGED_FILE();
Expand All @@ -49,6 +50,46 @@ VOID KphDynamicImport(
KphDynCiValidateFileObject = (PCI_VALIDATE_FILE_OBJECT)KphGetRoutineAddress(L"ci.dll", "CiValidateFileObject");
KphDynCiFreePolicyInfo = (PCI_FREE_POLICY_INFO)KphGetRoutineAddress(L"ci.dll", "CiFreePolicyInfo");
KphDynLxpThreadGetCurrent = (PLXP_THREAD_GET_CURRENT)KphGetRoutineAddress(L"lxcore.sys", "LxpThreadGetCurrent");

#ifdef _WIN64
__try
{
// ObGetObjectType have equal machine code on 10.0.10240 - 10.0.22631
//
// nt!ObGetObjectType+0x1C 488d0d[????????] lea rcx,[nt!ObTypeIndexTable]
// lea rcx, [rip + off32]
PUCHAR rip;

rip = (PUCHAR)ObGetObjectType + 0x1C;
Comment on lines +57 to +63
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not yet clear to me in the PR why this is necessary. Or why any additional driver APIs are necessary at all. In any case we need to be careful here and make sure this is correct. If we do need this we need some dynamic data handling around it.

I would prefer to take care of driver changes like this myself. If there is something you need for the driver to achieve the goals please allow me time to provide an appropriately safe API to do so.

Copy link
Contributor Author

@DartVanya DartVanya Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was experimental implementation, and I know what it is bad and not safe. I wrote this with a purpose to open objects for which public NtOpenXXX API isn't existing (like Type, Callback). This gives a power to open any object.
Object types table offset is RIP relative to instruction in ObGetObjectType. To add it to dyndata we need to know ObGetObjectType address, lea rcx instruction address and offset vaule, then we can calculate full address. And we should do it at runtime, since it address points to data section of loaded kernel image (hope I'm not wrong).

It's very interesting, but for now there is no particular need of KphOpenObjectByTypeIndex. Type information and statistics can be retrieved without need to open this Type object. Current implementation always open object properties, even if object cannot be opened.

But, if possible, I really want to keep PhOpenDevice (see answer below).

Example, \ObjectTypes\Token information with driver and KphOpenObjectByTypeIndex (left), and without (right):

s04_00-08_TGEhD.mp4


if ((*(PULONG)rip & 0xFFFFFF) == 0x0D8D48)
{
PVOID ObTypeIndexTableDecoded;
OBJECT_TYPES_INFORMATION typesInfo = { 0 };

rip += 3;

ObTypeIndexTableDecoded = (PVOID)(rip + sizeof(LONG) + *(PLONG)rip);

if (ZwQueryObject(NULL,
ObjectTypesInformation,
&typesInfo,
sizeof(typesInfo),
NULL) == STATUS_INFO_LENGTH_MISMATCH)
{
if (typesInfo.NumberOfTypes >= 2 && typesInfo.NumberOfTypes < 0x100 &&
NT_SUCCESS(KphValidateAddressForSystemModules(ObTypeIndexTableDecoded, typesInfo.NumberOfTypes * sizeof(POBJECT_TYPE))))
{
KphDynObTypeIndexTable = ObTypeIndexTableDecoded;
}
}
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
KphDynObTypeIndexTable = NULL;
}
#endif // _WIN64
}

/**
Expand Down
22 changes: 22 additions & 0 deletions KSystemInformer/include/kph.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ extern PSE_UNREGISTER_IMAGE_VERIFICATION_CALLBACK KphSeUnregisterImageVerificati
extern PCI_VALIDATE_FILE_OBJECT KphDynCiValidateFileObject;
extern PCI_FREE_POLICY_INFO KphDynCiFreePolicyInfo;
extern PLXP_THREAD_GET_CURRENT KphDynLxpThreadGetCurrent;
extern POBJECT_TYPE* KphDynObTypeIndexTable;

_IRQL_requires_max_(PASSIVE_LEVEL)
VOID KphDynamicImport(
Expand Down Expand Up @@ -786,6 +787,16 @@ NTSTATUS KphCompareObjects(
_In_ KPROCESSOR_MODE AccessMode
);

_IRQL_requires_max_(PASSIVE_LEVEL)
_Must_inspect_result_
NTSTATUS KphOpenObjectByTypeIndex(
_Out_ PHANDLE ObjectHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_In_ ULONG TypeIndex,
_In_ KPROCESSOR_MODE AccessMode
);

// process

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down Expand Up @@ -866,6 +877,17 @@ NTSTATUS KphQueryInformationDriver(
_In_ KPROCESSOR_MODE AccessMode
);

_IRQL_requires_max_(PASSIVE_LEVEL)
_Must_inspect_result_
NTSTATUS KphOpenDevice(
_Out_ PHANDLE DeviceHandle,
_Out_opt_ PHANDLE DriverHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ PUNICODE_STRING ObjectName,
_In_ BOOLEAN OpenLowest,
_In_ KPROCESSOR_MODE AccessMode
);

// thread

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down
56 changes: 56 additions & 0 deletions KSystemInformer/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2372,6 +2372,62 @@ NTSTATUS KphOpenNamedObject(
return status;
}

/**
* \brief Opens a named object by its type index from nt!ObTypeIndexTable.
*
* \param[out] ObjectHandle Set to the opened handle.
* \param[in] DesiredAccess Desires access to the object.
* \param[in] ObjectAttributes Attributes to open the object.
* \param[in] TypeIndex Type index of object to open.
* \param[in] AccessMode The mode in which to perform access checks.
*
* \return Successful or errant status.
*/
_IRQL_requires_max_(PASSIVE_LEVEL)
_Must_inspect_result_
NTSTATUS KphOpenObjectByTypeIndex(
_Out_ PHANDLE ObjectHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ POBJECT_ATTRIBUTES ObjectAttributes,
_In_ ULONG TypeIndex,
_In_ KPROCESSOR_MODE AccessMode
)
{
KPH_PAGED_CODE_PASSIVE();

if (!KphDynObTypeIndexTable)
{
return STATUS_NOINTERFACE;
}

if (AccessMode != KernelMode)
{
OBJECT_TYPES_INFORMATION typesInfo = { 0 };

if (ZwQueryObject(NULL,
ObjectTypesInformation,
&typesInfo,
sizeof(typesInfo),
NULL) == STATUS_INFO_LENGTH_MISMATCH)
{
if (TypeIndex < 2 || TypeIndex > typesInfo.NumberOfTypes)
{
return STATUS_INVALID_PARAMETER;
}
}
else
{
return STATUS_UNSUCCESSFUL;
}
}

return KphOpenNamedObject(ObjectHandle,
DesiredAccess,
ObjectAttributes,
KphDynObTypeIndexTable[TypeIndex],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can cause an out of bounds read in kernel mode. The kernel should not trust input from user mode under any circumstances.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that it enough to validate parameters in native.c
Is it correct to check this way from the kernel?

    if (AccessMode != KernelMode)
    {
        OBJECT_TYPES_INFORMATION typesInfo = { 0 };

        if (ZwQueryObject(NULL,
            ObjectTypesInformation,
            &typesInfo,
            sizeof(typesInfo),
            NULL) == STATUS_INFO_LENGTH_MISMATCH)
        {
            if (TypeIndex < 2 || TypeIndex > typesInfo.NumberOfTypes)
            {
                return STATUS_INVALID_PARAMETER;
            }
        }
        else
        {
            return STATUS_UNSUCCESSFUL;
        }
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be fine. Although I'll have to check some internals to be certain. Ideally, since we would be using some dyndata anyway - we would extract both the table and the count to avoid the syscall. But it sounds like KphOpenObjectByTypeIndex isn't strictly necessary for the changes anyway. I have an idea to be able to provide an implementation without dyndata at all. And might also provide an additional API... I'll get back to you on this.

AccessMode);
}

/**
* \brief Duplicates an object.
*
Expand Down
136 changes: 136 additions & 0 deletions KSystemInformer/qrydrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,139 @@ NTSTATUS KphQueryInformationDriver(

return status;
}

/**
* \brief Opens a device object.
*
* \param[out] DriverDevice Set to the opened handle to the device.
* \param[out_opt] DriverHandle Set to the opened handle to the device driver.
* \param[in] DesiredAccess Desired access to the driver object.
* \param[in] ObjectAttributes Object attributes for opening the driver object.
* \param[in] OpenLowest Open lowest (TRUE) or topmost (FALSE) device object in the stack
* \param[in] AccessMode The mode in which to perform access checks.
*
* \return Successful or errant status.
*/
_IRQL_requires_max_(PASSIVE_LEVEL)
_Must_inspect_result_
NTSTATUS KphOpenDevice(
_Out_ PHANDLE DeviceHandle,
_Out_opt_ PHANDLE DriverHandle,
_In_ ACCESS_MASK DesiredAccess,
_In_ PUNICODE_STRING ObjectName,
_In_ BOOLEAN OpenLowest,
_In_ KPROCESSOR_MODE AccessMode
)
{
NTSTATUS status;
HANDLE deviceHandle;
HANDLE driverHandle;
PDEVICE_OBJECT DeviceObject;
PDEVICE_OBJECT LowerDevice;
PFILE_OBJECT FileObject;

KPH_PAGED_CODE_PASSIVE();

deviceHandle = NULL;
driverHandle = NULL;
DeviceObject = NULL;
FileObject = NULL;

if (AccessMode != KernelMode)
{
__try
{
ProbeOutputType(DeviceHandle, HANDLE);
if (DriverHandle)
ProbeOutputType(DriverHandle, HANDLE);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
status = GetExceptionCode();
goto Exit;
}
}

status = IoGetDeviceObjectPointer(ObjectName, DesiredAccess, &FileObject, &DeviceObject);

if (!NT_SUCCESS(status))
{
KphTracePrint(TRACE_LEVEL_VERBOSE,
GENERAL,
"IoGetDeviceObjectPointer failed: %!STATUS!",
status);

goto Exit;
}

ObReferenceObject(DeviceObject);

if (OpenLowest)
{
//while (LowerDevice = IoGetLowerDeviceObject(DeviceObject))
// DeviceObject = LowerDevice;
#pragma warning(suppress: 4706) // suppress assignment within conditional expression
if (LowerDevice = IoGetDeviceAttachmentBaseRef(DeviceObject))
{
ObDereferenceObject(DeviceObject);
DeviceObject = LowerDevice;
}
}

status = ObOpenObjectByPointer(DeviceObject, 0, NULL, DesiredAccess, *IoDeviceObjectType, AccessMode, &deviceHandle);

if (!NT_SUCCESS(status))
{
KphTracePrint(TRACE_LEVEL_VERBOSE,
GENERAL,
"ObOpenObjectByPointer failed: %!STATUS!",
status);
deviceHandle = NULL;

goto Exit;
}

if (DriverHandle && DeviceObject->DriverObject)
{
if (!NT_SUCCESS(ObOpenObjectByPointer(DeviceObject->DriverObject, 0, NULL,
DesiredAccess, *IoDriverObjectType, AccessMode, &driverHandle)))
{
driverHandle = NULL;
status = STATUS_NOT_ALL_ASSIGNED;
}
}

if (AccessMode != KernelMode)
{
__try
{
*DeviceHandle = deviceHandle;
if (DriverHandle)
*DriverHandle = driverHandle;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
status = GetExceptionCode();
}
}
else
{
*DeviceHandle = deviceHandle;
if (DriverHandle)
*DriverHandle = driverHandle;
}

Exit:

if (FileObject)
{
ObDereferenceObject(FileObject);
}

if (DeviceObject)
{
ObDereferenceObject(DeviceObject);
}

return status;
}
14 changes: 14 additions & 0 deletions SystemInformer/SystemInformer.def
Original file line number Diff line number Diff line change
Expand Up @@ -1125,3 +1125,17 @@ EXPORTS
KsiLevel @2036 NONAME
KsiEnumerateProcessHandles @2037 NONAME
KsiQueryHashInformationFile @2038 NONAME
KphQueryInformationObject @2040 NONAME
KphAlpcQueryInformation @2041 NONAME
KphDuplicateObject @2042 NONAME

; phnative
PhGetDriverName @2043 NONAME
PhGetDriverImageFileName @2044 NONAME
PhEnumHandlesEx @2045 NONAME
PhGetObjectTypeNumber @2046 NONAME
PhOpenDevice @2047 NONAME
PhOpenObjectByTypeIndex @2048 NONAME
PhGetObjectTypeIndexName @2049 NONAME
PhGetPnPDeviceName @2050 NONAME
PhFilterConnectCommunicationPort @2051 NONAME
Loading
Loading