I'm trying to troubleshoot slow startup of a third-party binary (no source). It is a 32-bit application running on 64-bit Windows 7.
I've used a debugger to break into the application while it's hung with 0% CPU usage during startup, and it appears to be waiting for ReadFile
to return. The first argument to ReadFile
is the handle value, 000000f0. windbg's !handle
command tells me:
Handle f0 Type File Attributes 0 GrantedAccess 0x120189: ReadControl,Synch Read/List,ReadEA,ReadAttr,WriteAttr HandleCount 2 PointerCount 4 No Object Specific Information available
I want to know what device this corresponds to. But Sysinternals Process Explorer doesn't include this handle in its list of process handles.
I've used windbg to trace all calls to ntdll!NtCreateFile
and printed the path and returned handle: This handle is not among them. Breakpoints on kernel32!CreateNamedPipeW
, kernel32!CallNamedPipeW
, and kernel32!WaitNamedPipeW
are never triggered (which is odd because Process Explorer did show another handle with path \Device\NamedPipe\
).
For reference, here is the command to trace NtCreateFile
(akak ZwCreateFile
) on Windows x64:
bp ntdll!NtCreateFile "!ustr poi(@r8+10) ; r $t0 = @rcx ; gu ; dd @$t0 L1 ; gc"
Thanks to Skywing for pointing me in the right direction on that.
Where else can a HANDLE of type File
come from? Don't the other HANDLE creation functions delegate to NtCreateFile
for the actual syscall (I guess not)?
ReadFile
call that's timing out. I guess I could run a kernel debugger, with a VM it wouldn't be too bad, but I've been trying to avoid that. All the necessary information ought to be available in user mode, at the time the call is made to whatever API creates the HANDLE. – SorbianNtCreateFile
is the only system routine invoked in obtaining aHANDLE
. But I believe there should be a way to discover theHANDLE
properties nevertheless. Within the specific process theHANDLE
should correspond to the underlyingFILE_OBJECT
(if it's a file handle of course). You may useObReferenceObjectByHandle
, verify its a file handle (checkObjectType
), then cast the object data toFILE_OBJECT
. It contains among other things a pointer toDEVICE_OBJECT
, which contains a pointer toDRIVER_OBJECT
. So everything theoretically can be discovered – DisarraySysinternals Handle
? It's described as a command-line equivalent to Process Explorer. I'll give the Sysinternals version a try, I'm not running binaries downloaded from some unknown Russian web server. Nope, the handle doesn't appear in the output ofhandle.exe
either. – Sorbian-c
option tohandle.exe
, it finds the previously unlisted handle f0, and calls it\Device\NamedPipe
. So does the-a
option. I don't think that's the true path that was opened, however. – Sorbian!handle
when the debugger breaks on process entry, and it doesn't exist yet. – Sorbian