Skip to content

Commit

Permalink
Merge pull request #246 from mircokroon/auth
Browse files Browse the repository at this point in the history
Authentication fix
  • Loading branch information
mircokroon authored Nov 20, 2021
2 parents 17270a9 + f70ae53 commit a3dd3e1
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/main/java/proxy/auth/AuthDetailsFromProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,29 +128,21 @@ private List<String> findCandidateProcessUnix() throws IOException {
}

/**
* Retrieve launch parameters from a given PID on Windows.
*
* Source: https://stackoverflow.com/a/54790608
* Retrieve launch parameters from a given PID on Windows. Uses PowerShell since WMIC is removed in windows 11.
*/
private String getLaunchParametersWindows(long pid) {
String query = "SELECT CommandLine FROM Win32_Process WHERE ProcessID = \"" + pid + "\"";
String formatter = "| Select-Object -Property CommandLine | Out-String -width 9999";
String cmd = "\"Get-WmiObject -Query \\\"" + query + "\\\" " + formatter + "\"";
try {
Process process = new ProcessBuilder(
"wmic", "process", "where", "ProcessID=" + pid, "get", "commandline", "/format:list"
"Powershell.exe", "-Command", cmd
).redirectErrorStream(true).start();

try (InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream());
BufferedReader reader = new BufferedReader(inputStreamReader)) {
while (true) {
String line = reader.readLine();
if (line == null) {
return "";
}
if (!line.startsWith("CommandLine=")) {
continue;
}
return line.substring("CommandLine=".length());
}
}
String res = new BufferedReader(new InputStreamReader(process.getInputStream()))
.lines().filter(line -> line.contains("accessToken")).collect(Collectors.joining());

return res;
} catch (IOException e) {
e.printStackTrace();
return "";
Expand Down

0 comments on commit a3dd3e1

Please sign in to comment.