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