use of soot.dava.toolkits.base.AST.transformations.SimplifyExpressions in project soot by Sable.
the class InterProceduralAnalyses method applyInterProceduralAnalyses.
/*
* Method is invoked by postProcessDava in PackManager
* if the transformations flag is true
*
* All interproceduralAnalyses should be applied in here
*/
public static void applyInterProceduralAnalyses() {
Chain classes = Scene.v().getApplicationClasses();
if (DEBUG)
System.out.println("\n\nInvoking redundantFielduseEliminator");
ConstantFieldValueFinder finder = new ConstantFieldValueFinder(classes);
HashMap<String, Object> constantValueFields = finder.getFieldsWithConstantValues();
if (DEBUG)
finder.printConstantValueFields();
/*
* The code above this gathers interprocedural information
* the code below this USES the interprocedural results
*/
Iterator it = classes.iterator();
while (it.hasNext()) {
// go though all the methods
SootClass s = (SootClass) it.next();
Iterator methodIt = s.methodIterator();
while (methodIt.hasNext()) {
SootMethod m = (SootMethod) methodIt.next();
/*
* Adding try block to handle RuntimeException no active body found
*/
DavaBody body = null;
if (m.hasActiveBody()) {
body = (DavaBody) m.getActiveBody();
} else {
continue;
}
ASTNode AST = (ASTNode) body.getUnits().getFirst();
if (!(AST instanceof ASTMethodNode))
continue;
Map options = PhaseOptions.v().getPhaseOptions("db.deobfuscate");
boolean deobfuscate = PhaseOptions.getBoolean(options, "enabled");
// System.out.println("force is "+force);
if (deobfuscate) {
if (DEBUG)
System.out.println("\nSTART CP Class:" + s.getName() + " Method: " + m.getName());
CPApplication CPApp = new CPApplication((ASTMethodNode) AST, constantValueFields, finder.getClassNameFieldNameToSootFieldMapping());
AST.apply(CPApp);
if (DEBUG)
System.out.println("DONE CP for " + m.getName());
}
// expression simplification
// SimplifyExpressions.DEBUG=true;
AST.apply(new SimplifyExpressions());
// SimplifyConditions.DEBUG=true;
AST.apply(new SimplifyConditions());
// condition elimination
// EliminateConditions.DEBUG=true;
AST.apply(new EliminateConditions((ASTMethodNode) AST));
// the above should ALWAYS be followed by an unreachable code eliminator
AST.apply(new UnreachableCodeEliminator(AST));
// local variable cleanup
AST.apply(new LocalVariableCleaner(AST));
// VERY EXPENSIVE STAGE of redoing all analyses!!!!
if (deobfuscate) {
if (DEBUG)
System.out.println("reinvoking analyzeAST");
UselessLabelFinder.DEBUG = false;
body.analyzeAST();
}
// renaming should be applied as the last stage
options = PhaseOptions.v().getPhaseOptions("db.renamer");
boolean renamer = PhaseOptions.getBoolean(options, "enabled");
// System.out.println("renaming is"+renamer);
if (renamer) {
applyRenamerAnalyses(AST, body);
}
// remove returns from void methods
VoidReturnRemover.cleanClass(s);
}
}
}
Aggregations