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;
51 if (process.getClass().getName().equals(
"java.lang.Win32Process") ||
52 process.getClass().getName().equals(
"java.lang.ProcessImpl")) {
54 Field f = process.getClass().getDeclaredField(
"handle");
55 f.setAccessible(
true);
56 long handleVal = f.getLong(process);
57 handle =
new WinNT.HANDLE(Pointer.createConstant(handleVal));
58 }
catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
59 throw new Exception(ex.getMessage());
62 this.pid = Kernel32.INSTANCE.GetProcessId(handle);
73 handle = Kernel32.INSTANCE.OpenProcess(
89 throw new Exception(Kernel32Util.formatMessageFromLastErrorCode(Kernel32.INSTANCE.GetLastError()));
91 this.pid = Kernel32.INSTANCE.GetProcessId(handle);
96 Kernel32.INSTANCE.CloseHandle(handle);
104 Kernel32.INSTANCE.TerminateProcess(handle, 0);
115 ArrayList<Win32Process> result =
new ArrayList<>();
116 WinNT.HANDLE hSnap = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS,
new DWORD(0));
117 Tlhelp32.PROCESSENTRY32.ByReference ent =
new Tlhelp32.PROCESSENTRY32.ByReference();
118 if (!Kernel32.INSTANCE.Process32First(hSnap, ent)) {
122 if (ent.th32ParentProcessID.intValue() == pid) {
123 result.add(
new Win32Process(ent.th32ProcessID.intValue()));
125 }
while (Kernel32.INSTANCE.Process32Next(hSnap, ent));
126 Kernel32.INSTANCE.CloseHandle(hSnap);
List< Win32Process > getChildren()