From c9728df9d60aa08f3337ebc0488fcca0d92b8f66 Mon Sep 17 00:00:00 2001 From: Eduardo Alonso Date: Mon, 31 Dec 2018 14:12:52 +0100 Subject: [PATCH] Add support to send multiple packets at once in injection * Each line represents a packet Signed-off-by: Eduardo Alonso --- .../java/gearth/ui/injection/Injection.java | 51 +++++++++++++------ .../gearth/ui/injection/Injection.fxml | 1 + 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/G-Earth/src/main/java/gearth/ui/injection/Injection.java b/G-Earth/src/main/java/gearth/ui/injection/Injection.java index 9dea343..7952e80 100644 --- a/G-Earth/src/main/java/gearth/ui/injection/Injection.java +++ b/G-Earth/src/main/java/gearth/ui/injection/Injection.java @@ -25,19 +25,32 @@ public class Injection extends SubForm { } private void updateUI() { - HPacket packet = new HPacket(inputPacket.getText()); - if (!packet.isCorrupted()) { - lbl_corrruption.setText("isCorrupted: False"); - lbl_corrruption.setFill(Paint.valueOf("Green")); - lbl_pcktInfo.setText("header (id:"+packet.headerId()+", length:"+packet.length()+")"); + boolean dirty = false; + String[] rawPackets = inputPacket.getText().split("\n"); + HPacket[] packets = new HPacket[rawPackets.length]; + lbl_corrruption.setText("isCorrupted: False"); + lbl_corrruption.setFill(Paint.valueOf("Green")); + + for (int i = 0; i < packets.length; i++) { + packets[i] = new HPacket(rawPackets[i]); + if (packets[i].isCorrupted()) { + if (!dirty) { + lbl_corrruption.setText("isCorrupted: True -> " + i); + lbl_corrruption.setFill(Paint.valueOf("#ee0404b2")); + dirty = true; + } else + lbl_corrruption.setText(lbl_corrruption.getText() + ", " + i); + } + } + + if (!dirty) { btn_sendToClient.setDisable(getHConnection().getState() != HConnection.State.CONNECTED); btn_sendToServer.setDisable(getHConnection().getState() != HConnection.State.CONNECTED); - } - else { - lbl_corrruption.setText("isCorrupted: True"); - lbl_corrruption.setFill(Paint.valueOf("#ee0404b2")); - lbl_pcktInfo.setText("header (id:NULL, length:"+packet.getBytesLength()+")"); + lbl_pcktInfo.setText("header (id:" + packets[packets.length - 1].headerId() + ", length:" + + packets[packets.length - 1].length() + ")"); + } else { + lbl_pcktInfo.setText("header (id:NULL, length:" + packets[packets.length - 1].getBytesLength()+")"); btn_sendToClient.setDisable(true); btn_sendToServer.setDisable(true); @@ -46,14 +59,20 @@ public class Injection extends SubForm { } public void sendToServer_clicked(ActionEvent actionEvent) { - HPacket packet = new HPacket(inputPacket.getText()); - getHConnection().sendToServerAsync(packet); - writeToLog(Color.BLUE, "SS -> packet with id: " + packet.headerId()); + String[] rawPackets = inputPacket.getText().split("\n"); + for (String rawPacket : rawPackets) { + HPacket packet = new HPacket(rawPacket); + getHConnection().sendToServerAsync(packet); + writeToLog(Color.BLUE, "SS -> packet with id: " + packet.headerId()); + } } public void sendToClient_clicked(ActionEvent actionEvent) { - HPacket packet = new HPacket(inputPacket.getText()); - getHConnection().sendToClientAsync(packet); - writeToLog(Color.RED, "CS -> packet with id: " + packet.headerId()); + String[] rawPackets = inputPacket.getText().split("\n"); + for (String rawPacket : rawPackets) { + HPacket packet = new HPacket(rawPacket); + getHConnection().sendToClientAsync(packet); + writeToLog(Color.RED, "CS -> packet with id: " + packet.headerId()); + } } } diff --git a/G-Earth/src/main/resources/gearth/ui/injection/Injection.fxml b/G-Earth/src/main/resources/gearth/ui/injection/Injection.fxml index c1e3dfd..cd58ec6 100644 --- a/G-Earth/src/main/resources/gearth/ui/injection/Injection.fxml +++ b/G-Earth/src/main/resources/gearth/ui/injection/Injection.fxml @@ -9,6 +9,7 @@ +