|
11 | 11 |
|
12 | 12 | import java.io.IOException; |
13 | 13 | import java.lang.reflect.Field; |
| 14 | +import java.lang.reflect.Method; |
14 | 15 | import java.util.Map; |
15 | 16 | import org.eclipse.core.runtime.Platform; |
16 | 17 | import org.eclipse.debug.core.DebugException; |
@@ -62,16 +63,23 @@ private void disconnectDebuggerConnection() throws DebugException { |
62 | 63 | private void terminateInstance() { |
63 | 64 | try { |
64 | 65 | Process process = (Process) getSystemProcess(); |
65 | | - Field field = process.getClass().getDeclaredField("handle"); |
66 | | - field.setAccessible(true); |
67 | | - long handleValue = field.getLong(process); |
68 | | - Kernel32 kernel = Kernel32.INSTANCE; |
69 | | - WinNT.HANDLE handle = new WinNT.HANDLE(); |
70 | | - handle.setPointer(Pointer.createConstant(handleValue)); |
71 | | - int pid = kernel.GetProcessId(handle); |
| 66 | + long pid; |
| 67 | + try { |
| 68 | + Method method = process.getClass().getDeclaredMethod("pid"); |
| 69 | + method.setAccessible(true); |
| 70 | + pid = (long) method.invoke(process); |
| 71 | + } catch (NoSuchMethodException ex) { |
| 72 | + Field field = process.getClass().getDeclaredField("handle"); |
| 73 | + field.setAccessible(true); |
| 74 | + long handleValue = field.getLong(process); |
| 75 | + Kernel32 kernel = Kernel32.INSTANCE; |
| 76 | + WinNT.HANDLE handle = new WinNT.HANDLE(); |
| 77 | + handle.setPointer(Pointer.createConstant(handleValue)); |
| 78 | + pid = kernel.GetProcessId(handle); |
| 79 | + } |
72 | 80 | killProcess(String.valueOf(pid)); |
73 | 81 | } catch (Exception ex) { |
74 | | - LOG.log(Level.SEVERE, ERROR_MESSAGE, ex); |
| 82 | + LOG.log(Level.SEVERE, ERROR_MESSAGE, ex); |
75 | 83 | } |
76 | 84 | } |
77 | 85 |
|
|
0 commit comments