mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-26 18:30:52 +01:00
renew rc4obtainer <-> packethandler code
This commit is contained in:
parent
0e09ece9d6
commit
7196512ee1
@ -6,10 +6,8 @@ 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;
|
||||
import org.json.JSONArray;
|
||||
import gearth.protocol.packethandler.IncomingPacketHandler;
|
||||
import gearth.protocol.packethandler.OutgoingPacketHandler;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
@ -122,8 +120,8 @@ public class HConnection {
|
||||
|
||||
private volatile ServerSocket proxy_server = null; //listener for the client
|
||||
|
||||
private volatile IncomingHandler inHandler = null; //connection with client (only initialized when verified habbo connection)
|
||||
private volatile OutgoingHandler outHandler = null; //connection with server (only initialized when verified habbo connection)
|
||||
private volatile IncomingPacketHandler inHandler = null; //connection with client (only initialized when verified habbo connection)
|
||||
private volatile OutgoingPacketHandler outHandler = null; //connection with server (only initialized when verified habbo connection)
|
||||
|
||||
|
||||
public Proxy(String input_domain, String actual_domain, int actual_port, int intercept_port, String intercept_host) {
|
||||
@ -138,7 +136,7 @@ public class HConnection {
|
||||
this.proxy_server = socket;
|
||||
}
|
||||
|
||||
public void verifyProxy(IncomingHandler incomingHandler, OutgoingHandler outgoingHandler) {
|
||||
public void verifyProxy(IncomingPacketHandler incomingHandler, OutgoingPacketHandler outgoingHandler) {
|
||||
this.inHandler = incomingHandler;
|
||||
this.outHandler = outgoingHandler;
|
||||
}
|
||||
@ -167,11 +165,11 @@ public class HConnection {
|
||||
return intercept_host;
|
||||
}
|
||||
|
||||
public IncomingHandler getInHandler() {
|
||||
public IncomingPacketHandler getInHandler() {
|
||||
return inHandler;
|
||||
}
|
||||
|
||||
public OutgoingHandler getOutHandler() {
|
||||
public OutgoingPacketHandler getOutHandler() {
|
||||
return outHandler;
|
||||
}
|
||||
}
|
||||
@ -323,11 +321,9 @@ public class HConnection {
|
||||
final boolean[] aborted = new boolean[1];
|
||||
Rc4Obtainer rc4Obtainer = new Rc4Obtainer(this);
|
||||
|
||||
OutgoingHandler outgoingHandler = new OutgoingHandler(habbo_server_out, trafficListeners);
|
||||
rc4Obtainer.setOutgoingHandler(outgoingHandler);
|
||||
|
||||
IncomingHandler incomingHandler = new IncomingHandler(client_out, trafficListeners);
|
||||
rc4Obtainer.setIncomingHandler(incomingHandler);
|
||||
OutgoingPacketHandler outgoingHandler = new OutgoingPacketHandler(habbo_server_out, trafficListeners);
|
||||
IncomingPacketHandler incomingHandler = new IncomingPacketHandler(client_out, trafficListeners);
|
||||
rc4Obtainer.setPacketHandlers(outgoingHandler, incomingHandler);
|
||||
|
||||
outgoingHandler.addOnDatastreamConfirmedListener(hotelVersion -> {
|
||||
incomingHandler.setAsDataStream();
|
||||
|
@ -7,10 +7,7 @@ import gearth.protocol.HPacket;
|
||||
import gearth.protocol.crypto.RC4;
|
||||
import gearth.protocol.memory.habboclient.HabboClient;
|
||||
import gearth.protocol.memory.habboclient.HabboClientFactory;
|
||||
import gearth.protocol.packethandler.Handler;
|
||||
import gearth.protocol.packethandler.IncomingHandler;
|
||||
import gearth.protocol.packethandler.OutgoingHandler;
|
||||
import gearth.protocol.packethandler.PayloadBuffer;
|
||||
import gearth.protocol.packethandler.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
@ -22,47 +19,45 @@ import javafx.scene.web.WebView;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Rc4Obtainer {
|
||||
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
HabboClient client = null;
|
||||
OutgoingHandler outgoingHandler = null;
|
||||
IncomingHandler incomingHandler = null;
|
||||
private HabboClient client;
|
||||
private List<PacketHandler> packetHandlers;
|
||||
|
||||
public Rc4Obtainer(HConnection hConnection) {
|
||||
client = HabboClientFactory.get(hConnection);
|
||||
}
|
||||
|
||||
private boolean hashappened1 = false;
|
||||
public void setOutgoingHandler(OutgoingHandler handler) {
|
||||
outgoingHandler = handler;
|
||||
handler.addBufferListener((int addedbytes) -> {
|
||||
if (!hashappened1 && handler.isEncryptedStream()) {
|
||||
hashappened1 = true;
|
||||
onSendFirstEncryptedMessage(outgoingHandler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean hashappened2 = false;
|
||||
public void setIncomingHandler(IncomingHandler handler) {
|
||||
incomingHandler = handler;
|
||||
handler.addBufferListener((int addedbytes) -> {
|
||||
if (!hashappened2 && handler.isEncryptedStream()) {
|
||||
hashappened2 = true;
|
||||
onSendFirstEncryptedMessage(incomingHandler);
|
||||
}
|
||||
});
|
||||
public void setPacketHandlers(PacketHandler... packetHandlers) {
|
||||
this.packetHandlers = Arrays.asList(packetHandlers);
|
||||
|
||||
for (PacketHandler handler : packetHandlers) {
|
||||
BufferChangeListener bufferChangeListener = new BufferChangeListener() {
|
||||
@Override
|
||||
public void act() {
|
||||
if (handler.isEncryptedStream()) {
|
||||
onSendFirstEncryptedMessage(handler);
|
||||
handler.removeBufferChangeListener(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
handler.onBufferChanged(bufferChangeListener);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void onSendFirstEncryptedMessage(Handler handler) {
|
||||
|
||||
private void onSendFirstEncryptedMessage(PacketHandler packetHandler) {
|
||||
if (!HConnection.DECRYPTPACKETS) return;
|
||||
|
||||
outgoingHandler.block();
|
||||
incomingHandler.block();
|
||||
packetHandlers.forEach(PacketHandler::block);
|
||||
|
||||
new Thread(() -> {
|
||||
|
||||
@ -72,8 +67,8 @@ public class Rc4Obtainer {
|
||||
int i = 0;
|
||||
while (!worked && i < 4) {
|
||||
worked = (i % 2 == 0) ?
|
||||
onSendFirstEncryptedMessage(handler, client.getRC4cached()) :
|
||||
onSendFirstEncryptedMessage(handler, client.getRC4possibilities());
|
||||
onSendFirstEncryptedMessage(packetHandler, client.getRC4cached()) :
|
||||
onSendFirstEncryptedMessage(packetHandler, client.getRC4possibilities());
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -107,17 +102,16 @@ public class Rc4Obtainer {
|
||||
|
||||
}
|
||||
|
||||
incomingHandler.unblock();
|
||||
outgoingHandler.unblock();
|
||||
packetHandlers.forEach(PacketHandler::unblock);
|
||||
}).start();
|
||||
}
|
||||
|
||||
private boolean onSendFirstEncryptedMessage(Handler handler, List<byte[]> potentialRC4tables) {
|
||||
private boolean onSendFirstEncryptedMessage(PacketHandler packetHandler, List<byte[]> potentialRC4tables) {
|
||||
for (byte[] possible : potentialRC4tables) {
|
||||
|
||||
byte[] encBuffer = new byte[handler.getEncryptedBuffer().size()];
|
||||
byte[] encBuffer = new byte[packetHandler.getEncryptedBuffer().size()];
|
||||
for (int i = 0; i < encBuffer.length; i++) {
|
||||
encBuffer[i] = handler.getEncryptedBuffer().get(i);
|
||||
encBuffer[i] = packetHandler.getEncryptedBuffer().get(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
@ -125,7 +119,7 @@ public class Rc4Obtainer {
|
||||
byte[] keycpy = Arrays.copyOf(possible, possible.length);
|
||||
RC4 rc4Tryout = new RC4(keycpy, i, j);
|
||||
|
||||
if (handler.getMessageSide() == HMessage.Side.TOSERVER) rc4Tryout.undoRc4(encBuffer);
|
||||
if (packetHandler.getMessageSide() == HMessage.Side.TOSERVER) rc4Tryout.undoRc4(encBuffer);
|
||||
if (rc4Tryout.couldBeFresh()) {
|
||||
byte[] encDataCopy = Arrays.copyOf(encBuffer, encBuffer.length);
|
||||
RC4 rc4TryCopy = rc4Tryout.deepCopy();
|
||||
@ -136,7 +130,7 @@ public class Rc4Obtainer {
|
||||
HPacket[] checker = payloadBuffer.pushAndReceive(decoded);
|
||||
|
||||
if (payloadBuffer.peak().length == 0) {
|
||||
handler.setRc4(rc4Tryout);
|
||||
packetHandler.setRc4(rc4Tryout);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
package gearth.protocol.packethandler;
|
||||
|
||||
|
||||
public interface BufferChangeListener {
|
||||
|
||||
void act();
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package gearth.protocol.packethandler;
|
||||
|
||||
|
||||
public interface BufferListener {
|
||||
|
||||
void act(int addedbytes);
|
||||
|
||||
}
|
@ -8,9 +8,9 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
public class IncomingHandler extends Handler {
|
||||
public class IncomingPacketHandler extends PacketHandler {
|
||||
|
||||
public IncomingHandler(OutputStream outputStream, Object[] listeners) {
|
||||
public IncomingPacketHandler(OutputStream outputStream, Object[] listeners) {
|
||||
super(outputStream, listeners);
|
||||
|
||||
TrafficListener listener = new TrafficListener() {
|
@ -8,9 +8,9 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OutgoingHandler extends Handler {
|
||||
public class OutgoingPacketHandler extends PacketHandler {
|
||||
|
||||
public OutgoingHandler(OutputStream outputStream, Object[] listeners) {
|
||||
public OutgoingPacketHandler(OutputStream outputStream, Object[] listeners) {
|
||||
super(outputStream, listeners);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Handler {
|
||||
public abstract class PacketHandler {
|
||||
|
||||
protected static final boolean DEBUG = false;
|
||||
|
||||
@ -31,7 +31,7 @@ public abstract class Handler {
|
||||
protected volatile boolean isEncryptedStream = false;
|
||||
|
||||
|
||||
public Handler(OutputStream outputStream, Object[] listeners) {
|
||||
public PacketHandler(OutputStream outputStream, Object[] listeners) {
|
||||
this.listeners = listeners;
|
||||
out = outputStream;
|
||||
}
|
||||
@ -47,7 +47,7 @@ public abstract class Handler {
|
||||
|
||||
public abstract void act(byte[] buffer) throws IOException;
|
||||
protected void continuedAct(byte[] buffer) throws IOException {
|
||||
notifyBufferListeners(buffer.length);
|
||||
notifyBufferListeners();
|
||||
|
||||
if (!isEncryptedStream) {
|
||||
payloadBuffer.push(buffer);
|
||||
@ -164,16 +164,16 @@ public abstract class Handler {
|
||||
|
||||
protected abstract void printForDebugging(byte[] bytes);
|
||||
|
||||
private List<BufferListener> bufferListeners = new ArrayList<>();
|
||||
public void addBufferListener(BufferListener listener) {
|
||||
bufferListeners.add(listener);
|
||||
private List<BufferChangeListener> bufferChangeListeners = new ArrayList<>();
|
||||
public void onBufferChanged(BufferChangeListener listener) {
|
||||
bufferChangeListeners.add(listener);
|
||||
}
|
||||
public void removeBufferListener(BufferListener listener) {
|
||||
bufferListeners.remove(listener);
|
||||
public void removeBufferChangeListener(BufferChangeListener listener) {
|
||||
bufferChangeListeners.remove(listener);
|
||||
}
|
||||
void notifyBufferListeners(int addedbytes) {
|
||||
for (int i = bufferListeners.size() - 1; i >= 0; i -= 1) {
|
||||
bufferListeners.get(i).act(addedbytes);
|
||||
void notifyBufferListeners() {
|
||||
for (int i = bufferChangeListeners.size() - 1; i >= 0; i -= 1) {
|
||||
bufferChangeListeners.get(i).act();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user