Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SVFA implementation #20

Open
wants to merge 46 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
221893d
fix: add value line in to string
Nov 3, 2022
ae2b31a
Merge branch 'rbonifacio:develop' into develop
galilasmb Mar 1, 2023
42608f1
fix: add config to ignore resolution errors from soot
May 24, 2023
328bd75
Merge branch 'rbonifacio:develop' into develop
galilasmb May 24, 2023
8886ead
feat: print depth methods visited and number of methods
May 31, 2023
c8834fb
fix: add edge to fields
Jun 7, 2023
2878d85
fix: adjusting algorithm
Jun 8, 2023
a26b50b
fix: adjusting field algoritms
Jun 12, 2023
b2c1bc1
fix: adjusting to casting
Jun 12, 2023
0558e55
fix: adjusting build.sbt
Jun 12, 2023
0858a27
refactoring: removing entryPointMethod
Jun 12, 2023
a87af2d
fix: adjusting algorithm
Jun 13, 2023
b978fa0
fix: adjusting pattern match
Jun 13, 2023
10aa6d2
fix: adjuting report number of conflicts
Jun 13, 2023
3795e47
refact: removing unused variables
Jun 13, 2023
7dd5569
refact: add field number line
Jun 15, 2023
8289f69
tests: adjusting tests
Jun 15, 2023
fe0f476
fix: add fields in allocationSites
Jun 15, 2023
2b13647
fix: adjusting load and store algorithm
Jun 16, 2023
56cb7a5
fix: adjusting algoritm
Jun 22, 2023
b1ad049
tests: new tests
Jun 22, 2023
b087045
fix: removing used code
Jun 22, 2023
102df9b
fix: removing used code
Jun 22, 2023
df5a213
fix: removing used code
Jun 22, 2023
00a38e4
tests: add more tests
Jun 22, 2023
d7d2e82
feat: add flag enableAllocationSiteDF
Jun 23, 2023
f4ec53b
fix: create assignStatements field
Jun 26, 2023
cf3bf95
refact: renaming variable
Jun 26, 2023
2307d67
refact: removing unsed methods
Jun 26, 2023
713419a
error: adjusting
Jun 26, 2023
a435da2
fix: adjusting tests and fixing algoritm
Jun 27, 2023
77296f7
tests: add more tests with integer
Jun 27, 2023
759eab6
fix: adjusting depth limit to 10
Jul 5, 2023
97fc372
fix: adjusting and refactoring
Jul 10, 2023
ec5f787
refact: renaming variable
Jul 10, 2023
392a128
feat: add call to InstanceInvokeExpr with an AssignStmt
Jul 11, 2023
847c738
fix: adjusting total visited methods
Jul 13, 2023
ec0fcb7
fix: updating allocation site before
Jul 13, 2023
b0a15af
adding visited methods in the node graph
Aug 15, 2023
d82467a
udpating svfa
Sep 22, 2023
c8362c3
adjusting path visited method
Sep 22, 2023
a32a1d2
add use field algorithm
Nov 13, 2023
e0a67f3
fix: adjusting patern matching
Nov 29, 2023
583c1ca
feat: add support for java 9 or higher
barbosamaatheus May 30, 2024
77756a9
feat: add support for java 9 or higher
barbosamaatheus May 30, 2024
915798a
Merge pull request #1 from barbosamaatheus/testing_fields_svfa
galilasmb May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ project/plugins/project/
# Scala-IDE specific
.scala_dependencies
.worksheet
.idea
.idea
.gradle/
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ scalaVersion := "2.12.8"
name := "svfa-scala"
organization := "br.unb.cic"

version := "0.2.1-SNAPSHOT"
version := "0.5.9"

githubOwner := "rbonifacio"
githubOwner := "galilasmb"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alterar isso para o de Rodrigo.

githubRepository := "svfa-scala"
githubTokenSource := TokenSource.GitConfig("github.token")

Expand Down
66 changes: 56 additions & 10 deletions src/main/scala/br/unb/cic/soot/graph/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import scalax.collection.edge.LkDiEdge
import soot.SootMethod

