Skip to content

Commit

Permalink
feat(spgroup#31): add Interprocedural Override Assignment Analysis to…
Browse files Browse the repository at this point in the history
… main
  • Loading branch information
barbosamaatheus committed Dec 9, 2020
1 parent 8121522 commit 3cdf69c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 37 deletions.
92 changes: 62 additions & 30 deletions src/main/java/br/unb/cic/analysis/Main.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
package br.unb.cic.analysis;

import java.io.File;
import java.io.FileWriter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.Map.Entry;

import br.unb.cic.analysis.df.*;
import br.unb.cic.analysis.io.DefaultReader;
import br.unb.cic.analysis.io.MergeConflictReader;
import br.unb.cic.analysis.ioa.InterproceduralOverrideAssignment;
import br.unb.cic.analysis.model.Statement;
import br.unb.cic.analysis.reachability.ReachabilityAnalysis;
import br.unb.cic.analysis.svfa.SVFAAnalysis;
import br.unb.cic.analysis.svfa.SVFAInterProcedural;
import br.unb.cic.analysis.svfa.SVFAIntraProcedural;
import br.unb.cic.analysis.svfa.confluence.SVFAConfluenceAnalysis;
import br.unb.cic.diffclass.DiffClass;
import org.apache.commons.cli.*;

import scala.collection.JavaConverters;
import soot.Body;
import soot.BodyTransformer;
import soot.PackManager;
import soot.Transform;

import br.unb.cic.analysis.io.DefaultReader;
import br.unb.cic.analysis.io.MergeConflictReader;
import br.unb.cic.analysis.model.Statement;
import br.unb.cic.analysis.reachability.ReachabilityAnalysis;
import br.unb.cic.diffclass.DiffClass;
import java.io.File;
import java.io.FileWriter;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

public class Main {

Expand Down Expand Up @@ -149,13 +147,27 @@ private void createOptions() {

private void runAnalysis(String mode, String classpath) {
switch(mode) {
case "svfa-interprocedural" : runSparseValueFlowAnalysis(classpath, true); break;
case "svfa-intraprocedural" : runSparseValueFlowAnalysis(classpath, false); break;
case "svfa-confluence-interprocedural": runSparseValueFlowConfluenceAnalysis(classpath, true); break;
case "svfa-confluence-intraprocedural": runSparseValueFlowConfluenceAnalysis(classpath, false); break;
case "reachability" : runReachabilityAnalysis(classpath); break;
default : runDataFlowAnalysis(classpath, mode);
}
case "svfa-interprocedural":
runSparseValueFlowAnalysis(classpath, true);
break;
case "svfa-intraprocedural":
runSparseValueFlowAnalysis(classpath, false);
break;
case "svfa-confluence-interprocedural":
runSparseValueFlowConfluenceAnalysis(classpath, true);
break;
case "svfa-confluence-intraprocedural":
runSparseValueFlowConfluenceAnalysis(classpath, false);
break;
case "reachability":
runReachabilityAnalysis(classpath);
break;
case "overriding-interprocedural":
runInterproceduralOverrideAssignmentAnalysis(classpath);
break;
default:
runDataFlowAnalysis(classpath, mode);
}
}

private void runDataFlowAnalysis(String classpath, String mode) {
Expand All @@ -167,8 +179,12 @@ protected void internalTransform(Body body, String phaseName, Map<String, String
case "dataflow" : analysis = new ReachDefinitionAnalysis(body, definition); break;
case "tainted" : analysis = new TaintedAnalysis(body, definition);
case "confluence" : analysis = new ConfluentAnalysis(body, definition); break;
case "confluence-tainted": analysis = new ConfluentTaintedAnalysis(body, definition); break;
case "overriding" : analysis = new OverridingAssignmentAnalysis(body, definition); break;
case "confluence-tainted":
analysis = new ConfluentTaintedAnalysis(body, definition);
break;
case "overriding":
analysis = new OverridingAssignmentAnalysis(body, definition);
break;
default: {
System.out.println("Error: " + "invalid mode " + mode);
System.exit(-1);
Expand All @@ -177,25 +193,41 @@ protected void internalTransform(Body body, String phaseName, Map<String, String
}
}));
SootWrapper.builder()
.withClassPath(classpath)
.addClass(targetClasses.stream().collect(Collectors.joining(" ")))
.build()
.execute();
.withClassPath(classpath)
.addClass(targetClasses.stream().collect(Collectors.joining(" ")))
.build()
.execute();
if (analysis != null) {
conflicts.addAll(analysis.getConflicts().stream().map(c -> c.toString()).collect(Collectors.toList()));
}
}

private void runInterproceduralOverrideAssignmentAnalysis(String classpath) {
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);

PackManager.v().getPack("wjtp").add(new Transform("wjtp.analysis", analysis));
soot.options.Options.v().setPhaseOption("cg.spark", "on");
soot.options.Options.v().setPhaseOption("cg.spark", "verbose:true");

SootWrapper.builder()
.withClassPath(classpath)
.addClass(targetClasses.stream().collect(Collectors.joining(" ")))
.build()
.execute();

conflicts.addAll(analysis.getConflicts().stream().map(c -> c.toString()).collect(Collectors.toList()));
}

/*
* After discussing this algorithm with the researchers at
* UFPE, we decided that we should not support this analysis
* any more. It might lead to a huge number of false-positives.
*/
@Deprecated
private void runReachabilityAnalysis(String classpath) {
ReachabilityAnalysis analysis = new ReachabilityAnalysis(definition);
PackManager.v().getPack("wjtp").add(new Transform("wjtp.analysis", analysis));
ReachabilityAnalysis analysis = new ReachabilityAnalysis(definition);

PackManager.v().getPack("wjtp").add(new Transform("wjtp.analysis", analysis));
soot.options.Options.v().setPhaseOption("cg.spark", "on");
soot.options.Options.v().setPhaseOption("cg.spark", "verbose:true");

Expand All @@ -204,7 +236,7 @@ private void runReachabilityAnalysis(String classpath) {
.addClass(targetClasses.stream().collect(Collectors.joining(" ")))
.build()
.execute();

conflicts.addAll(analysis.getConflicts().stream().map(c -> c.toString()).collect(Collectors.toList()));
}

Expand Down
9 changes: 2 additions & 7 deletions src/main/java/br/unb/cic/analysis/svfa/SVFAAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

import br.unb.cic.analysis.AbstractMergeConflictDefinition;
import br.unb.cic.analysis.model.Statement;

import br.unb.cic.soot.graph.*;
import br.unb.cic.soot.svfa.jimple.JSVFA;
import scala.collection.JavaConverters;
import soot.SootMethod;
import soot.Unit;

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -74,7 +69,7 @@ public final scala.collection.immutable.List<SootMethod> getEntryPoints() {
definition.loadSinkStatements();
return JavaConverters.asScalaBuffer(getSourceStatements()
.stream()
.map(stmt -> stmt.getSootMethod())
.map(Statement::getSootMethod)
.collect(Collectors.toList())).toList();
}

Expand Down

0 comments on commit 3cdf69c

Please sign in to comment.