From da15c84bd06af55a818b2be94cd33951053a9e0f Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Thu, 17 Jan 2019 19:42:18 +0100 Subject: [PATCH] 1 jar 1/2 --- .../habboclient/HabboClientFactory.java | 2 + .../habboclient/macOs/MacOsHabboClient.java | 145 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 G-Earth/src/main/java/gearth/protocol/memory/habboclient/macOs/MacOsHabboClient.java diff --git a/G-Earth/src/main/java/gearth/protocol/memory/habboclient/HabboClientFactory.java b/G-Earth/src/main/java/gearth/protocol/memory/habboclient/HabboClientFactory.java index 584f83c..1f96de9 100644 --- a/G-Earth/src/main/java/gearth/protocol/memory/habboclient/HabboClientFactory.java +++ b/G-Earth/src/main/java/gearth/protocol/memory/habboclient/HabboClientFactory.java @@ -3,6 +3,7 @@ package gearth.protocol.memory.habboclient; import gearth.misc.OSValidator; import gearth.protocol.HConnection; import gearth.protocol.memory.habboclient.linux.LinuxHabboClient; +import gearth.protocol.memory.habboclient.macOs.MacOsHabboClient; import gearth.protocol.memory.habboclient.windows.WindowsHabboClient; /** @@ -14,6 +15,7 @@ public class HabboClientFactory { public static HabboClient get(HConnection connection) { if (OSValidator.isUnix()) return new LinuxHabboClient(connection); if (OSValidator.isWindows()) return new WindowsHabboClient(connection); + if (OSValidator.isMac()) return new MacOsHabboClient(connection); return null; } diff --git a/G-Earth/src/main/java/gearth/protocol/memory/habboclient/macOs/MacOsHabboClient.java b/G-Earth/src/main/java/gearth/protocol/memory/habboclient/macOs/MacOsHabboClient.java new file mode 100644 index 0000000..a50c053 --- /dev/null +++ b/G-Earth/src/main/java/gearth/protocol/memory/habboclient/macOs/MacOsHabboClient.java @@ -0,0 +1,145 @@ +package gearth.protocol.memory.habboclient.macOs; + +import gearth.misc.Cacher; +import gearth.protocol.HConnection; +import gearth.protocol.HMessage; +import gearth.protocol.memory.habboclient.HabboClient; +import org.json.JSONArray; +import org.json.JSONObject; + + +import javax.xml.bind.DatatypeConverter; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.StringJoiner; + +public class MacOsHabboClient extends HabboClient { + + public MacOsHabboClient(HConnection connection) { + super(connection); + + connection.addTrafficListener(0, message -> { + if (message.getDestination() == HMessage.Side.TOSERVER && message.getPacket().headerId() == PRODUCTION_ID) { + production = message.getPacket().readString(); + } + }); + } + + + private static final String OFFSETS_CACHE_KEY = "RC4Offsets"; + private static final int PRODUCTION_ID = 4000; + private String production = ""; + + @Override + public List getRC4cached() { + List result = new ArrayList<>(); + try { + List possibleResults = readPossibleBytes(true); + + if (possibleResults == null) + return new ArrayList<>(); + + for (String s : possibleResults) + result.add(hexStringToByteArray(s)); + } catch (IOException | URISyntaxException e) { + e.printStackTrace(); + } + return result; + } + + private ArrayList readPossibleBytes(boolean useCache) throws IOException, URISyntaxException { + ProcessBuilder pb; + + JSONObject revisionList = (JSONObject) Cacher.get(OFFSETS_CACHE_KEY); + if (revisionList == null) { + Cacher.put(OFFSETS_CACHE_KEY, new JSONObject()); + revisionList = (JSONObject) Cacher.get(OFFSETS_CACHE_KEY); + } + + assert revisionList != null; + JSONArray cachedOffsets; + if (revisionList.has(production)) + cachedOffsets = (JSONArray) revisionList.get(production); + else + cachedOffsets = null; + + StringJoiner joiner = new StringJoiner(" "); + + if (useCache) { + if (cachedOffsets == null) { + return null; + } + + for (Object s : cachedOffsets) { + joiner.add((String)s); + } + } + + String g_mem = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getParent() + "/G-Mem"; + if (!useCache) + pb = new ProcessBuilder(g_mem, hConnection.getClientHostAndPort().substring(0, hConnection.getClientHostAndPort().indexOf(':')) , Integer.toString(hConnection.getPort())); + else + pb = new ProcessBuilder(g_mem, hConnection.getClientHostAndPort().substring(0, hConnection.getClientHostAndPort().indexOf(':')) , Integer.toString(hConnection.getPort()), "-c" + joiner.toString()); + + + Process p = pb.start(); + BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); + + String line; + ArrayList possibleData = new ArrayList<>(); + + if (cachedOffsets == null) { + cachedOffsets = new JSONArray(); + } + + + int count = 0; + while((line = reader.readLine()) != null) { + if (line.length() > 1) { + if (!useCache && (count++ % 2 == 0)) { + if (!cachedOffsets.toList().contains(line)) { + cachedOffsets.put(line); + System.out.println("[+] " + line); + } + } + else + possibleData.add(line); + } + } + + revisionList.put(production, cachedOffsets); + Cacher.put(OFFSETS_CACHE_KEY, revisionList); + p.destroy(); + return possibleData; + } + + @Override + public List getRC4possibilities() { + List result = new ArrayList<>(); + try { + ArrayList possibleData = readPossibleBytes(false); + + for (String possibleHexStr : possibleData) { + result.add(hexStringToByteArray(possibleHexStr)); + } + } catch (IOException | URISyntaxException e) { + e.printStackTrace(); + } + return result; + } + + private static byte[] hexStringToByteArray(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i+1), 16)); + } + return data; + } +}