I am attempting to find the name of a process that owns a handle from a list of handles obtained through NtQueryObject. I am running through each handle to check its process name and occasionally it throws the "com.sun.jna.platform.win32.Win32Exception: A device attached to the system is not functioning." error. This normally works fine but when it does happen it seems to throw it for a large number of handles on several processes. I am using JNA to make all the calls from a java program running on Windows 10.
I have tried narrowing it down as much as possible but I cannot figure out why it would be throwing this error sometimes.
NtDllX.SYSTEM_HANDLE_INFORMATION info = getSystemHandleInfo();
for(int i = 0; i < info.HandleCount; i++) {
//For each handle check for target handle
NtDllX.SYSTEM_HANDLE sh = info.Handles[i];
HANDLE sHandle = new HANDLE(new Pointer(sh.Handle));
HANDLE rProcess = Kernel32.INSTANCE.OpenProcess(Kernel32.PROCESS_DUP_HANDLE | Kernel32.PROCESS_QUERY_INFORMATION | Kernel32.PROCESS_VM_READ, false, sh.ProcessId);
//Check for target process
if(rProcess != null) {
String p = "";
try {
p = Kernel32Util.QueryFullProcessImageName(rProcess, 0); //Throwing Error Occasionally
} catch (Exception e) {
...
The error being thrown:
com.sun.jna.platform.win32.Win32Exception: A device attached to the system is not functioning. at com.sun.jna.platform.win32.Kernel32Util.QueryFullProcessImageName(Kernel32Util.java:842)