mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-27 02:40:51 +01:00
block&/replace packets extension UI
This commit is contained in:
parent
0d7c7b07ef
commit
4bd2798c71
@ -1,6 +1,11 @@
|
||||
package extensions.blockreplacepackets;
|
||||
|
||||
import gearth.protocol.HPacket;
|
||||
import gearth.ui.GEarthController;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
@ -26,8 +31,9 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
|
||||
public TextField txt_replacement;
|
||||
public ComboBox<String> cmb_type;
|
||||
public TextField txt_id;
|
||||
public Button btn_add;
|
||||
public ComboBox<String> cmb_side;
|
||||
public TextField txt_value;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ExtensionForm.args = args;
|
||||
@ -36,10 +42,85 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
|
||||
//initialize javaFX elements
|
||||
public void initialize() {
|
||||
cmb_type.getItems().addAll("Block OUT", "Block IN", "Replace OUT", "Replace IN");
|
||||
cmb_type.getItems().addAll("Block packet", "Replace packet", "Replace integer", "Replace string", "Replace substring");
|
||||
cmb_type.getSelectionModel().selectFirst();
|
||||
cmb_type.requestFocus();
|
||||
|
||||
cmb_side.getItems().addAll("Incoming", "Outgoing");
|
||||
cmb_side.getSelectionModel().selectFirst();
|
||||
|
||||
cmb_side.getSelectionModel().selectedItemProperty().addListener(observable -> Platform.runLater(this::refreshOptions));
|
||||
cmb_type.getSelectionModel().selectedItemProperty().addListener(observable -> Platform.runLater(this::refreshOptions));
|
||||
txt_replacement.textProperty().addListener(event -> Platform.runLater(this::refreshOptions));
|
||||
txt_value.textProperty().addListener(event -> Platform.runLater(this::refreshOptions));
|
||||
|
||||
refreshOptions();
|
||||
}
|
||||
|
||||
private void refreshOptions() {
|
||||
txt_replacement.setDisable(cmb_type.getSelectionModel().getSelectedItem().startsWith("Block"));
|
||||
if (cmb_side.getItems().size() == 2 && !cmb_type.getSelectionModel().getSelectedItem().endsWith("packet")) {
|
||||
cmb_side.getItems().add("All");
|
||||
}
|
||||
else if (cmb_side.getItems().size() == 3 && cmb_type.getSelectionModel().getSelectedItem().endsWith("packet")) {
|
||||
if (cmb_side.getSelectionModel().getSelectedItem() != null && cmb_side.getSelectionModel().getSelectedItem().equals("All")) {
|
||||
cmb_side.getSelectionModel().selectFirst();
|
||||
}
|
||||
cmb_side.getItems().remove(2);
|
||||
}
|
||||
|
||||
boolean isValid = false;
|
||||
String val = txt_value.getText();
|
||||
String repl = txt_replacement.getText();
|
||||
String type = cmb_type.getSelectionModel().getSelectedItem();
|
||||
String side = cmb_side.getSelectionModel().getSelectedItem();
|
||||
|
||||
if (side == null) {
|
||||
isValid = false;
|
||||
}
|
||||
else if (type.equals("Block packet")) {
|
||||
try {
|
||||
int v = Integer.parseInt(val);
|
||||
isValid = (v < (Short.MAX_VALUE * 2 + 2) && v > 0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (type.endsWith("packet")) {
|
||||
try {
|
||||
int v = Integer.parseInt(val);
|
||||
isValid = (v < (Short.MAX_VALUE * 2 + 2) && v > 0);
|
||||
if (isValid) {
|
||||
HPacket packet = new HPacket(repl);
|
||||
isValid = !packet.isCorrupted();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
else if (type.endsWith("string")) {
|
||||
isValid = !val.equals("") && !repl.equals("") && !val.equals(repl);
|
||||
}
|
||||
else if (type.endsWith("integer")) {
|
||||
try {
|
||||
int v1 = Integer.parseInt(val);
|
||||
int v2 = Integer.parseInt(repl);
|
||||
isValid = (v1 != v2);
|
||||
}
|
||||
catch (Exception e) {
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
btn_add.setDisable(!isValid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void initExtension() {
|
||||
|
||||
@ -51,7 +132,12 @@ public class BlockAndReplacePackets extends ExtensionForm {
|
||||
Parent root = loader.load();
|
||||
|
||||
primaryStage.setTitle("Packet blocker &/ replacer");
|
||||
primaryStage.setScene(new Scene(root, 580, 262));
|
||||
primaryStage.setScene(new Scene(root));
|
||||
primaryStage.setResizable(false);
|
||||
primaryStage.getScene().getStylesheets().add(GEarthController.class.getResource("/gearth/ui/bootstrap3.css").toExternalForm());
|
||||
}
|
||||
|
||||
public void click_btnAddRule(ActionEvent actionEvent) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,73 +4,144 @@
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Tab?>
|
||||
<?import javafx.scene.control.TabPane?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?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?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<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="extensions.blockreplacepackets.BlockAndReplacePackets">
|
||||
<tabs>
|
||||
<Tab text="Block/replace packet">
|
||||
<content>
|
||||
<GridPane>
|
||||
<GridPane prefHeight="324.0" prefWidth="588.0" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx/8.0.131" xmlns:fx="http://javafx.com/fxml/1" fx:controller="extensions.blockreplacepackets.BlockAndReplacePackets">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<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 maxHeight="276.0" minHeight="10.0" prefHeight="249.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="80.0" minHeight="80.0" prefHeight="80.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<GridPane prefHeight="30.0" prefWidth="500.0" GridPane.rowIndex="1">
|
||||
<GridPane 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 hgrow="SOMETIMES" maxWidth="464.0" minWidth="10.0" prefWidth="464.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="283.0" minWidth="10.0" prefWidth="116.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.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 left="5.0" right="5.0" />
|
||||
</GridPane.margin>
|
||||
</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 maxHeight="1.7976931348623157E308">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<children>
|
||||
<GridPane prefHeight="41.0" prefWidth="580.0">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="191.0" minWidth="10.0" prefWidth="127.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="346.0" minWidth="10.0" prefWidth="52.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="314.0" minWidth="10.0" prefWidth="136.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="314.0" minWidth="10.0" prefWidth="123.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="52.0" prefWidth="78.0" text="Value:" GridPane.columnIndex="1" />
|
||||
<TextField fx:id="txt_value" prefHeight="25.0" prefWidth="106.0" GridPane.columnIndex="2">
|
||||
<GridPane.margin>
|
||||
<Insets left="5.0" right="5.0" />
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<ComboBox fx:id="cmb_type" maxWidth="1.7976931348623157E308" GridPane.columnIndex="2">
|
||||
<ComboBox fx:id="cmb_type" maxWidth="1.7976931348623157E308">
|
||||
<GridPane.margin>
|
||||
<Insets left="5.0" right="5.0" />
|
||||
</GridPane.margin>
|
||||
</ComboBox>
|
||||
<TextField fx:id="txt_replacement" disable="true" GridPane.columnIndex="3">
|
||||
<ComboBox fx:id="cmb_side" maxWidth="1.7976931348623157E308" GridPane.columnIndex="3">
|
||||
<GridPane.margin>
|
||||
<Insets left="5.0" right="5.0" />
|
||||
</GridPane.margin>
|
||||
</ComboBox>
|
||||
</children>
|
||||
<GridPane.margin>
|
||||
<Insets right="10.0" />
|
||||
</GridPane.margin>
|
||||
</GridPane>
|
||||
<GridPane prefHeight="45.0" prefWidth="546.0" GridPane.rowIndex="1">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="153.0" minWidth="10.0" prefWidth="88.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="373.0" minWidth="10.0" prefWidth="366.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="1.7976931348623157E308" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="32.0" prefWidth="99.0" text="Replace with:" />
|
||||
<TextField fx:id="txt_replacement" disable="true" GridPane.columnIndex="1">
|
||||
<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" />
|
||||
<Insets bottom="10.0" right="10.0" />
|
||||
</GridPane.margin>
|
||||
</GridPane>
|
||||
</children>
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="39.0" prefHeight="47.0" />
|
||||
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="41.0" prefHeight="41.0" />
|
||||
</rowConstraints>
|
||||
<GridPane.margin>
|
||||
<Insets />
|
||||
</GridPane.margin>
|
||||
</GridPane>
|
||||
</content>
|
||||
</Tab>
|
||||
<Tab text="Block/replace value">
|
||||
<Button fx:id="btn_add" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#click_btnAddRule" text="Add" GridPane.columnIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="7.0" left="5.0" top="5.0" />
|
||||
</GridPane.margin>
|
||||
</Button>
|
||||
</children>
|
||||
<GridPane.margin>
|
||||
<Insets bottom="5.0" />
|
||||
</GridPane.margin>
|
||||
</GridPane>
|
||||
<ScrollPane fx:id="scrollpane" hbarPolicy="NEVER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-border-color: #888888; -fx-background: #FFFFFF; -fx-border-radius: 4px;" vbarPolicy="ALWAYS">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
|
||||
<VBox fx:id="schedulecontainer" maxHeight="1.7976931348623157E308" prefWidth="559.0">
|
||||
<children>
|
||||
<GridPane fx:id="header" gridLinesVisible="true">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="163.0" minWidth="10.0" percentWidth="12.0" prefWidth="57.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="190.0" minWidth="10.0" percentWidth="14.0" prefWidth="189.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="118.0" minWidth="10.0" percentWidth="18.0" prefWidth="66.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="33.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="15.0" prefWidth="100.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="10.0" percentWidth="6.0" prefWidth="100.0" />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<VBox.margin>
|
||||
<Insets bottom="-2.0" left="-2.0" right="-2.0" top="-2.0" />
|
||||
</VBox.margin>
|
||||
<children>
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-text-fill: #666666; -fx-background-color: #F7F7F7;" text="Option" />
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-text-fill: #666666; -fx-background-color: #F7F7F7;" text="Type" GridPane.columnIndex="1" />
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-text-fill: #666666; -fx-background-color: #F7F7F7;" text="Value" GridPane.columnIndex="2" />
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-text-fill: #666666; -fx-background-color: #F7F7F7;" text="Replacement" GridPane.columnIndex="3" />
|
||||
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-text-fill: #666666; -fx-background-color: #F7F7F7;" text="Destination" GridPane.columnIndex="4" />
|
||||
<Label alignment="CENTER" layoutX="564.0" layoutY="10.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" style="-fx-text-fill: #666666; -fx-background-color: #F7F7F7;" text=" " GridPane.columnIndex="5" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
</VBox>
|
||||
</content>
|
||||
</Tab>
|
||||
</tabs>
|
||||
</TabPane>
|
||||
<GridPane.margin>
|
||||
<Insets bottom="8.0" />
|
||||
</GridPane.margin>
|
||||
</ScrollPane>
|
||||
</children>
|
||||
<padding>
|
||||
<Insets left="17.0" right="17.0" top="17.0" />
|
||||
</padding>
|
||||
</GridPane>
|
||||
|
@ -0,0 +1,54 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class BlockPacketRule extends BlockReplaceRule{
|
||||
|
||||
private int headerId;
|
||||
private Side side;
|
||||
|
||||
BlockPacketRule(Side side, int headerId) {
|
||||
this.headerId = headerId;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Side.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Side.TOCLIENT && side ==Side.INCOMING)) {
|
||||
if (message.getPacket().headerId() == headerId) {
|
||||
message.setBlocked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return headerId+"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return "";
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public abstract class BlockReplaceRule {
|
||||
|
||||
public enum Option {
|
||||
BLOCK,
|
||||
REPLACE
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
PACKET,
|
||||
INTEGER,
|
||||
STRING,
|
||||
SUBSTRING
|
||||
}
|
||||
|
||||
public enum Side {
|
||||
INCOMING,
|
||||
OUTGOING,
|
||||
ALL
|
||||
}
|
||||
|
||||
|
||||
public abstract void appendRuleToMessage(HMessage message);
|
||||
|
||||
public abstract Option option();
|
||||
public abstract Type type();
|
||||
public abstract Side side();
|
||||
|
||||
public abstract String value();
|
||||
public abstract String replacement();
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ReplaceIntegerRule extends BlockReplaceRule {
|
||||
|
||||
Side side;
|
||||
int value;
|
||||
int replacement;
|
||||
|
||||
ReplaceIntegerRule(Side side, int value, int replacement) {
|
||||
this.side = side;
|
||||
this.value = value;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Side.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Side.TOCLIENT && side ==Side.INCOMING)) {
|
||||
message.getPacket().replaceAllIntegers(value, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.REPLACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.INTEGER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return value+"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return replacement+"";
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
/**
|
||||
* Created by Jeunez on 6/11/2018.
|
||||
*/
|
||||
public class ReplacePacketRule extends BlockReplaceRule {
|
||||
|
||||
private Side side;
|
||||
private int headerId;
|
||||
private HPacket replacement;
|
||||
|
||||
ReplacePacketRule(Side side, int headerId, HPacket replacement) {
|
||||
this.side = side;
|
||||
this.headerId = headerId;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Side.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Side.TOCLIENT && side ==Side.INCOMING)) {
|
||||
if (message.getPacket().headerId() == headerId) {
|
||||
message.getPacket().constructFromString(replacement.stringify());
|
||||
message.getPacket().overrideEditedField(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.REPLACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return headerId+"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return replacement.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ReplaceStringRule extends BlockReplaceRule {
|
||||
|
||||
private Side side;
|
||||
private String value;
|
||||
private String replacement;
|
||||
|
||||
ReplaceStringRule(Side side, String value, String replacement) {
|
||||
this.side = side;
|
||||
this.value = value;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Side.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Side.TOCLIENT && side ==Side.INCOMING)) {
|
||||
message.getPacket().replaceAllStrings(value, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.REPLACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return replacement;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HMessage;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class ReplaceSubstringRule extends BlockReplaceRule {
|
||||
|
||||
private Side side;
|
||||
private String value;
|
||||
private String replacement;
|
||||
|
||||
ReplaceSubstringRule(Side side, String value, String replacement) {
|
||||
this.side = side;
|
||||
this.value = value;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendRuleToMessage(HMessage message) {
|
||||
if (side == Side.ALL
|
||||
|| (message.getDestination() == HMessage.Side.TOSERVER && side == Side.OUTGOING)
|
||||
|| (message.getDestination() == HMessage.Side.TOCLIENT && side ==Side.INCOMING)) {
|
||||
message.getPacket().replaceAllSubstrings(value, replacement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Option option() {
|
||||
return Option.REPLACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return Type.SUBSTRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side side() {
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String replacement() {
|
||||
return replacement;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package extensions.blockreplacepackets.rules;
|
||||
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 6/11/2018.
|
||||
*/
|
||||
public class RuleFactory {
|
||||
|
||||
public static BlockReplaceRule getRule(String type, String side, String value, String replacement) {
|
||||
BlockReplaceRule.Option rOption = BlockReplaceRule.Option.valueOf(type.split(" ")[0].toUpperCase());
|
||||
BlockReplaceRule.Type rType = BlockReplaceRule.Type.valueOf(type.split(" ")[1].toUpperCase());
|
||||
BlockReplaceRule.Side rSide = BlockReplaceRule.Side.valueOf(type.toUpperCase());
|
||||
|
||||
if (rOption == BlockReplaceRule.Option.BLOCK) {
|
||||
return new BlockPacketRule(rSide, Integer.parseInt(value));
|
||||
}
|
||||
if (rOption == BlockReplaceRule.Option.REPLACE) {
|
||||
if (rType == BlockReplaceRule.Type.INTEGER) {
|
||||
return new ReplaceIntegerRule(rSide, Integer.parseInt(value), Integer.parseInt(replacement));
|
||||
}
|
||||
if (rType == BlockReplaceRule.Type.PACKET) {
|
||||
return new ReplacePacketRule(rSide, Integer.parseInt(value), new HPacket(replacement));
|
||||
}
|
||||
if (rType == BlockReplaceRule.Type.STRING) {
|
||||
return new ReplaceStringRule(rSide, value, replacement);
|
||||
}
|
||||
if (rType == BlockReplaceRule.Type.SUBSTRING) {
|
||||
return new ReplaceSubstringRule(rSide, value, replacement);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -186,10 +186,10 @@ public abstract class Extension {
|
||||
}
|
||||
|
||||
for(MessageListener listener : correctListeners) {
|
||||
habboMessage.getPacket().setReadIndex(6);
|
||||
habboMessage.getPacket().resetReadIndex();
|
||||
listener.act(habboMessage);
|
||||
}
|
||||
habboMessage.getPacket().setReadIndex(6);
|
||||
habboMessage.getPacket().resetReadIndex();
|
||||
|
||||
HPacket response = new HPacket(Extensions.INCOMING_MESSAGES_IDS.MANIPULATEDPACKET);
|
||||
response.appendLongString(habboMessage.stringify());
|
||||
|
@ -58,7 +58,7 @@ public abstract class ExtensionForm extends Application {
|
||||
extension.run();
|
||||
// Platform.runLater(primaryStage::close);
|
||||
//when the extension has ended, close this process
|
||||
Platform.exit();
|
||||
System.exit(0);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
@ -99,6 +99,7 @@ public abstract class ExtensionForm extends Application {
|
||||
private void onClick(){
|
||||
Platform.runLater(() -> {
|
||||
primaryStage.show();
|
||||
primaryStage.toFront();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -446,20 +446,79 @@ public class HPacket implements StringifyAble {
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean canReadString(int index) {
|
||||
if (index < packetInBytes.length - 1) {
|
||||
int l = readUshort(index);
|
||||
if (index + 1 + l < packetInBytes.length) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//returns if done r not
|
||||
public boolean replaceFirstString(String oldS, String newS) {
|
||||
public HPacket replaceFirstString(String oldS, String newS) {
|
||||
return replaceXStrings(oldS, newS, 1);
|
||||
}
|
||||
public HPacket replaceXStrings(String oldS, String newS, int amount) {
|
||||
if (amount == 0) return this;
|
||||
|
||||
int i = 6;
|
||||
while (i < packetInBytes.length - 1 - oldS.length()) {
|
||||
if (readUshort(i) == oldS.length() && readString(i).equals(oldS)) {
|
||||
replaceString(i, newS);
|
||||
return true;
|
||||
i += 1 + newS.length();
|
||||
amount -= 1;
|
||||
if (amount == 0) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return false;
|
||||
return this;
|
||||
}
|
||||
public HPacket replaceAllStrings(String oldS, String newS) {
|
||||
return replaceXStrings(oldS, newS, -1);
|
||||
}
|
||||
|
||||
public HPacket replaceFirstSubstring(String oldS, String newS) {
|
||||
return replaceXSubstrings(oldS, newS, 1);
|
||||
}
|
||||
public HPacket replaceXSubstrings(String oldS, String newS, int amount) {
|
||||
if (amount == 0) {
|
||||
return this;
|
||||
}
|
||||
int i = 6;
|
||||
while (i < packetInBytes.length - 1 - oldS.length()) {
|
||||
if (canReadString(i)) {
|
||||
String s = readString(i);
|
||||
if (s.contains(oldS)) {
|
||||
String replacement = s.replaceAll(oldS, newS);
|
||||
replaceString(i, replacement);
|
||||
i += 1 + replacement.length();
|
||||
amount -= 1;
|
||||
if (amount == 0) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public HPacket replaceAllSubstrings(String oldS, String newS) {
|
||||
return replaceXSubstrings(oldS, newS, -1);
|
||||
}
|
||||
|
||||
public HPacket replaceAllIntegers(int val, int replacement) {
|
||||
int i = 6;
|
||||
while (i < packetInBytes.length - 3) {
|
||||
if (readInteger(i) == val) {
|
||||
replaceInt(i, replacement);
|
||||
i += 3;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
public HPacket replaceAllString(String oldS, String newS) {
|
||||
while (replaceFirstString(oldS, newS)) {}
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -551,6 +610,9 @@ public class HPacket implements StringifyAble {
|
||||
isEdited = remember;
|
||||
}
|
||||
|
||||
public void overrideEditedField(boolean edited) {
|
||||
isEdited = edited;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns "" if not found or not sure enough
|
||||
@ -845,9 +907,9 @@ public class HPacket implements StringifyAble {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
HPacket packet = new HPacket("{l}{u:1442}");
|
||||
HPacket packet = new HPacket("{l}{u:1442}{i:5}{i:4}{i:80015}{s:goiazdq}{s:samen spelen is tof}{b:false}{i:4}{s:spelletjes spelen}");
|
||||
|
||||
System.out.println(packet.structureEquals("s,b"));
|
||||
System.out.println(packet.replaceAllSubstrings("spelen", "ownen").replaceAllIntegers(4, 45664868).toExpression());
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user