Use GlobalOptions.

new flag syntax


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@676 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent e5c541bb00
commit 912b7bf041
  1. 126
      jode/jode/obfuscator/Main.java

@ -25,14 +25,10 @@ import java.lang.reflect.Modifier;
import java.io.PrintStream;
public class Obfuscator {
public static int verboseLevel = 0;
public static boolean isDebugging = false;
public static boolean shouldStrip = true;
public static boolean swapOrder = false;
public static boolean preserveSerial = true;
public static PrintStream err = System.err;
public static final int PRESERVE_NONE = 0;
public static final int PRESERVE_PUBLIC = Modifier.PUBLIC;
public static final int PRESERVE_PROTECTED =
@ -44,46 +40,55 @@ public class Obfuscator {
public static final int RENAME_WEAK = 1;
public static final int RENAME_UNIQUE = 2;
public static final int RENAME_NONE = 3;
public static final int RENAME_TABLE = 4;
public static void usage() {
PrintStream err = GlobalOptions.err;
err.println("usage: jode.Obfuscator flags* [class | package]*");
err.println("\t[-v] "+
err.println("\t-v "+
"Verbose output (allowed multiple times).");
err.println("\t[-debug] "+"Debugging");
err.println("\t[-nostrip] "+
err.println("\t--nostrip "+
"Don't strip not needed methods");
err.println("\t[-cp <classpath>] "+
err.println("\t--cp <classpath> "+
"The class path; should contain classes.zip");
err.println("\t[-d <directory>] "+
err.println("\t-d,--dest <directory> "+
"Destination directory for output classes");
err.println("Preserve options: ");
err.println("\t[-package] "+
err.println("\t--package "+
"Preserve all package members");
err.println("\t[-protected] "+
err.println("\t--protected "+
"Preserve all protected members");
err.println("\t[-public] "+
err.println("\t--public "+
"Preserve all public members");
err.println("\t[-preserve <name>] "+
err.println("\t--preserve <name> "+
"Preserve only the given name (allowed multiple times)");
err.println("\t[-breakserial] "+
err.println("\t--breakserial "+
"Allow the serialized form to change");
err.println("Obfuscating options: ");
err.println("\t[-strong] "+
"Rename identifiers to random unicode identifier");
err.println("\t[-weak] "+
"Rename to random, but legal java identifier");
err.println("\t[-unique] "+
"Rename to unique legal java identifier");
err.println("\t[-none] "+
"Don't rename any method.");
err.println("\t[-table <file>] "+
err.println("\t--rename={strong|weak|unique|none} "+
"Rename identifiers with given scheme");
err.println("\t--table <file> "+
"Read (some) translation table from file");
err.println("\t[-revtable <file>] "+
err.println("\t--revtable <file> "+
"Write reversed translation table to file");
err.println("\t[-swaporder] "+
err.println("\t--swaporder "+
"Swap the order of fields and methods.");
err.println("\t--debug=... "+
"use --debug=help for more information.");
}
public static int parseRenameOption(String option) {
if (option.equals("strong"))
return RENAME_STRONG;
else if (option.equals("--weak"))
return RENAME_WEAK;
else if (option.equals("--unique"))
return RENAME_UNIQUE;
else if (option.equals("--none"))
return RENAME_NONE;
usage();
System.exit(0);
return 0;
}
public static void main(String[] params) {
@ -100,86 +105,91 @@ public class Obfuscator {
for (i=0; i<params.length && params[i].startsWith("-"); i++) {
if (params[i].equals("-v"))
verboseLevel++;
else if (params[i].equals("-debug"))
isDebugging = true;
else if (params[i].equals("-nostrip"))
GlobalOptions.verboseLevel++;
else if (params[i].startsWith("--debug")) {
String flags;
if (params[i].startsWith("--debug=")) {
flags = params[i].substring(8);
} else if (params[i].length() != 7) {
usage();
return;
} else {
flags = params[++i];
}
GlobalOptions.setDebugging(flags);
} else if (params[i].equals("--nostrip"))
shouldStrip = false;
else if (params[i].equals("-sourcepath")
|| params[i].equals("-classpath")
|| params[i].equals("-cp"))
else if (params[i].equals("--sourcepath")
|| params[i].equals("--classpath")
|| params[i].equals("--cp"))
sourcePath = params[++i];
else if (params[i].equals("-dest")
else if (params[i].equals("--dest")
|| params[i].equals("-d"))
destPath = params[++i];
/* Preserve options */
else if (params[i].equals("-package"))
else if (params[i].equals("--package"))
preserveRule = PRESERVE_PACKAGE;
else if (params[i].equals("-protected"))
else if (params[i].equals("--protected"))
preserveRule = PRESERVE_PROTECTED;
else if (params[i].equals("-public"))
else if (params[i].equals("--public"))
preserveRule = PRESERVE_PUBLIC;
else if (params[i].equals("-preserve")) {
else if (params[i].equals("--preserve")) {
String ident = params[++i];
preservedIdents.addElement(ident);
}
else if (params[i].equals("-breakserial"))
else if (params[i].equals("--breakserial"))
preserveSerial = false;
/* Obfuscate options */
else if (params[i].equals("-strong"))
rename = RENAME_STRONG;
else if (params[i].equals("-weak"))
rename = RENAME_WEAK;
else if (params[i].equals("-unique"))
rename = RENAME_UNIQUE;
else if (params[i].equals("-none"))
rename = RENAME_NONE;
else if (params[i].equals("-table")) {
else if (params[i].equals("--rename"))
rename = parseRenameOption(params[++i]);
else if (params[i].startsWith("--rename="))
rename = parseRenameOption(params[i].substring(9));
else if (params[i].equals("--table")) {
table = params[++i];
}
else if (params[i].equals("-revtable")) {
else if (params[i].equals("--revtable")) {
toTable = params[++i];
}
else if (params[i].equals("-swaporder"))
else if (params[i].equals("--swaporder"))
swapOrder = true;
else if (params[i].equals("--")) {
i++;
break;
} else {
if (!params[i].startsWith("-h"))
err.println("Unknown option: "+params[i]);
if (!params[i].equals("-h") && !params[i].equals("--help"))
GlobalOptions.err.println("Unknown option: "+params[i]);
usage();
return;
}
}
if (i == params.length) {
err.println("No package or classes specified.");
GlobalOptions.err.println("No package or classes specified.");
usage();
return;
}
err.println("Loading classes");
GlobalOptions.err.println("Loading classes");
ClassInfo.setClassPath(sourcePath);
ClassBundle bundle = new ClassBundle();
for (; i< params.length; i++)
bundle.loadClasses(params[i]);
err.println("Computing reachable / preserved settings");
GlobalOptions.err.println("Computing reachable / preserved settings");
bundle.setPreserved(preserveRule, preservedIdents);
err.println("Renaming methods");
GlobalOptions.err.println("Renaming methods");
if (table != null)
bundle.readTable(table);
bundle.buildTable(rename);
if (toTable != null)
bundle.writeTable(toTable);
err.println("Transforming the classes");
GlobalOptions.err.println("Transforming the classes");
bundle.doTransformations();
err.println("Writing new classes");
GlobalOptions.err.println("Writing new classes");
bundle.storeClasses(destPath);
}
}

Loading…
Cancel
Save