use of soot.dava.toolkits.base.AST.transformations.LocalVariableCleaner 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);
}
}
}
use of soot.dava.toolkits.base.AST.transformations.LocalVariableCleaner in project soot by Sable.
the class DavaBody method applyStructuralAnalyses.
private void applyStructuralAnalyses(ASTNode AST) {
// TESTING REACHING DEFS
// ReachingDefs defs = new ReachingDefs(AST);
// AST.apply(new tester(true,defs));
// TESTING REACHING COPIES
// ReachingCopies copies = new ReachingCopies(AST);
// AST.apply(new tester(true,copies));
// TESTING ASTUSESANDDEFS
// AST.apply(new ASTUsesAndDefs(AST));
/*
* Structural flow analyses.....
*/
// CopyPropagation.DEBUG=true;
debug("applyStructureAnalyses", "invoking copy propagation");
CopyPropagation prop = new CopyPropagation(AST);
AST.apply(prop);
debug("applyStructureAnalyses", "invoking copy propagation DONE");
// copy propagation should be followed by LocalVariableCleaner to get max effect
// ASTUsesAndDefs.DEBUG=true;
debug("applyStructureAnalyses", "Local Variable Cleaner started");
AST.apply(new LocalVariableCleaner(AST));
debug("applyStructureAnalyses", "Local Variable Cleaner DONE");
}
Aggregations