preserveSerial added

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@280 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 2dac695779
commit 44fe5feb29
  1. 19
      jode/jode/obfuscator/ClassIdentifier.java
  2. 31
      jode/jode/obfuscator/Main.java

@ -106,8 +106,18 @@ public class ClassIdentifier extends Identifier {
* a compatible class. * a compatible class.
*/ */
public void preserveSerializable() { public void preserveSerializable() {
/*XXX*/ preserveIdentifier("writeObject", "(Ljava.io.ObjectOutputStream)V");
/* add a field serializableVersionUID if not existent */ preserveIdentifier("readObject", "(Ljava.io.ObjectOutputStream)V");
if (Obfuscator.preserveSerial) {
/* XXX - add a field serializableVersionUID if not existent */
preserveIdentifier("serializableVersionUID", "I");
for (int i=0; i < fieldCount; i++) {
FieldIdentifier ident = (FieldIdentifier) identifiers[i];
if ((ident.info.getModifiers()
& (Modifier.TRANSIENT | Modifier.STATIC)) == 0)
identifiers[i].setPreserved();
}
}
} }
public void initSuperClasses(ClassInfo superclass) { public void initSuperClasses(ClassInfo superclass) {
@ -174,9 +184,11 @@ public class ClassIdentifier extends Identifier {
MethodInfo[] minfos = info.getMethods(); MethodInfo[] minfos = info.getMethods();
if (Obfuscator.swapOrder) { if (Obfuscator.swapOrder) {
Random rand = new Random(); Random rand = new Random();
// XXX replace the following for JDK12 with:
// Collections.shuffle(Arrays.asList(finfos), rand);
// Collections.shuffle(Arrays.asList(minfos), rand);
for (int i=1; i < finfos.length; i++) { for (int i=1; i < finfos.length; i++) {
int j = (Math.abs(rand.nextInt()) % (i+1)); int j = (Math.abs(rand.nextInt()) % (i+1));
// XXX replace with nextInt(i+1) for JDK12.
if (j != i) { if (j != i) {
FieldInfo tmp = finfos[i]; FieldInfo tmp = finfos[i];
finfos[i] = finfos[j]; finfos[i] = finfos[j];
@ -185,7 +197,6 @@ public class ClassIdentifier extends Identifier {
} }
for (int i=1; i < minfos.length; i++) { for (int i=1; i < minfos.length; i++) {
int j = (Math.abs(rand.nextInt()) % (i+1)); int j = (Math.abs(rand.nextInt()) % (i+1));
// XXX replace with nextInt(i+1) for JDK12.
if (j != i) { if (j != i) {
MethodInfo tmp = minfos[i]; MethodInfo tmp = minfos[i];
minfos[i] = minfos[j]; minfos[i] = minfos[j];

@ -29,6 +29,7 @@ public class Obfuscator {
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 PrintStream err = System.err; public static PrintStream err = System.err;
public static final int PRESERVE_NONE = 0; public static final int PRESERVE_NONE = 0;
@ -49,36 +50,38 @@ public class Obfuscator {
err.println("\t[-v] "+"Verbose output"); err.println("\t[-v] "+"Verbose output");
err.println("\t[-debug] "+"Debugging"); 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 <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] "+
"Allow the serialized form to change");
err.println("Obfuscating options: "); err.println("Obfuscating options: ");
err.println("\t[-strong] "+ err.println("\t[-strong] "+
"Rename identifiers to random unicode identifier"); "Rename identifiers to random unicode identifier");
err.println("\t[-weak] "+ err.println("\t[-weak] "+
"Rename to random, but legal java identifier"); "Rename to random, but legal java identifier");
err.println("\t[-unique] "+ err.println("\t[-unique] "+
"Rename to unique legal java identifier"); "Rename to unique legal java identifier");
err.println("\t[-none] "+ err.println("\t[-none] "+
"Don't rename any method."); "Don't rename any method.");
err.println("\t[-table <file>] "+ err.println("\t[-table <file>] "+
"Read translation table from file"); "Read 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.");
} }
public static void main(String[] params) { public static void main(String[] params) {
@ -119,6 +122,8 @@ public class Obfuscator {
String ident = params[++i]; String ident = params[++i];
preservedIdents.addElement(ident); preservedIdents.addElement(ident);
} }
else if (params[i].equals("-breakserial"))
preserveSerial = false;
/* Obfuscate options */ /* Obfuscate options */
else if (params[i].equals("-strong")) else if (params[i].equals("-strong"))

Loading…
Cancel
Save