mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
Merge branch 'master' into windowsSupport
# Conflicts: # G-Earth.iml
This commit is contained in:
commit
5ba1ddf8a8
@ -7,8 +7,6 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="jna-4.5.1" level="project" />
|
||||
<orderEntry type="library" name="jna-platform-4.5.1" level="project" />
|
||||
<orderEntry type="library" name="json-simple-1.1.1" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -3,6 +3,9 @@ package main.extensions.examples.blockreplacepackets;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import main.extensions.ExtensionForm;
|
||||
import main.extensions.ExtensionInfo;
|
||||
@ -23,11 +26,22 @@ import java.net.URL;
|
||||
)
|
||||
public class BlockAndReplacePackets extends ExtensionForm {
|
||||
|
||||
public TextField txt_replacement;
|
||||
public ComboBox<String> cmb_type;
|
||||
public TextField txt_id;
|
||||
public Button btn_add;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ExtensionForm.args = args;
|
||||
launch(args);
|
||||
}
|
||||
|
||||
//initialize javaFX elements
|
||||
public void initialize() {
|
||||
cmb_type.getItems().addAll("Block OUT", "Block IN", "Replace OUT", "Replace IN");
|
||||
cmb_type.getSelectionModel().selectFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initExtension() {
|
||||
|
||||
@ -38,7 +52,8 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
FXMLLoader loader = new FXMLLoader(BlockAndReplacePackets.class.getResource("blockreplace.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle("Packet blocker and replacer");
|
||||
primaryStage.setScene(new Scene(root, 565, 262));
|
||||
primaryStage.setTitle("Packet blocker &/ replacer");
|
||||
primaryStage.setScene(new Scene(root, 580, 262));
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("bootstrap3.css").toExternalForm());
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextArea?>
|
||||
<?import javafx.scene.control.Tab?>
|
||||
<?import javafx.scene.control.TabPane?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
|
||||
<GridPane prefHeight="260.0" prefWidth="179.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.extensions.examples.blockreplacepackets.BlockAndReplacePackets">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="367.0" minWidth="10.0" prefWidth="163.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<TabPane prefHeight="255.0" prefWidth="580.0" tabClosingPolicy="UNAVAILABLE" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.extensions.examples.blockreplacepackets.BlockAndReplacePackets">
|
||||
<tabs>
|
||||
<Tab text="Block/replace packet">
|
||||
<content>
|
||||
<GridPane>
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="121.0" minHeight="10.0" prefHeight="28.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="234.0" minHeight="10.0" prefHeight="234.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="209.0" minHeight="10.0" prefHeight="187.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="363.0" minHeight="10.0" prefHeight="35.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<TextArea fx:id="text" editable="false" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
|
||||
<GridPane prefHeight="30.0" prefWidth="500.0" GridPane.rowIndex="1">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="118.0" minWidth="10.0" prefWidth="28.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="291.0" minWidth="0.0" prefWidth="68.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="291.0" minWidth="0.0" prefWidth="124.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="246.0" minWidth="10.0" prefWidth="246.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="91.0" minWidth="10.0" prefWidth="68.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Button fx:id="btn_add" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Add" GridPane.columnIndex="4">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
<Insets left="5.0" right="5.0" />
|
||||
</GridPane.margin>
|
||||
</TextArea>
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Blocks packets:" textAlignment="CENTER" GridPane.halignment="CENTER" GridPane.valignment="CENTER" />
|
||||
</Button>
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Id:" textAlignment="CENTER" textFill="#000000ba" />
|
||||
<TextField fx:id="txt_id" GridPane.columnIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets left="5.0" right="5.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<ComboBox fx:id="cmb_type" maxWidth="1.7976931348623157E308" GridPane.columnIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="5.0" right="5.0" />
|
||||
</GridPane.margin>
|
||||
</ComboBox>
|
||||
<TextField fx:id="txt_replacement" disable="true" GridPane.columnIndex="3">
|
||||
<GridPane.margin>
|
||||
<Insets left="5.0" right="5.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
</children>
|
||||
<GridPane.margin>
|
||||
<Insets bottom="10.0" left="17.0" right="17.0" />
|
||||
</GridPane.margin>
|
||||
</GridPane>
|
||||
</children>
|
||||
</GridPane>
|
||||
</GridPane>
|
||||
</content>
|
||||
</Tab>
|
||||
<Tab text="Block/replace value">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
|
||||
</content>
|
||||
</Tab>
|
||||
</tabs>
|
||||
</TabPane>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package main.misc;
|
||||
|
||||
import main.Main;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
@ -17,10 +18,10 @@ import java.util.Map;
|
||||
*/
|
||||
public class Cacher {
|
||||
|
||||
private static final String CACHEFILENAME = "jsoncache.json";
|
||||
private static final String CACHEFILENAME = "cache.json";
|
||||
|
||||
private static String getCacheDir() {
|
||||
return System.getProperty("user.home") + File.separator + ".G-Earth" + File.separator;
|
||||
return new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent();
|
||||
}
|
||||
|
||||
private static boolean cacheFileExists() {
|
||||
|
@ -265,7 +265,7 @@ public class HConnection {
|
||||
|
||||
handler.act(buffer);
|
||||
if (!datastream[0] && handler.isDataStream()) {
|
||||
clientHostAndPort = client.getInetAddress().getHostAddress() + ":" + client.getPort();
|
||||
clientHostAndPort = client.getLocalAddress().getHostAddress() + ":" + client.getPort();
|
||||
if (DEBUG) System.out.println(clientHostAndPort);
|
||||
datastream[0] = true;
|
||||
setState(State.CONNECTED);
|
||||
|
@ -185,6 +185,46 @@ public class HPacket implements StringifyAble {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
public boolean structureEquals(String structure) {
|
||||
if (isCorrupted()) return false;
|
||||
|
||||
int indexbuffer = readIndex;
|
||||
readIndex = 6;
|
||||
|
||||
String[] split = structure.split(",");
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
String s = split[i];
|
||||
|
||||
if (s.equals("s")) {
|
||||
if (readUshort(readIndex) + 2 + readIndex > getBytesLength()) return false;
|
||||
readString();
|
||||
}
|
||||
else if (s.equals("i")) {
|
||||
if (readIndex + 4 > getBytesLength()) return false;
|
||||
readInteger();
|
||||
}
|
||||
else if (s.equals("u")) {
|
||||
if (readIndex + 2 > getBytesLength()) return false;
|
||||
readUshort();
|
||||
}
|
||||
else if (s.equals("b")) {
|
||||
if (readIndex + 1 > getBytesLength()) return false;
|
||||
readBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
boolean result = (isEOF() == 1);
|
||||
readIndex = indexbuffer;
|
||||
return result;
|
||||
}
|
||||
|
||||
public int isEOF() {
|
||||
if (readIndex < getBytesLength()) return 0;
|
||||
if (readIndex == getBytesLength()) return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
public byte[] toBytes() {
|
||||
return packetInBytes;
|
||||
}
|
||||
@ -800,34 +840,5 @@ public class HPacket implements StringifyAble {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// HPacket packet = new HPacket("{l}{u:500}{i:4}{s:heey}{b:false}");
|
||||
// System.out.println(packet);
|
||||
//
|
||||
// String stringified = packet.stringify();
|
||||
// System.out.println("stringified: " + stringified);
|
||||
// System.out.println(stringified.length());
|
||||
//
|
||||
//
|
||||
// HPacket packet1 = new HPacket(new byte[0]);
|
||||
// packet1.constructFromString(stringified);
|
||||
//
|
||||
// System.out.println(packet1);
|
||||
// System.out.println(packet.equals(packet1));
|
||||
|
||||
HPacket packet = new HPacket(555);
|
||||
for (int i = -128; i < 128; i++) {
|
||||
packet.appendByte((byte)i);
|
||||
}
|
||||
System.out.println(packet);
|
||||
|
||||
String stringified = packet.stringify();
|
||||
System.out.println(stringified.length());
|
||||
|
||||
|
||||
HPacket packet1 = new HPacket(new byte[0]);
|
||||
packet1.constructFromString(stringified);
|
||||
|
||||
System.out.println(packet1);
|
||||
System.out.println(packet.equals(packet1));
|
||||
}
|
||||
}
|
@ -203,4 +203,8 @@ public class RC4 {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public byte[] getState () {
|
||||
return state;
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
package main.protocol.memory;
|
||||
|
||||
import main.protocol.HConnection;
|
||||
import main.protocol.HMessage;
|
||||
import main.protocol.HPacket;
|
||||
import main.protocol.crypto.RC4;
|
||||
import main.protocol.memory.habboclient.HabboClient;
|
||||
import main.protocol.memory.habboclient.HabboClientFactory;
|
||||
import main.protocol.memory.habboclient.linux.LinuxHabboClient;
|
||||
import main.protocol.packethandler.Handler;
|
||||
import main.protocol.packethandler.IncomingHandler;
|
||||
import main.protocol.packethandler.OutgoingHandler;
|
||||
import main.protocol.packethandler.PayloadBuffer;
|
||||
@ -29,56 +31,65 @@ public class Rc4Obtainer {
|
||||
public void setOutgoingHandler(OutgoingHandler handler) {
|
||||
outgoingHandler = handler;
|
||||
handler.addBufferListener((int addedbytes) -> {
|
||||
if (!hashappened1 && handler.getCurrentIndex() == 3) {
|
||||
if (!hashappened1 && handler.isEncryptedStream()) {
|
||||
hashappened1 = true;
|
||||
onSendFirstEncryptedMessage();
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onSendFirstEncryptedMessage() {
|
||||
|
||||
private void onSendFirstEncryptedMessage(Handler handler) {
|
||||
outgoingHandler.block();
|
||||
incomingHandler.block();
|
||||
new Thread(() -> {
|
||||
if (DEBUG) System.out.println("[+] send encrypted");
|
||||
|
||||
new Thread(() -> {
|
||||
|
||||
if (DEBUG) System.out.println("[+] send encrypted");
|
||||
|
||||
List<byte[]> results = client.getRC4possibilities();
|
||||
outerloop:
|
||||
for (byte[] possible : results) {
|
||||
|
||||
byte[] encBuffer = new byte[outgoingHandler.getEncryptedBuffer().size()];
|
||||
byte[] encBuffer = new byte[handler.getEncryptedBuffer().size()];
|
||||
for (int i = 0; i < encBuffer.length; i++) {
|
||||
encBuffer[i] = outgoingHandler.getEncryptedBuffer().get(i);
|
||||
encBuffer[i] = handler.getEncryptedBuffer().get(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
// System.out.println(i);
|
||||
for (int j = 0; j < 256; j++) {
|
||||
byte[] keycpy = Arrays.copyOf(possible, possible.length);
|
||||
RC4 rc4Tryout = new RC4(keycpy, i, j);
|
||||
|
||||
rc4Tryout.undoRc4(encBuffer);
|
||||
if (handler.getMessageSide() == HMessage.Side.TOSERVER) rc4Tryout.undoRc4(encBuffer);
|
||||
if (rc4Tryout.couldBeFresh()) {
|
||||
byte[] encDataCopy = Arrays.copyOf(encBuffer, encBuffer.length);
|
||||
RC4 rc4TryCopy = rc4Tryout.deepCopy();
|
||||
|
||||
try {
|
||||
PayloadBuffer payloadBuffer = new PayloadBuffer();
|
||||
HPacket[] checker = payloadBuffer.pushAndReceive(rc4TryCopy.rc4(encDataCopy));
|
||||
byte[] decoded = rc4TryCopy.rc4(encDataCopy);
|
||||
HPacket[] checker = payloadBuffer.pushAndReceive(decoded);
|
||||
|
||||
if (payloadBuffer.peak().length == 0) {
|
||||
outgoingHandler.setRc4(rc4Tryout);
|
||||
incomingHandler.setRc4(rc4Tryout);
|
||||
handler.setRc4(rc4Tryout);
|
||||
break outerloop;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -146,13 +146,25 @@ public class LinuxHabboClient extends HabboClient {
|
||||
for (LinuxMemorySnippet snippet : possibilities) {
|
||||
if (snippet.getData().length >= 1024 && snippet.getData().length <= 1024+2*offset) {
|
||||
for (int i = 0; i < (snippet.getData().length - ((256 - 1) * offset)); i+=offset) {
|
||||
byte[] wannabeRC4data = Arrays.copyOfRange(snippet.getData(), i, 1025 + i);
|
||||
byte[] wannabeRC4data = Arrays.copyOfRange(snippet.getData(), i, 1024 + i);
|
||||
byte[] data = new byte[256]; // dis is the friggin key
|
||||
for (int j = 0; j < 256; j++) data[j] = wannabeRC4data[j*4];
|
||||
|
||||
boolean isvalid = true;
|
||||
for (int j = 0; j < 1024; j++) {
|
||||
if (j % 4 != 0 && wannabeRC4data[j] != 0) {
|
||||
isvalid = false;
|
||||
break;
|
||||
}
|
||||
if (j % 4 == 0) {
|
||||
data[j/4] = wannabeRC4data[j];
|
||||
}
|
||||
}
|
||||
if (isvalid) {
|
||||
resultSet.add(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.protocol.packethandler;
|
||||
|
||||
import main.protocol.HMessage;
|
||||
import main.protocol.HPacket;
|
||||
import main.protocol.TrafficListener;
|
||||
import main.protocol.crypto.RC4;
|
||||
|
||||
@ -20,8 +21,13 @@ public abstract class Handler {
|
||||
volatile boolean isDataStream = false;
|
||||
volatile int currentIndex = 0;
|
||||
|
||||
protected RC4 clientcipher = null;
|
||||
protected RC4 servercipher = null;
|
||||
protected final Object lock = new Object();
|
||||
|
||||
protected RC4 decryptcipher = null;
|
||||
protected RC4 encryptcipher = null;
|
||||
|
||||
protected volatile List<Byte> tempEncryptedBuffer = new ArrayList<>();
|
||||
protected volatile boolean isEncryptedStream = false;
|
||||
|
||||
|
||||
public Handler(OutputStream outputStream, Object[] listeners) {
|
||||
@ -34,11 +40,51 @@ public abstract class Handler {
|
||||
isDataStream = true;
|
||||
}
|
||||
|
||||
public boolean isEncryptedStream() {
|
||||
return isEncryptedStream;
|
||||
}
|
||||
|
||||
public abstract void act(byte[] buffer) throws IOException;
|
||||
protected void continuedAct(byte[] buffer) throws IOException {
|
||||
notifyBufferListeners(buffer.length);
|
||||
|
||||
if (!isEncryptedStream) {
|
||||
payloadBuffer.push(buffer);
|
||||
}
|
||||
else if (decryptcipher == null) {
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
tempEncryptedBuffer.add(buffer[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
byte[] tm = decryptcipher.rc4(buffer);
|
||||
if (DEBUG) {
|
||||
printForDebugging(tm);
|
||||
}
|
||||
payloadBuffer.push(tm);
|
||||
}
|
||||
|
||||
if (!isTempBlocked) {
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setRc4(RC4 rc4) {
|
||||
this.clientcipher = rc4.deepCopy();
|
||||
this.servercipher = rc4.deepCopy();
|
||||
this.decryptcipher = rc4.deepCopy();
|
||||
this.encryptcipher = rc4.deepCopy();
|
||||
|
||||
byte[] encrbuffer = new byte[tempEncryptedBuffer.size()];
|
||||
for (int i = 0; i < tempEncryptedBuffer.size(); i++) {
|
||||
encrbuffer[i] = tempEncryptedBuffer.get(i);
|
||||
}
|
||||
|
||||
try {
|
||||
act(encrbuffer);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
tempEncryptedBuffer = null;
|
||||
}
|
||||
|
||||
public void block() {
|
||||
@ -58,19 +104,55 @@ public abstract class Handler {
|
||||
* @param message
|
||||
*/
|
||||
void notifyListeners(HMessage message) {
|
||||
for (TrafficListener listener : (List<TrafficListener>)listeners[0]) {
|
||||
listener.onCapture(message);
|
||||
}
|
||||
for (TrafficListener listener : (List<TrafficListener>)listeners[1]) {
|
||||
listener.onCapture(message);
|
||||
}
|
||||
for (TrafficListener listener : (List<TrafficListener>)listeners[2]) {
|
||||
listener.onCapture(message);
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int i = ((List<TrafficListener>)listeners[x]).size() - 1; i >= 0; i--) {
|
||||
((List<TrafficListener>)listeners[x]).get(i).onCapture(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
public abstract void sendToStream(byte[] buffer);
|
||||
|
||||
public abstract void flush() throws IOException;
|
||||
public void sendToStream(byte[] buffer) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
out.write(
|
||||
(!isEncryptedStream)
|
||||
? buffer
|
||||
: encryptcipher.rc4(buffer)
|
||||
);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
synchronized (lock) {
|
||||
HPacket[] hpackets = payloadBuffer.receive();
|
||||
|
||||
for (HPacket hpacket : hpackets){
|
||||
HMessage hMessage = new HMessage(hpacket, getMessageSide(), currentIndex);
|
||||
boolean isencrypted = isEncryptedStream;
|
||||
if (isDataStream) {
|
||||
notifyListeners(hMessage);
|
||||
}
|
||||
|
||||
if (!hMessage.isBlocked()) {
|
||||
out.write(
|
||||
(!isencrypted)
|
||||
? hMessage.getPacket().toBytes()
|
||||
: encryptcipher.rc4(hMessage.getPacket().toBytes())
|
||||
);
|
||||
}
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract HMessage.Side getMessageSide();
|
||||
|
||||
public List<Byte> getEncryptedBuffer() {
|
||||
return tempEncryptedBuffer;
|
||||
}
|
||||
|
||||
protected abstract void printForDebugging(byte[] bytes);
|
||||
|
||||
|
@ -2,44 +2,36 @@ package main.protocol.packethandler;
|
||||
|
||||
import main.protocol.HMessage;
|
||||
import main.protocol.HPacket;
|
||||
import main.protocol.memory.Rc4Obtainer;
|
||||
import main.protocol.TrafficListener;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
public class IncomingHandler extends Handler {
|
||||
|
||||
public IncomingHandler(OutputStream outputStream, Object[] listeners) {
|
||||
super(outputStream, listeners);
|
||||
|
||||
TrafficListener listener = new TrafficListener() {
|
||||
@Override
|
||||
public void onCapture(HMessage message) {
|
||||
if (isDataStream && message.getPacket().structureEquals("s,b")) {
|
||||
((List<TrafficListener>)listeners[0]).remove(this);
|
||||
HPacket packet = message.getPacket();
|
||||
packet.readString();
|
||||
isEncryptedStream = packet.readBoolean();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
private Boolean isEncryptedStream = null;
|
||||
|
||||
((List<TrafficListener>)listeners[0]).add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(byte[] buffer) throws IOException {
|
||||
if (isDataStream) {
|
||||
if (DEBUG) {
|
||||
printForDebugging(buffer);
|
||||
}
|
||||
|
||||
|
||||
if (isEncryptedStream == null || !isEncryptedStream) {
|
||||
payloadBuffer.push(buffer);
|
||||
}
|
||||
else {
|
||||
payloadBuffer.push(servercipher.rc4(buffer));
|
||||
}
|
||||
|
||||
|
||||
notifyBufferListeners(buffer.length);
|
||||
|
||||
if (!isTempBlocked) {
|
||||
flush();
|
||||
}
|
||||
continuedAct(buffer);
|
||||
}
|
||||
else {
|
||||
out.write(buffer);
|
||||
@ -47,46 +39,8 @@ public class IncomingHandler extends Handler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToStream(byte[] buffer) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
out.write(
|
||||
(isEncryptedStream == null || !isEncryptedStream)
|
||||
? buffer
|
||||
: clientcipher.rc4(buffer)
|
||||
);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
synchronized (lock) {
|
||||
HPacket[] hpackets = payloadBuffer.receive();
|
||||
|
||||
for (HPacket hpacket : hpackets){
|
||||
HMessage hMessage = new HMessage(hpacket, HMessage.Side.TOCLIENT, currentIndex);
|
||||
if (isDataStream) {
|
||||
notifyListeners(hMessage);
|
||||
}
|
||||
|
||||
if (!hMessage.isBlocked()) {
|
||||
out.write(
|
||||
(isEncryptedStream == null || !isEncryptedStream)
|
||||
? hMessage.getPacket().toBytes()
|
||||
: clientcipher.rc4(hMessage.getPacket().toBytes())
|
||||
);
|
||||
}
|
||||
|
||||
if (isDataStream && isEncryptedStream == null && hpacket.length() == 261) {
|
||||
isEncryptedStream = hpacket.readBoolean(264);
|
||||
}
|
||||
currentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
public HMessage.Side getMessageSide() {
|
||||
return HMessage.Side.TOCLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,21 +2,13 @@ package main.protocol.packethandler;
|
||||
|
||||
import main.protocol.HMessage;
|
||||
import main.protocol.HPacket;
|
||||
import main.protocol.crypto.RC4;
|
||||
import main.protocol.memory.Rc4Obtainer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OutgoingHandler extends Handler {
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
private final static int encryptOffset = 3; //all packets with index < 3 aren't encrypted
|
||||
private List<Byte> tempEncryptedBuffer = new ArrayList<>();
|
||||
|
||||
public OutgoingHandler(OutputStream outputStream, Object[] listeners) {
|
||||
super(outputStream, listeners);
|
||||
}
|
||||
@ -31,28 +23,13 @@ public class OutgoingHandler extends Handler {
|
||||
@Override
|
||||
public void act(byte[] buffer) throws IOException {
|
||||
dataStreamCheck(buffer);
|
||||
|
||||
if (isDataStream) {
|
||||
if (currentIndex < encryptOffset) {
|
||||
payloadBuffer.push(buffer);
|
||||
}
|
||||
else if (clientcipher == null) {
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
tempEncryptedBuffer.add(buffer[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
byte[] tm = clientcipher.rc4(buffer);
|
||||
if (DEBUG) {
|
||||
printForDebugging(tm);
|
||||
}
|
||||
payloadBuffer.push(tm);
|
||||
if (!isEncryptedStream && (new HPacket(buffer).length() < 2 || new HPacket(buffer).length() > 1000)) {
|
||||
isEncryptedStream = true;
|
||||
}
|
||||
|
||||
notifyBufferListeners(buffer.length);
|
||||
|
||||
if (!isTempBlocked) {
|
||||
flush();
|
||||
}
|
||||
continuedAct(buffer);
|
||||
}
|
||||
else {
|
||||
out.write(buffer);
|
||||
@ -60,55 +37,8 @@ public class OutgoingHandler extends Handler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRc4(RC4 rc4) {
|
||||
super.setRc4(rc4);
|
||||
|
||||
byte[] encrbuffer = new byte[tempEncryptedBuffer.size()];
|
||||
for (int i = 0; i < tempEncryptedBuffer.size(); i++) {
|
||||
encrbuffer[i] = tempEncryptedBuffer.get(i);
|
||||
}
|
||||
|
||||
try {
|
||||
act(encrbuffer);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
tempEncryptedBuffer = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToStream(byte[] buffer) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
out.write(servercipher.rc4(buffer));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Byte> getEncryptedBuffer() {
|
||||
return tempEncryptedBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
synchronized (lock) {
|
||||
HPacket[] hpackets = payloadBuffer.receive();
|
||||
for (HPacket hpacket : hpackets){
|
||||
HMessage hMessage = new HMessage(hpacket, HMessage.Side.TOSERVER, currentIndex);
|
||||
if (isDataStream) notifyListeners(hMessage);
|
||||
if (!hMessage.isBlocked()) {
|
||||
out.write(
|
||||
currentIndex < encryptOffset ? hMessage.getPacket().toBytes() :
|
||||
servercipher.rc4(hMessage.getPacket().toBytes())
|
||||
);
|
||||
}
|
||||
currentIndex ++;
|
||||
}
|
||||
}
|
||||
|
||||
public HMessage.Side getMessageSide() {
|
||||
return HMessage.Side.TOSERVER;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user