From fc7b86dc9564ca63ec16167567d0a5182d5ba88e Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Wed, 30 Jan 2019 01:16:06 +0100 Subject: [PATCH] advanced; option to override connection info with raw values --- .../java/gearth/protocol/HConnection.java | 72 ++++++++++--------- .../misc/ConnectionInfoOverrider.java | 12 ++++ .../src/main/java/gearth/ui/extra/Extra.java | 21 +++++- .../main/resources/gearth/ui/extra/Extra.fxml | 8 +-- 4 files changed, 76 insertions(+), 37 deletions(-) create mode 100644 G-Earth/src/main/java/gearth/protocol/misc/ConnectionInfoOverrider.java diff --git a/G-Earth/src/main/java/gearth/protocol/HConnection.java b/G-Earth/src/main/java/gearth/protocol/HConnection.java index aef5b3d..94cb1a7 100644 --- a/G-Earth/src/main/java/gearth/protocol/HConnection.java +++ b/G-Earth/src/main/java/gearth/protocol/HConnection.java @@ -5,6 +5,7 @@ import gearth.misc.OSValidator; import gearth.protocol.hostreplacer.HostReplacer; import gearth.protocol.hostreplacer.HostReplacerFactory; import gearth.protocol.memory.Rc4Obtainer; +import gearth.protocol.misc.ConnectionInfoOverrider; import gearth.protocol.packethandler.Handler; import gearth.protocol.packethandler.IncomingHandler; import gearth.protocol.packethandler.OutgoingHandler; @@ -101,8 +102,9 @@ public class HConnection { } - public static boolean DECRYPTPACKETS = true; - public static boolean DEBUG = false; + private static volatile ConnectionInfoOverrider connectionInfoOverrider; + public static volatile boolean DECRYPTPACKETS = true; + public static volatile boolean DEBUG = false; private static final HostReplacer hostsReplacer = HostReplacerFactory.get(); private volatile boolean hostRedirected = false; @@ -110,7 +112,7 @@ public class HConnection { private volatile List stateChangeListeners = new ArrayList<>(); private volatile State state = State.NOT_CONNECTED; - private class Proxy { + public static class Proxy { private volatile String input_domain; //string representation of the domain to intercept private volatile String actual_domain; //dns resolved domain (ignoring hosts file) private volatile int actual_port; //port of the server @@ -178,7 +180,6 @@ public class HConnection { private volatile Proxy actual_proxy = null; private volatile String hotelVersion = ""; - public State getState() { return state; } @@ -214,41 +215,44 @@ public class HConnection { removeFromHosts(); } - List willremove = new ArrayList<>(); + if (connectionInfoOverrider.mustOverrideConnection()) { + potentialProxies.add(connectionInfoOverrider.getOverrideProxy()); + } + else { + List willremove = new ArrayList<>(); + int c = 0; + for (String host : allPotentialHosts) { + String[] split = host.split(":"); + String input_dom = split[0]; + int port = Integer.parseInt(split[1]); + String actual_dom; - int c = 0; + InetAddress address = null; + try { + address = InetAddress.getByName(input_dom); + actual_dom = address.getHostAddress(); + } + catch (UnknownHostException e) { + willremove.add(host); + continue; + } - for (String host : allPotentialHosts) { - String[] split = host.split(":"); - String input_dom = split[0]; - int port = Integer.parseInt(split[1]); - String actual_dom; - - InetAddress address = null; - try { - address = InetAddress.getByName(input_dom); - actual_dom = address.getHostAddress(); - } - catch (UnknownHostException e) { - willremove.add(host); - continue; + int intercept_port = port; + String intercept_host = "127.0." + (c / 254) + "." + (1 + c % 254); + potentialProxies.add(new Proxy(input_dom, actual_dom, port, intercept_port, intercept_host)); + c++; } - int intercept_port = port; - String intercept_host = "127.0." + (c / 254) + "." + (1 + c % 254); - potentialProxies.add(new Proxy(input_dom, actual_dom, port, intercept_port, intercept_host)); - c++; + List additionalCachedHotels = Cacher.getList(HOTELS_CACHE_KEY); + if (additionalCachedHotels != null) { + for (String host : willremove) { + additionalCachedHotels.remove(host); + } + Cacher.put(HOTELS_CACHE_KEY, additionalCachedHotels); + } } - List additionalCachedHotels = Cacher.getList(HOTELS_CACHE_KEY); - if (additionalCachedHotels != null) { - for (String host : willremove) { - additionalCachedHotels.remove(host); - } - Cacher.put(HOTELS_CACHE_KEY, additionalCachedHotels); - } - setState(State.PREPARED); } @@ -567,4 +571,8 @@ public class HConnection { public String getHotelVersion() { return hotelVersion; } + + public static void setConnectionInfoOverrider(ConnectionInfoOverrider connectionInfoOverrider) { + HConnection.connectionInfoOverrider = connectionInfoOverrider; + } } diff --git a/G-Earth/src/main/java/gearth/protocol/misc/ConnectionInfoOverrider.java b/G-Earth/src/main/java/gearth/protocol/misc/ConnectionInfoOverrider.java new file mode 100644 index 0000000..f02f20d --- /dev/null +++ b/G-Earth/src/main/java/gearth/protocol/misc/ConnectionInfoOverrider.java @@ -0,0 +1,12 @@ +package gearth.protocol.misc; + +import gearth.protocol.HConnection; + +/** + * Created by Jeunez on 30/01/2019. + */ +public interface ConnectionInfoOverrider { + + boolean mustOverrideConnection(); + HConnection.Proxy getOverrideProxy(); +} diff --git a/G-Earth/src/main/java/gearth/ui/extra/Extra.java b/G-Earth/src/main/java/gearth/ui/extra/Extra.java index 90e9b60..b2c8e33 100644 --- a/G-Earth/src/main/java/gearth/ui/extra/Extra.java +++ b/G-Earth/src/main/java/gearth/ui/extra/Extra.java @@ -2,6 +2,7 @@ package gearth.ui.extra; import gearth.misc.Cacher; import gearth.protocol.HConnection; +import gearth.protocol.misc.ConnectionInfoOverrider; import gearth.ui.SubForm; import gearth.ui.info.Info; import javafx.beans.InvalidationListener; @@ -12,7 +13,7 @@ import javafx.scene.layout.GridPane; /** * Created by Jonas on 06/04/18. */ -public class Extra extends SubForm { +public class Extra extends SubForm implements ConnectionInfoOverrider { public static final String NOTEPAD_CACHE_KEY = "notepad_text"; @@ -36,6 +37,8 @@ public class Extra extends SubForm { public CheckBox cbx_debug; public void initialize() { + HConnection.setConnectionInfoOverrider(this); + url_troubleshooting.setTooltip(new Tooltip("https://github.com/sirjonasxx/G-Earth/wiki/Troubleshooting")); Info.activateHyperlink(url_troubleshooting); @@ -82,4 +85,20 @@ public class Extra extends SubForm { cbx_disableDecryption.setDisable(getHConnection().getState() != HConnection.State.NOT_CONNECTED); } + + @Override + public boolean mustOverrideConnection() { + return cbx_ovcinfo.isSelected(); + } + + @Override + public HConnection.Proxy getOverrideProxy() { + return new HConnection.Proxy( + txt_realIp.getText(), + txt_realIp.getText(), + Integer.parseInt(txt_realPort.getText()), + Integer.parseInt(txt_mitmPort.getText()), + txt_mitmIP.getText() + ); + } } diff --git a/G-Earth/src/main/resources/gearth/ui/extra/Extra.fxml b/G-Earth/src/main/resources/gearth/ui/extra/Extra.fxml index 25bb03f..715d0dc 100644 --- a/G-Earth/src/main/resources/gearth/ui/extra/Extra.fxml +++ b/G-Earth/src/main/resources/gearth/ui/extra/Extra.fxml @@ -71,7 +71,7 @@