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