Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions native/envvar-cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,14 @@ jstring getCmdLineAndEnvVars(
return packedStr;
}

JNIEXPORT jint JNICALL Java_org_jvnet_winp_Native_getProcessId(JNIEnv* pEnv, jclass clazz, jint handle) {
JNIEXPORT jint JNICALL Java_org_jvnet_winp_Native_getProcessId(JNIEnv* pEnv, jclass clazz, jlong handle) {
char errorBuffer[ERRMSG_SIZE];
HANDLE hProcess = (HANDLE)handle;
PROCESS_BASIC_INFORMATION ProcInfo;
SIZE_T sRead;
if(!NT_SUCCESS(ZwQueryInformationProcess(hProcess, ProcessBasicInformation, &ProcInfo, sizeof(ProcInfo), &sRead))) {
reportError(pEnv,"Failed to ZWQueryInformationProcess");
DWORD pid = GetProcessId(hProcess);
if (!pid) {
sprintf_s<ERRMSG_SIZE>(errorBuffer, "Failed to get process id from handle=%ld.", handle);
reportError(pEnv, errorBuffer);
return -1;
}

return (jint)ProcInfo.UniqueProcessId;
/* ULONG id=0;

if(!ReadProcessMemory(hProcess, ProcInfo.UniqueProcessId, &id, sizeof(ULONG), &_)) {
reportError(pEnv,"Failed to read process ID");
return NULL;
}

return id;*/
return pid;
}
4 changes: 2 additions & 2 deletions native/java-interface.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion native/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// are changed infrequently
#pragma once

#define _WIN32_WINNT 0x500
#define _WIN32_WINNT 0x501

#include <windows.h>
#include <tchar.h>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jvnet/winp/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Native {
native static boolean sendCtrlC(int pid, String sendctrlcExePath);
native static boolean isCriticalProcess(int pid);
native static int setPriority(int pid, int value);
native static int getProcessId(int handle);
native static int getProcessId(long handle);
native static boolean exitWindowsEx(int flags,int reasonCode);

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jvnet/winp/WinProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public WinProcess(Process proc) {
try {
Field f = proc.getClass().getDeclaredField("handle");
f.setAccessible(true);
int handle = ((Number)f.get(proc)).intValue();
long handle = f.getLong(proc);
pid = Native.getProcessId(handle);
} catch (NoSuchFieldException e) {
throw new NotWindowsException(e);
Expand Down