From b1964c126ed41841feca6a46b260c46e305b7608 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Fri, 29 Jun 2018 10:06:56 +0200 Subject: [PATCH] fix SimplePacketLogger, expand HabboClient code 4windows --- src/main/protocol/HConnection.java | 14 ++++- src/main/protocol/memory/Rc4Obtainer.java | 5 +- .../memory/habboclient/HabboClient.java | 12 +++- .../habboclient/HabboClientFactory.java | 7 ++- .../habboclient/linux/LinuxHabboClient.java | 7 ++- .../windows/WindowsHabboClient.java | 59 +++++++++++++++++++ .../loggerdisplays/SimpleTerminalLogger.java | 2 + 7 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java diff --git a/src/main/protocol/HConnection.java b/src/main/protocol/HConnection.java index 6bbe511..43f4e78 100644 --- a/src/main/protocol/HConnection.java +++ b/src/main/protocol/HConnection.java @@ -96,6 +96,8 @@ public class HConnection { private volatile boolean autoDetectHost = false; + private volatile String clientHostAndPort = ""; + public State getState() { return state; @@ -211,7 +213,7 @@ public class HConnection { final boolean[] aborted = new boolean[1]; - Rc4Obtainer rc4Obtainer = new Rc4Obtainer(); + Rc4Obtainer rc4Obtainer = new Rc4Obtainer(this); // wachten op data van client new Thread(() -> { @@ -226,6 +228,8 @@ public class HConnection { handler.act(buffer); if (!datastream[0] && handler.isDataStream()) { + clientHostAndPort = client.getInetAddress().getHostAddress() + ":" + client.getPort(); + System.out.println(clientHostAndPort); datastream[0] = true; setState(State.CONNECTED); onConnect(); @@ -373,6 +377,10 @@ public class HConnection { sendToServerAsyncQueue.clear(); } if (state != this.state) { + if (state != State.CONNECTED) { + clientHostAndPort = ""; + } + State buffer = this.state; this.state = state; for (StateChangeListener listener : stateChangeListeners) { @@ -443,4 +451,8 @@ public class HConnection { } } + public String getClientHostAndPort() { + return clientHostAndPort; + } + } diff --git a/src/main/protocol/memory/Rc4Obtainer.java b/src/main/protocol/memory/Rc4Obtainer.java index 5bb3329..cd173fb 100644 --- a/src/main/protocol/memory/Rc4Obtainer.java +++ b/src/main/protocol/memory/Rc4Obtainer.java @@ -1,5 +1,6 @@ package main.protocol.memory; +import main.protocol.HConnection; import main.protocol.HPacket; import main.protocol.crypto.RC4; import main.protocol.memory.habboclient.HabboClient; @@ -20,8 +21,8 @@ public class Rc4Obtainer { OutgoingHandler outgoingHandler = null; IncomingHandler incomingHandler = null; - public Rc4Obtainer() { - client = HabboClientFactory.get(); + public Rc4Obtainer(HConnection hConnection) { + client = HabboClientFactory.get(hConnection); } private boolean hashappened1 = false; diff --git a/src/main/protocol/memory/habboclient/HabboClient.java b/src/main/protocol/memory/habboclient/HabboClient.java index a013873..af3c097 100644 --- a/src/main/protocol/memory/habboclient/HabboClient.java +++ b/src/main/protocol/memory/habboclient/HabboClient.java @@ -1,11 +1,19 @@ package main.protocol.memory.habboclient; +import main.protocol.HConnection; + import java.util.List; /** * Created by Jonas on 13/06/18. */ -public interface HabboClient { +public abstract class HabboClient { - List getRC4possibilities(); + protected HConnection hConnection; + + public HabboClient(HConnection connection) { + this.hConnection = connection; + } + + public abstract List getRC4possibilities(); } diff --git a/src/main/protocol/memory/habboclient/HabboClientFactory.java b/src/main/protocol/memory/habboclient/HabboClientFactory.java index 0770ba5..b74a719 100644 --- a/src/main/protocol/memory/habboclient/HabboClientFactory.java +++ b/src/main/protocol/memory/habboclient/HabboClientFactory.java @@ -1,7 +1,9 @@ package main.protocol.memory.habboclient; import main.misc.OSValidator; +import main.protocol.HConnection; import main.protocol.memory.habboclient.linux.LinuxHabboClient; +import main.protocol.memory.habboclient.windows.WindowsHabboClient; /** * Created by Jonas on 13/06/18. @@ -9,8 +11,9 @@ import main.protocol.memory.habboclient.linux.LinuxHabboClient; public class HabboClientFactory { - public static HabboClient get() { - if (OSValidator.isUnix()) return new LinuxHabboClient(); + public static HabboClient get(HConnection connection) { + if (OSValidator.isUnix()) return new LinuxHabboClient(connection); + if (OSValidator.isWindows()) return new WindowsHabboClient(connection); return null; } diff --git a/src/main/protocol/memory/habboclient/linux/LinuxHabboClient.java b/src/main/protocol/memory/habboclient/linux/LinuxHabboClient.java index c1d2246..aaf1c28 100644 --- a/src/main/protocol/memory/habboclient/linux/LinuxHabboClient.java +++ b/src/main/protocol/memory/habboclient/linux/LinuxHabboClient.java @@ -1,12 +1,13 @@ package main.protocol.memory.habboclient.linux; +import main.protocol.HConnection; import main.protocol.memory.habboclient.HabboClient; import java.io.*; import java.nio.file.Files; import java.util.*; -public class LinuxHabboClient implements HabboClient { +public class LinuxHabboClient extends HabboClient { private static final String[] potentialProcessNames = {"--ppapi-flash-args", "plugin-container"}; @@ -16,7 +17,9 @@ public class LinuxHabboClient implements HabboClient { private static final boolean DEBUG = false; - public LinuxHabboClient() { + public LinuxHabboClient(HConnection connection) { + super(connection); + File folder = new File("/proc"); boolean found = false; diff --git a/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java b/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java new file mode 100644 index 0000000..9ebb517 --- /dev/null +++ b/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java @@ -0,0 +1,59 @@ +package main.protocol.memory.habboclient.windows; + +import main.protocol.HConnection; +import main.protocol.memory.habboclient.HabboClient; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Jeunez on 27/06/2018. + */ +public class WindowsHabboClient extends HabboClient { + + private static final boolean DEBUG = true; + private int[] PID; // list of potential PIDs + + public WindowsHabboClient(HConnection connection) { + super(connection); + + + } + + private void obtain_PID () { + String command="cmd /C netstat -a -o -n | findstr "+hConnection.getClientHostAndPort()+" | findstr ESTABLISHED"; + try { + Process process = Runtime.getRuntime().exec(command); + BufferedReader reader=new BufferedReader( new InputStreamReader(process.getInputStream())); + String s; + while ((s = reader.readLine()) != null){ + String[] split = s.split(" "); + + List realSplit = new ArrayList<>(); + for (String spli : split) { + if (!spli.equals("") && !spli.equals(" ")) { + realSplit.add(spli); + } + } + + if (realSplit.get(1).equals(hConnection.getClientHostAndPort())) { +// PID = Integer.parseInt(realSplit.get(4)); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public List getRC4possibilities() { + obtain_PID(); + if (DEBUG) System.out.println("FLASH PROCESS ID: " + PID); + + while (true) {} +// return null; + } +} diff --git a/src/main/ui/logger/loggerdisplays/SimpleTerminalLogger.java b/src/main/ui/logger/loggerdisplays/SimpleTerminalLogger.java index badedd0..2758071 100644 --- a/src/main/ui/logger/loggerdisplays/SimpleTerminalLogger.java +++ b/src/main/ui/logger/loggerdisplays/SimpleTerminalLogger.java @@ -48,6 +48,8 @@ class SimpleTerminalLogger implements PacketLogger { "" : packet.toString() ); + + System.out.println(output.toString()); } @Override