Example #1
0
  /**
   * Obfuscates the file
   *
   * @throws IOException
   * @throws org.gradle.api.InvalidUserDataException if the there is insufficient information
   *     available to generate the signature.
   */
  void generate(ReobfExceptor exc, File srg) throws IOException {
    File toObf = getToObf();
    if (toObf == null) {
      throw new InvalidUserDataException(
          "Unable to obfuscate as the file to obfuscate has not been specified");
    }

    File output = getFile();
    File excepted = new File(caller.getTemporaryDir(), "excepted.jar");
    Files.copy(toObf, excepted);

    // copy input somewhere else...
    if (exc != null) {
      exc.toReobfJar = toObf;
      exc.buildSrg();
      srg = exc.outSrg;

      // append SRG
      BufferedWriter writer = new BufferedWriter(new FileWriter(srg, true));
      for (String line : caller.getExtraSrg()) {
        writer.write(line);
        writer.newLine();
      }
      writer.flush();
      writer.close();
    }

    // obfuscate!
    if (caller.getUseRetroGuard()) applyRetroGuard(excepted, output, srg);
    else applySpecialSource(excepted, output, srg);
  }
Example #2
0
  private void applyRetroGuard(File input, File output, File srg) throws IOException {
    File cfg = new File(caller.getTemporaryDir(), "retroguard.cfg");
    generateRgConfig(cfg, input, output, srg);

    String[] args = new String[] {"-notch", cfg.getCanonicalPath()};

    NameProvider.parseCommandLine(args);
  }
Example #3
0
  private void generateRgConfig(File config, File in, File out, File srg) throws IOException {
    String log = new File(caller.getTemporaryDir(), "retroguard.log").getCanonicalPath();
    File script = new File(caller.getTemporaryDir(), "retroguard.script");

    // the config
    String[] lines =
        new String[] {
          "reobinput = " + in.getCanonicalPath(),
          "reoboutput = " + out.getCanonicalPath(),
          "reobf = " + srg.getCanonicalPath(),
          "script = " + script.getCanonicalPath(),
          "log = " + log,
          "verbose = 0",
          "quiet = 1",
          "fullmap = 0",
          "startindex = 0",
          "protectedpackage = paulscode",
          "protectedpackage = com",
          "protectedpackage = isom",
          "protectedpackage = ibxm",
          "protectedpackage = de/matthiasmann/twl",
          "protectedpackage = org",
          "protectedpackage = javax",
          "protectedpackage = argo",
          "protectedpackage = gnu",
          "protectedpackage = io/netty"
        };

    Files.write(Joiner.on(Constants.NEWLINE).join(lines), config, Charset.defaultCharset());

    // the script.
    lines =
        new String[] {
          ".option Application",
          ".option Applet",
          ".option Repackage",
          ".option Annotations",
          ".option MapClassString",
          ".attribute LineNumberTable",
          ".attribute EnclosingMethod",
          ".attribute Deprecated"
        };

    Files.write(Joiner.on(Constants.NEWLINE).join(lines), script, Charset.defaultCharset());
  }