soot.jbco.Main Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of soot Show documentation
Show all versions of soot Show documentation
A Java Optimization Framework
package soot.jbco;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 1999 Raja Vallee-Rai
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import soot.Local;
import soot.Pack;
import soot.PackManager;
import soot.SootClass;
import soot.SootMethod;
import soot.Transform;
import soot.Transformer;
import soot.jbco.bafTransformations.AddJSRs;
import soot.jbco.bafTransformations.BAFCounter;
import soot.jbco.bafTransformations.BAFPrintout;
import soot.jbco.bafTransformations.BafLineNumberer;
import soot.jbco.bafTransformations.ConstructorConfuser;
import soot.jbco.bafTransformations.FindDuplicateSequences;
import soot.jbco.bafTransformations.FixUndefinedLocals;
import soot.jbco.bafTransformations.IfNullToTryCatch;
import soot.jbco.bafTransformations.IndirectIfJumpsToCaughtGotos;
import soot.jbco.bafTransformations.Jimple2BafLocalBuilder;
import soot.jbco.bafTransformations.LocalsToBitField;
import soot.jbco.bafTransformations.MoveLoadsAboveIfs;
import soot.jbco.bafTransformations.RemoveRedundantPushStores;
import soot.jbco.bafTransformations.TryCatchCombiner;
import soot.jbco.bafTransformations.UpdateConstantsToFields;
import soot.jbco.bafTransformations.WrapSwitchesInTrys;
import soot.jbco.jimpleTransformations.AddSwitches;
import soot.jbco.jimpleTransformations.ArithmeticTransformer;
import soot.jbco.jimpleTransformations.BuildIntermediateAppClasses;
import soot.jbco.jimpleTransformations.ClassRenamer;
import soot.jbco.jimpleTransformations.CollectConstants;
import soot.jbco.jimpleTransformations.CollectJimpleLocals;
import soot.jbco.jimpleTransformations.FieldRenamer;
import soot.jbco.jimpleTransformations.GotoInstrumenter;
import soot.jbco.jimpleTransformations.LibraryMethodWrappersBuilder;
import soot.jbco.jimpleTransformations.MethodRenamer;
/**
* @author Michael Batchelder
*
* Created on 24-Jan-2006
*/
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
public static boolean jbcoDebug = false;
public static boolean jbcoSummary = true;
public static boolean jbcoVerbose = false;
public static boolean metrics = false;
public static Map transformsToWeights = new ConcurrentHashMap<>();
public static Map> transformsToMethodsToWeights = new ConcurrentHashMap<>();
public static Map method2Locals2REALTypes = new ConcurrentHashMap();
public static Map> methods2Baf2JLocals = new ConcurrentHashMap<>();
public static Map> methods2JLocals = new ConcurrentHashMap<>();
public static List IntermediateAppClasses = new CopyOnWriteArrayList<>();
static List jbcotransforms = new CopyOnWriteArrayList<>();
static String[][] optionStrings = new String[][] {
{ "Rename Classes", "Rename Methods", "Rename Fields", "Build API Buffer Methods", "Build Library Buffer Classes",
"Goto Instruction Augmentation", "Add Dead Switche Statements", "Convert Arith. Expr. To Bitshifting Ops",
"Convert Branches to JSR Instructions", "Disobey Constructor Conventions", "Reuse Duplicate Sequences",
"Replace If(Non)Nulls with Try-Catch", "Indirect If Instructions", "Pack Locals into Bitfields",
"Reorder Loads Above Ifs", "Combine Try and Catch Blocks", "Embed Constants in Fields",
"Partially Trap Switches" },
{ "wjtp.jbco_cr", "wjtp.jbco_mr", "wjtp.jbco_fr", "wjtp.jbco_blbc", "wjtp.jbco_bapibm", "jtp.jbco_gia",
"jtp.jbco_adss", "jtp.jbco_cae2bo", "bb.jbco_cb2ji", "bb.jbco_dcc", "bb.jbco_rds", "bb.jbco_riitcb", "bb.jbco_iii",
"bb.jbco_plvb", "bb.jbco_rlaii", "bb.jbco_ctbcb", "bb.jbco_ecvf", "bb.jbco_ptss" } };
public static void main(String[] argv) {
int rcount = 0;
Vector transformsToAdd = new Vector();
boolean remove[] = new boolean[argv.length];
for (int i = 0; i < argv.length; i++) {
String arg = argv[i];
if (arg.equals("-jbco:help")) {
System.out.println("The Java Bytecode Obfuscator (JBCO)\n\nGeneral Options:");
System.out.println("\t-jbco:help - print this help message.");
System.out.println("\t-jbco:verbose - print extra information during obfuscation.");
System.out.println("\t-jbco:silent - turn off all output, including summary information.");
System.out.println("\t-jbco:metrics - calculate total vertices and edges;\n"
+ "\t calculate avg. and highest graph degrees.");
System.out.println("\t-jbco:debug - turn on extra debugging like\n"
+ "\t stack height and type verifier.\n\nTransformations ( -t:[W:][:pattern] )\n"
+ "\tW - specify obfuscation weight (0-9)\n"
+ "\t - name of obfuscation (from list below)\n"
+ "\tpattern - limit to method names matched by pattern\n"
+ "\t prepend * to pattern if a regex\n");
for (int j = 0; j < optionStrings[0].length; j++) {
String line = "\t" + optionStrings[1][j];
int size = 20 - line.length();
while (size-- > 0) {
line += " ";
}
line += "- " + optionStrings[0][j];
System.out.println(line);
}
System.exit(0);
} else if (arg.equals("-jbco:metrics")) {
metrics = true;
remove[i] = true;
rcount++;
} // temp dumby arg to printout name of benchmark for output files
else if (arg.startsWith("-jbco:name:")) {
remove[i] = true;
rcount++;
} // dumby dumby dumby
else if (arg.startsWith("-t:")) {
arg = arg.substring(3);
int tweight = 9;
char cweight = arg.charAt(0);
if (cweight >= '0' && cweight <= '9') {
try {
tweight = Integer.parseInt(arg.substring(0, 1));
} catch (NumberFormatException nfe) {
logger.debug("Improperly formated transformation weight: " + argv[i]);
System.exit(1);
}
arg = arg.substring(arg.indexOf(':') + 1);
}
transformsToAdd.add(arg);
transformsToWeights.put(arg, new Integer(tweight));
if (arg.equals("wjtp.jbco_fr")) {
FieldRenamer.rename_fields = true;
}
remove[i] = true;
rcount++;
} else if (arg.equals("-jbco:verbose")) {
jbcoVerbose = true;
remove[i] = true;
rcount++;
} else if (arg.equals("-jbco:silent")) {
jbcoSummary = false;
jbcoVerbose = false;
remove[i] = true;
rcount++;
} else if (arg.equals("-jbco:debug")) {
jbcoDebug = true;
remove[i] = true;
rcount++;
} else if (arg.startsWith("-i") && arg.length() > 4 && arg.charAt(3) == ':' && arg.charAt(2) == 't') {
Object o = null;
arg = arg.substring(4);
int tweight = 9;
char cweight = arg.charAt(0);
if (cweight >= '0' && cweight <= '9') {
try {
tweight = Integer.parseInt(arg.substring(0, 1));
} catch (NumberFormatException nfe) {
logger.debug("Improperly formatted transformation weight: " + argv[i]);
System.exit(1);
}
if (arg.indexOf(':') < 0) {
logger.debug("Illegally Formatted Option: " + argv[i]);
System.exit(1);
}
arg = arg.substring(arg.indexOf(':') + 1);
}
int index = arg.indexOf(':');
if (index < 0) {
logger.debug("Illegally Formatted Option: " + argv[i]);
System.exit(1);
}
String trans = arg.substring(0, index);
arg = arg.substring(index + 1, arg.length());
if (arg.startsWith("*")) {
arg = arg.substring(1);
try {
o = java.util.regex.Pattern.compile(arg);
} catch (java.util.regex.PatternSyntaxException pse) {
logger.debug("Illegal Regular Expression Pattern: " + arg);
System.exit(1);
}
} else {
o = arg;
}
transformsToAdd.add(trans);
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy