From aa73cef0bcb371a26c15c59c0b44fdd9a528b2dd Mon Sep 17 00:00:00 2001 From: Guenther Demetz Date: Wed, 5 Jun 2019 14:02:57 +0200 Subject: [PATCH 1/2] In case of 64bit windows system, try to use req query tool to detect if there is AutoconfigURL configured in the registry --- .../getdown/launcher/ProxyUtil.java | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java index 8962d35b..09e988d6 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java @@ -8,9 +8,11 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.Reader; +import java.io.StringWriter; import java.net.Authenticator; import java.net.HttpURLConnection; import java.net.InetAddress; @@ -101,7 +103,43 @@ public static boolean autoDetectProxy (Application app) log.info("Detected no proxy settings in the registry."); } - } catch (Throwable t) { + } + catch (UnsatisfiedLinkError ul) { + log.info("Now trying to read windows registry using reg query tool.."); + try { + Process process = Runtime.getRuntime().exec(AUTO_CONFIG_URL); + StreamReader reader = new StreamReader(process.getInputStream()); + + reader.start(); + process.waitFor(); + reader.join(); + + String result = reader.getResult(); + int p = result.indexOf(REGSTR_TOKEN); + + if (p >= 0) { + String rpac = result.substring(p + REGSTR_TOKEN.length()).trim(); + + URL configURL = app.getConfigResource().getRemote(); + log.info("PAC-ConfigURL: " + configURL); + Reader acjs = new InputStreamReader(new URL(rpac).openStream()); + // technically we should be returning all this info and trying each proxy + // in succession, but that's complexity we'll leave for another day + + for (String proxy : findPACProxiesForURL(acjs, configURL)) { + if (proxy.startsWith("PROXY ")) { + String[] hostPort = splitHostPort(proxy.substring(6)); + host = hostPort[0]; + port = hostPort[1]; + break; + } + } + } + } catch (Exception ex) { + log.info("Failed to find proxy settings in Windows registry", "error", ex); + } + } + catch (Throwable t) { log.info("Failed to find proxy settings in Windows registry", "error", t); } } @@ -121,6 +159,29 @@ public static boolean autoDetectProxy (Application app) initProxy(app, host, port, null, null); return true; } + + static class StreamReader extends Thread { + private InputStream is; + private StringWriter sw; + + StreamReader(InputStream is) { + this.is = is; + sw = new StringWriter(); + } + + public void run() { + try { + int c; + while ((c = is.read()) != -1) + sw.write(c); + } + catch (IOException e) { ; } + } + + String getResult() { + return sw.toString(); + } + } public static boolean canLoadWithoutProxy (URL rurl, int timeoutSeconds) { @@ -291,4 +352,10 @@ private static String[] splitHostPort (String hostPort) { protected static final String PROXY_REGISTRY = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"; + protected static final String REGQUERY_UTIL = "reg query "; + protected static final String REGSTR_TOKEN = "REG_SZ"; + protected static final String REGDWORD_TOKEN = "REG_DWORD"; + protected static final String AUTO_CONFIG_URL = REGQUERY_UTIL + + "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\" + + "Internet Settings\" /v AutoconfigURL"; } From f900ea501624f121d7c28a9ddbe83cf4e2aaa49d Mon Sep 17 00:00:00 2001 From: Guenther Demetz Date: Wed, 5 Jun 2019 14:08:03 +0200 Subject: [PATCH 2/2] little fix --- .../main/java/com/threerings/getdown/launcher/ProxyUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java index 09e988d6..d0389a06 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/ProxyUtil.java @@ -121,7 +121,7 @@ public static boolean autoDetectProxy (Application app) String rpac = result.substring(p + REGSTR_TOKEN.length()).trim(); URL configURL = app.getConfigResource().getRemote(); - log.info("PAC-ConfigURL: " + configURL); + log.info("PAC-ConfigURL: " + rpac); Reader acjs = new InputStreamReader(new URL(rpac).openStream()); // technically we should be returning all this info and trying each proxy // in succession, but that's complexity we'll leave for another day