From 2dac69577962139b1d0763aa1c97f2812329f414 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 12 Feb 1999 16:10:54 +0000 Subject: [PATCH] new swap order option git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@279 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/obfuscator/ClassIdentifier.java | 21 +++++++++++ jode/jode/obfuscator/Main.java | 45 +++++++++++++---------- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/jode/jode/obfuscator/ClassIdentifier.java b/jode/jode/obfuscator/ClassIdentifier.java index 2e45de2..e815f2c 100644 --- a/jode/jode/obfuscator/ClassIdentifier.java +++ b/jode/jode/obfuscator/ClassIdentifier.java @@ -172,6 +172,27 @@ public class ClassIdentifier extends Identifier { FieldInfo[] finfos = info.getFields(); MethodInfo[] minfos = info.getMethods(); + if (Obfuscator.swapOrder) { + Random rand = new Random(); + for (int i=1; i < finfos.length; i++) { + int j = (Math.abs(rand.nextInt()) % (i+1)); + // XXX replace with nextInt(i+1) for JDK12. + if (j != i) { + FieldInfo tmp = finfos[i]; + finfos[i] = finfos[j]; + finfos[j] = tmp; + } + } + for (int i=1; i < minfos.length; i++) { + int j = (Math.abs(rand.nextInt()) % (i+1)); + // XXX replace with nextInt(i+1) for JDK12. + if (j != i) { + MethodInfo tmp = minfos[i]; + minfos[i] = minfos[j]; + minfos[j] = tmp; + } + } + } fieldCount = finfos.length; identifiers = new Identifier[finfos.length + minfos.length]; for (int i=0; i< fieldCount; i++) { diff --git a/jode/jode/obfuscator/Main.java b/jode/jode/obfuscator/Main.java index e63de49..fd0a16c 100644 --- a/jode/jode/obfuscator/Main.java +++ b/jode/jode/obfuscator/Main.java @@ -28,6 +28,7 @@ public class Obfuscator { public static boolean isDebugging = false; public static boolean shouldStrip = true; + public static boolean swapOrder = false; public static PrintStream err = System.err; public static final int PRESERVE_NONE = 0; @@ -44,38 +45,40 @@ public class Obfuscator { public static final int RENAME_TABLE = 4; public static void usage() { - Obfuscator.err.println("usage: jode.Obfuscator flags* [class | package]*"); - Obfuscator.err.println("\t[-v] "+"Verbose output"); - Obfuscator.err.println("\t[-debug] "+"Debugging"); - Obfuscator.err.println("\t[-nostrip] "+ + err.println("usage: jode.Obfuscator flags* [class | package]*"); + err.println("\t[-v] "+"Verbose output"); + err.println("\t[-debug] "+"Debugging"); + err.println("\t[-nostrip] "+ "Don't strip not needed methods"); - Obfuscator.err.println("\t[-cp ] "+ + err.println("\t[-cp ] "+ "The class path; should contain classes.zip"); - Obfuscator.err.println("\t[-d ] "+ + err.println("\t[-d ] "+ "Destination directory for output classes"); - Obfuscator.err.println("Preserve options: "); - Obfuscator.err.println("\t[-package] "+ + err.println("Preserve options: "); + err.println("\t[-package] "+ "Preserve all package members"); - Obfuscator.err.println("\t[-protected] "+ + err.println("\t[-protected] "+ "Preserve all protected members"); - Obfuscator.err.println("\t[-public] "+ + err.println("\t[-public] "+ "Preserve all public members"); - Obfuscator.err.println("\t[-preserve ] "+ + err.println("\t[-preserve ] "+ "Preserve only the given name (allowed multiple times)"); - Obfuscator.err.println("Obfuscating options: "); - Obfuscator.err.println("\t[-strong] "+ + err.println("Obfuscating options: "); + err.println("\t[-strong] "+ "Rename identifiers to random unicode identifier"); - Obfuscator.err.println("\t[-weak] "+ + err.println("\t[-weak] "+ "Rename to random, but legal java identifier"); - Obfuscator.err.println("\t[-unique] "+ + err.println("\t[-unique] "+ "Rename to unique legal java identifier"); - Obfuscator.err.println("\t[-none] "+ + err.println("\t[-none] "+ "Don't rename any method."); - Obfuscator.err.println("\t[-table ] "+ + err.println("\t[-table ] "+ "Read translation table from file"); - Obfuscator.err.println("\t[-revtable ] "+ + err.println("\t[-revtable ] "+ "Write reversed translation table to file"); + err.println("\t[-swaporder] "+ + "Swap the order of fields and methods."); } public static void main(String[] params) { @@ -133,18 +136,20 @@ public class Obfuscator { else if (params[i].equals("-revtable")) { toTable = params[++i]; } + else if (params[i].equals("-swaporder")) + swapOrder = true; else if (params[i].equals("--")) { i++; break; } else { if (!params[i].startsWith("-h")) - Obfuscator.err.println("Unknown option: "+params[i]); + err.println("Unknown option: "+params[i]); usage(); return; } } if (i == params.length) { - Obfuscator.err.println("No package or classes specified."); + err.println("No package or classes specified."); usage(); return; }