1 19 20 package jode.obfuscator; 21 import jode.bytecode.ClassInfo; 22 import jode.bytecode.SearchPath; 23 import jode.GlobalOptions; 24 25 import gnu.getopt.LongOpt; 26 import gnu.getopt.Getopt; 27 28 import java.lang.reflect.Modifier ; 29 import java.io.PrintWriter ; 30 import java.io.FileReader ; 31 import java.io.InputStreamReader ; 32 import java.io.IOException ; 33 import java.util.Collections ; 34 import java.util.Random ; 35 36 public class Main { 37 public static boolean swapOrder = false; 38 39 public static final int OPTION_STRONGOVERLOAD = 0x0001; 40 public static final int OPTION_PRESERVESERIAL = 0x0002; 41 public static int options = OPTION_PRESERVESERIAL; 42 43 private static final LongOpt[] longOptions = new LongOpt[] { 44 new LongOpt("cp", LongOpt.REQUIRED_ARGUMENT, null, 'c'), 45 new LongOpt("classpath", LongOpt.REQUIRED_ARGUMENT, null, 'c'), 46 new LongOpt("destpath", LongOpt.REQUIRED_ARGUMENT, null, 'd'), 47 new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'), 48 new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V'), 49 new LongOpt("verbose", LongOpt.OPTIONAL_ARGUMENT, null, 'v'), 50 new LongOpt("debug", LongOpt.OPTIONAL_ARGUMENT, null, 'D'), 51 }; 52 53 public static final String [] stripNames = { 54 "unreach", "inner", "lvt", "lnt", "source" 55 }; 56 public static final int STRIP_UNREACH = 0x0001; 57 public static final int STRIP_INNERINFO = 0x0002; 58 public static final int STRIP_LVT = 0x0004; 59 public static final int STRIP_LNT = 0x0008; 60 public static final int STRIP_SOURCE = 0x0010; 61 public static int stripping = 0; 62 69 public static Random rand = new Random (123456); 70 71 private static ClassBundle bundle; 72 73 public static void usage() { 74 PrintWriter err = GlobalOptions.err; 75 err.println("usage: jode.Obfuscator flags* script"); 76 err.println(" -h, --help "+ 77 "show this information."); 78 err.println(" -V, --version "+ 79 "output version information and exit."); 80 err.println(" -v, --verbose "+ 81 "be verbose (multiple times means more verbose)."); 82 err.println(" -c, --classpath <path> "+ 83 "search for classes in specified classpath."); 84 err.println(" "+ 85 "The directories should be separated by ','."); 86 err.println(" -d, --dest <dir> "+ 87 "write decompiled files to disk into directory destdir."); 88 err.println(" -D, --debug=... "+ 89 "use --debug=help for more information."); 90 } 91 92 93 public static ClassBundle getClassBundle() { 94 return bundle; 95 } 96 97 public static void main(String [] params) { 98 if (params.length == 0) { 99 usage(); 100 return; 101 } 102 String cp = null, dest = null; 103 104 GlobalOptions.err.println(GlobalOptions.copyright); 105 bundle = new ClassBundle(); 106 boolean errorInParams = false; 107 Getopt g = new Getopt("jode.obfuscator.Main", params, "hVvc:d:D:", 108 longOptions, true); 109 for (int opt = g.getopt(); opt != -1; opt = g.getopt()) { 110 switch(opt) { 111 case 0: 112 break; 113 case 'h': 114 usage(); 115 errorInParams = true; 116 break; 117 case 'V': 118 GlobalOptions.err.println(GlobalOptions.version); 119 break; 120 case 'c': 121 cp = g.getOptarg(); 122 break; 123 case 'd': 124 dest = g.getOptarg(); 125 break; 126 case 'v': { 127 String arg = g.getOptarg(); 128 if (arg == null) 129 GlobalOptions.verboseLevel++; 130 else { 131 try { 132 GlobalOptions.verboseLevel = Integer.parseInt(arg); 133 } catch (NumberFormatException ex) { 134 GlobalOptions.err.println 135 ("jode.obfuscator.Main: Argument `" 136 +arg+"' to --verbose must be numeric:"); 137 errorInParams = true; 138 } 139 } 140 break; 141 } 142 case 'D': { 143 String arg = g.getOptarg(); 144 if (arg == null) 145 arg = "help"; 146 errorInParams |= !GlobalOptions.setDebugging(arg); 147 break; 148 } 149 default: 150 errorInParams = true; 151 break; 152 } 153 } 154 if (errorInParams) 155 return; 156 157 if (g.getOptind() != params.length - 1) { 158 GlobalOptions.err.println("You must specify exactly one script."); 159 return; 160 } 161 162 163 try { 164 String filename = params[g.getOptind()]; 165 ScriptParser parser = new ScriptParser 166 (filename.equals("-") 167 ? new InputStreamReader (System.in) 168 : new FileReader (filename)); 169 parser.parseOptions(bundle); 170 } catch (IOException ex) { 171 GlobalOptions.err.println 172 ("IOException while reading script file."); 173 ex.printStackTrace(GlobalOptions.err); 174 return; 175 } catch (ParseException ex) { 176 GlobalOptions.err.println("Syntax error in script file: "); 177 GlobalOptions.err.println(ex.getMessage()); 178 if (GlobalOptions.verboseLevel > 5) 179 ex.printStackTrace(GlobalOptions.err); 180 return; 181 } 182 183 if (cp != null) 185 bundle.setOption("classpath", Collections.singleton(cp)); 186 if (dest != null) 187 bundle.setOption("dest", Collections.singleton(dest)); 188 189 bundle.run(); 190 } 191 } 192 193 | Popular Tags |