English 中文(简体)
Is anyone familiar with the undocumented ObReferenceObjectByName windows kernel function?
原标题:

I read a very fascinating article that was about programming drivers using the wdk, and one of the functions it used is called ObReferenceObjectByName. This function has given me lots of headaches. The first bad thing is that it s not documented by microsoft. The second thing, is that the language used in the article was C++, and I want to keep my code in plain ol C. I know that most of the time this shouldn t be a problem, but I haven t - for the life of me - been able to figure out how to include this function.

The code in the article goes something like:

extern "C"{

 #include <ntifs.h>


 NTSYSAPI NTSTATUS NTAPI ObReferenceObjectByName(PUNICODE_STRING ObjectName,

         ULONG Attributes,

         PACCESS_STATE AccessState,

         ACCESS_MASK DesiredAccess,

         POBJECT_TYPE ObjectType,

         KPROCESSOR_MODE AccessMode,

         PVOID ParseContext OPTIONAL,

         PVOID* Object);
}

I ve been trying to replicate this for hours. I tried declaring it without the extern keyword, I tried changing the calling convention, I tried changing the includes... I always end up with the error "unresolved external symbol...".

I m absolutely stumped, so if anyone could offer some advice, I d be grateful. Thanks.

问题回答

You wouldn t be reading http://www.codeproject.com/KB/recipes/keystroke-hook.aspx and trying to create your own Keyboard Logger would you?

Anyways, instead of using this, call ZwCreateFile then ObReferenceObjectByHandle instead.

Here is a test C code compiled and built with no problems:

#include <ntddk.h>

NTSYSAPI NTSTATUS NTAPI ObReferenceObjectByName(
    PUNICODE_STRING ObjectName,
    ULONG Attributes,
    PACCESS_STATE AccessState,
    ACCESS_MASK DesiredAccess,
    POBJECT_TYPE ObjectType,
    KPROCESSOR_MODE AccessMode,
    PVOID ParseContext OPTIONAL,
    PVOID* Object
    );

NTSTATUS DriverEntry(
    IN PDRIVER_OBJECT  DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
    ObReferenceObjectByName(0, 0, 0, 0, 0, 0, 0, 0);

    return STATUS_SUCCESS;
}

I don t know this API, but I can give you a trick that might help you diagnose the problem.

at a command prompt that has MSVC tools in the path

link /dump /exports ???.dll

where ???.dll is the dll were you expect this function to be. This will give you a complete list of exported symbol names and will tell you two things. 1) is the symbol there? and 2) is it being decorated the same as your attempted prototype.

For 32 bit kernel, you should expect this to be called _ObReferenceObjectByName@64,





相关问题
Why running a service as Local System is bad on windows?

I am trying to find out the difference between difference service account types. I tumbled upon this question. The answer was because it has powerful access to local resources, and Network Service ...

Programmatically detect Windows cluster configuration?

Does anyone know how to programatically detect that a Windows server is part of a cluster? Further, is it possible to detect that the server is the active or passive node? [Edit] And detect it from ...

get file icon for Outlook appointment (.msg)

I ve read Get File Icon used by Shell and the other similar posts - and already use SHFileInfo to get the associated icon for any given extension, and that works great. However, Outlook uses ".msg" ...

Identifying idle state on a windows machine

I know about the GetLastInputInfo method but that would only give me the duration since last user input - keyboard or mouse. If a user input was last received 10 minutes ago, that wouldn t mean the ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签