import scala.collection.immutable.HashSet
import scala.collection.mutable.ListBuffer

/*
* This trait define the base type for node classifications.
Expand All @@ -27,6 +28,16 @@ trait GraphNode {
def unit(): soot.Unit
def method(): soot.SootMethod
def show(): String
def line(): Int
def pathVisitedMethods: ListBuffer[VisitedMethods]
def pathVisitedMethodsToString(): String = {
var methodsString = ""

if (pathVisitedMethods != null){
methodsString = pathVisitedMethods.map(_. toString).mkString(" => ")
}
s"path: $methodsString"
}
}

trait LambdaNode extends scala.AnyRef {
Expand All @@ -44,24 +55,39 @@ trait LambdaNode extends scala.AnyRef {
*/
case class Statement(className: String, method: String, stmt: String, line: Int, sootUnit: soot.Unit = null, sootMethod: soot.SootMethod = null)

case class VisitedMethods(sootMethod: soot.SootMethod = null, sootUnit: soot.Unit = null, line: Int) {
override def toString: String = s"($sootMethod, $sootUnit, $line)"
def getMethod = sootMethod
def getUnit = sootUnit
def getLine = line
}

/*
* A graph node defined using the GraphNode abstraction specific for statements.
* Use this class as example to define your own custom nodes.
*/
case class StatementNode(value: Statement, nodeType: NodeType) extends GraphNode {
case class StatementNode(value: Statement, nodeType: NodeType, pathVisitedMethods: ListBuffer[VisitedMethods]) extends GraphNode {
type T = Statement

// override def show(): String = "(" ++ value.method + ": " + value.stmt + " - " + value.line + " <" + nodeType.toString + ">)"
override def show(): String = value.stmt
def getPathVisitedMethods() = pathVisitedMethods

override def pathVisitedMethodsToString(): String = {
var methodsString = ""

if (pathVisitedMethods != null){
methodsString = pathVisitedMethods.map(_. toString).mkString(" => ")
}
s"path: $methodsString"
}

override def show(): String = "(" ++ value.method + ": " + value.stmt + " - " + value.line + " <" + nodeType.toString + ">)"

override def toString: String =
"Node(" + value.method + "," + value.stmt + "," + "," + nodeType.toString + ")"
"Node(" + value.method + "," + value.stmt + "," + value.line+ "," + nodeType.toString + ", "+pathVisitedMethodsToString+")"

override def equals(o: Any): Boolean = {
o match {
// case stmt: StatementNode => stmt.value.toString == value.toString
// case stmt: StatementNode => stmt.value == value && stmt.nodeType == nodeType
case stmt: StatementNode => stmt.value.className.equals(value.className) &&
case stmt: StatementNode => stmt.value.className.equals(value.className) &&
stmt.value.method.equals(value.method) &&
stmt.value.stmt.equals(value.stmt) &&
stmt.value.line.equals(value.line) &&
Expand All @@ -75,6 +101,8 @@ case class StatementNode(value: Statement, nodeType: NodeType) extends GraphNode
override def unit(): soot.Unit = value.sootUnit

override def method(): SootMethod = value.sootMethod

override def line(): Int = value.line
}

/*
Expand Down Expand Up @@ -164,6 +192,7 @@ class Graph() {
permitedReturnEdge = true
}


def gNode(outerNode: GraphNode): graph.NodeT = graph.get(outerNode)
def gEdge(outerEdge: LkDiEdge[GraphNode]): graph.EdgeT = graph.get(outerEdge)

Expand Down Expand Up @@ -445,13 +474,27 @@ class Graph() {
/*
* creates a graph node from a sootMethod / sootUnit
*/
def createNode(method: SootMethod, stmt: soot.Unit, f: (soot.Unit) => NodeType): StatementNode =
def createNode(method: SootMethod, stmt: soot.Unit, f: (soot.Unit) => NodeType, pathVisitedMethods: ListBuffer[VisitedMethods]): StatementNode =
StatementNode(br.unb.cic.soot.graph.Statement(method.getDeclaringClass.toString, method.getSignature, stmt.toString,
stmt.getJavaSourceStartLineNumber, stmt, method), f(stmt))
stmt.getJavaSourceStartLineNumber, stmt, method), f(stmt), pathVisitedMethods)

def reportConflicts(): scala.collection.Set[String] =
findConflictingPaths().map(p => p.toString)

def reportConflitcsMessage() = {
val conflicts = findConflictingPaths()
conflicts.foreach( conflict =>{
val h = conflict.head
val l = conflict.last
val p1 = conflict.head
val p2 = conflict.last
println("DF interference in class "+p1.method().getDeclaringClass+", method "+ p1.pathVisitedMethods.head.sootMethod.getName)
println("Execution of line "+p1.pathVisitedMethods.head.line+" to "+p2.pathVisitedMethods.head.line+" defined in "+h.unit()+" and propagated in "+l.unit())
println("Caused by line "+p1.pathVisitedMethods.head.line+ " flow: "+p1.pathVisitedMethodsToString())
println("Caused by line "+p2.pathVisitedMethods.head.line+ " flow: "+p2.pathVisitedMethodsToString())
})
}

def findConflictingPaths(): scala.collection.Set[List[GraphNode]] = {
if (fullGraph) {
val conflicts = findPathsFullGraph()
Expand All @@ -464,7 +507,10 @@ class Graph() {
sourceNodes.foreach(source => {
sinkNodes.foreach(sink => {
val paths = findPath(source, sink)
conflicts = conflicts ++ paths
val pathsHaveSameSourceAndSinkRootTraversedLine: Boolean = conflicts.exists(c => paths.exists(p => c.head.line() == p.head.line() && c.last.line() == p.last.line()))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignorar caminhos repetidos com mesma origem e destino.

if (!pathsHaveSameSourceAndSinkRootTraversedLine){
conflicts = conflicts ++ paths
}
})
})
conflicts.filter(p => p.nonEmpty).toSet
Expand Down
21 changes: 19 additions & 2 deletions src/main/scala/br/unb/cic/soot/svfa/SootConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ abstract class SootConfiguration {
Options.v().set_allow_phantom_refs(true)
Options.v().set_include(getIncludeList().asJava);
Options.v().set_output_format(Options.output_format_none)

if (getJavaVersion < 9) {
Options.v.set_prepend_classpath(true)
Options.v().set_soot_classpath(sootClassPath() + File.pathSeparator + pathToJCE() + File.pathSeparator + pathToRT())
}
else if (getJavaVersion >= 9) {
Options.v.set_soot_classpath(sootClassPath())
}

Options.v().set_whole_program(true)
Options.v().set_soot_classpath(sootClassPath() + File.pathSeparator + pathToJCE() + File.pathSeparator + pathToRT())
Options.v().set_process_dir(applicationClassPath().asJava)
Options.v().set_full_resolver(true)
Options.v().set_keep_line_number(true)
Options.v().set_prepend_classpath(true)
Options.v().setPhaseOption("jb", "use-original-names:true")
Options.v().set_ignore_resolution_errors(true);
configureCallGraphPhase()

Scene.v().loadNecessaryClasses()
Expand Down Expand Up @@ -77,4 +85,13 @@ abstract class SootConfiguration {
def pathToRT(): String =
System.getProperty("java.home") + File.separator + "lib" + File.separator + "rt.jar"

private def getJavaVersion = {
var version = System.getProperty("java.version")
if (version.startsWith("1.")) version = version.substring(2, 3)
else {
val dot = version.indexOf(".")
if (dot != -1) version = version.substring(0, dot)
}
version.toInt
}
}
10 changes: 10 additions & 0 deletions src/main/scala/br/unb/cic/soot/svfa/jimple/AnalysisDepth.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package br.unb.cic.soot.svfa.jimple

trait AnalysisDepth {
def maxDepth(): Int = 0
def isLimited(): Boolean= maxDepth() > 0
}

trait StandardLimitedAnalysis extends AnalysisDepth {
override def maxDepth(): Int = 10
}
Loading