19 package org.sleuthkit.autopsy.coreutils;
21 import com.sun.jna.Pointer;
22 import com.sun.jna.platform.win32.Kernel32;
23 import com.sun.jna.platform.win32.Kernel32Util;
24 import com.sun.jna.platform.win32.Tlhelp32;
25 import com.sun.jna.platform.win32.WinDef.DWORD;
26 import com.sun.jna.platform.win32.WinNT;
27 import java.io.IOException;
28 import java.lang.reflect.Field;
29 import java.util.ArrayList;
30 import java.util.List;
49 if (process.getClass().getName().equals(
"java.lang.Win32Process") ||
50 process.getClass().getName().equals(
"java.lang.ProcessImpl")) {
52 Field f = process.getClass().getDeclaredField(
"handle");
53 f.setAccessible(
true);
54 long handleVal = f.getLong(process);
55 handle =
new WinNT.HANDLE(Pointer.createConstant(handleVal));
57 catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
58 throw new Exception(ex.getMessage());
61 this.pid = Kernel32.INSTANCE.GetProcessId(handle);
71 handle = Kernel32.INSTANCE.OpenProcess (
79 throw new Exception (Kernel32Util.formatMessageFromLastErrorCode (Kernel32.INSTANCE.GetLastError ()));
80 this.pid = Kernel32.INSTANCE.GetProcessId(handle);
86 Kernel32.INSTANCE.CloseHandle (handle);
95 Kernel32.INSTANCE.TerminateProcess (handle, 0);
105 ArrayList<Win32Process> result =
new ArrayList<> ();
106 WinNT.HANDLE hSnap = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS,
new DWORD(0));
107 Tlhelp32.PROCESSENTRY32.ByReference ent =
new Tlhelp32.PROCESSENTRY32.ByReference ();
108 if (!Kernel32.INSTANCE.Process32First (hSnap, ent))
return result;
110 if (ent.th32ParentProcessID.intValue () == pid) result.add (
new Win32Process (ent.th32ProcessID.intValue ()));
111 }
while (Kernel32.INSTANCE.Process32Next (hSnap, ent));
112 Kernel32.INSTANCE.CloseHandle (hSnap);
List< Win32Process > getChildren()