Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Scala CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'

- name: Cache SBT
uses: actions/cache@v3
with:
path: |
~/.ivy2/cache
~/.sbt
key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt') }}
restore-keys: |
${{ runner.os }}-sbt-

- name: Run sbt tests
run: sbt test
23 changes: 6 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,31 @@ scalaVersion := "2.12.8"
name := "pdg-sdg"
organization := "br.ufpe.cin"

version := "0.7.0"
version := "0.4.41"

githubOwner := "spgroup"
githubRepository := "pdg-sdg"
githubTokenSource := TokenSource.GitConfig("github.token")

parallelExecution in Test := false

resolvers += "soot snapshots" at "https://soot-build.cs.uni-paderborn.de/nexus/repository/soot-snapshot/"

resolvers += "soot releases" at "https://soot-build.cs.uni-paderborn.de/nexus/repository/soot-release/"

resolvers += "Maven Central" at "https://repo1.maven.org/maven2/"
resolvers += "SPG Maven Repository" at "https://maven.pkg.github.com/spgroup/soot/"
resolvers += "SVFA releases" at "https://maven.pkg.github.com/spgroup/svfa-scala/"
resolvers += "Local maven repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"

resolvers += Classpaths.typesafeReleases

resolvers += "SVFA releases" at "https://maven.pkg.github.com/galilasmb/svfa-scala/"

libraryDependencies += "org.typelevel" %% "cats-core" % "1.6.0"

libraryDependencies += "ca.mcgill.sable" % "soot" % "3.3.0"
libraryDependencies += "org.soot-oss" % "soot" % "4.5.1"
libraryDependencies += "com.google.guava" % "guava" % "27.1-jre"
libraryDependencies += "org.scala-graph" %% "graph-core" % "1.13.0"

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"

libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2"

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"

libraryDependencies += "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided"

libraryDependencies += "javax.servlet" % "servlet-api" % "2.5" % "provided"

libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"

libraryDependencies += "br.unb.cic" % "svfa-scala_2.12" % "0.7.0"
libraryDependencies += "br.unb.cic" % "svfa-scala_2.12" % "0.5.13"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Po que tá usando essa versão?


parallelExecution in Test := false
12 changes: 7 additions & 5 deletions src/main/scala/br/ufpe/cin/soot/analysis/jimple/JDFP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package br.ufpe.cin.soot.analysis.jimple

import br.unb.cic.soot.graph.VisitedMethods
import br.unb.cic.soot.svfa.jimple.{AssignStmt, InvalidStmt, InvokeStmt, JSVFA, Statement}
import soot.PackManager
import soot.{Local, PackManager, Scene, SceneTransformer, SootMethod, Transform}
import soot.jimple._
import soot.toolkits.graph.ExceptionalUnitGraph
import soot.toolkits.scalar.SimpleLocalDefs
import soot.{Local, Scene, SceneTransformer, SootMethod, Transform}

import java.io.{FileWriter, IOException}
import java.text.{DecimalFormat, NumberFormat}
import java.util
import scala.collection.convert.ImplicitConversions.`collection asJava`
import scala.collection.mutable.ListBuffer


Expand Down Expand Up @@ -46,7 +44,7 @@ abstract class JDFP extends JSVFA{
class TransformerDFP extends SceneTransformer {
override def internalTransform(phaseName: String, options: util.Map[String, String]): scala.Unit = {
pointsToAnalysis = Scene.v().getPointsToAnalysis
Scene.v().getEntryPoints.forEach(method => {
getAnalysisEntryPoint().forEach(method => {
traverseDFP(method, new ListBuffer[VisitedMethods]())
methods = methods + 1
})
Expand Down Expand Up @@ -132,6 +130,10 @@ abstract class JDFP extends JSVFA{
val stmt = base.asInstanceOf[soot.jimple.ReturnStmt]
}

def getAnalysisEntryPoint(): util.List[SootMethod] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Esse método foi feito pra usar em classes posteriores com overriden?

Scene.v().getEntryPoints
}


def traverse(stmt: ReturnStmt, method: SootMethod, defs: SimpleLocalDefs, visitedMethods: ListBuffer[VisitedMethods]) : scala.Unit = {
val op = stmt.stmt.getUseBoxes
Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/br/ufpe/cin/soot/graph/LocalDummy.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ public class LocalDummy implements Local, ConvertToBaf {
public LocalDummy(String name, Type type) {
setName(name);
setType(type);
Numberer<Local> numberer = Scene.v().getLocalNumberer();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Por que removeu isso? Isso é usado pra criar um dos nós do grafo de PDG e PDG. A exemplo, START e STOP.

Copy link
Collaborator

Choose a reason for hiding this comment

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

if (numberer != null) {
numberer.add(this);
}
}

/** Returns true if the given object is structurally equal to this one. */
Expand Down Expand Up @@ -78,6 +74,11 @@ public void setType(Type t) {
this.type = t;
}

@Override
public boolean isStackLocal() {
return true;
}

@Override
public String toString() {
return getName();
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/samples/PointerAnalysis/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package samples.PointerAnalysis;

public class Main {
public static void main(String[] ars) {
Report r = new ReportAdvanced();
Text t = new Text(r);
t.generateReport();
}
}
11 changes: 11 additions & 0 deletions src/test/java/samples/PointerAnalysis/Report.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package samples.PointerAnalysis;

public interface Report {


void countDupWords();

void countDupWhiteSpace();

void countComments();
}
21 changes: 21 additions & 0 deletions src/test/java/samples/PointerAnalysis/ReportAdvanced.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package samples.PointerAnalysis;

public class ReportAdvanced implements Report {
int fixes = 0;

@Override
public void countDupWords() {
fixes++;
}

@Override
public void countDupWhiteSpace() {
int count = fixes;
//fixes = count;
}

@Override
public void countComments() {

}
}
23 changes: 23 additions & 0 deletions src/test/java/samples/PointerAnalysis/ReportSimple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package samples.PointerAnalysis;

public class ReportSimple implements Report {
int dupWords = 0;
int dupWhiteSpace = 0;

@Override
public void countDupWords() {
dupWords++;
}

@Override
public void countDupWhiteSpace() {
dupWhiteSpace++;
}

@Override
public void countComments() {

}


}
15 changes: 15 additions & 0 deletions src/test/java/samples/PointerAnalysis/Text.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package samples.PointerAnalysis;

public class Text {
private Report r;
Text(Report r) {
this.r = r;
}
void generateReport() {
r = new ReportSimple();
//Text t = new Text(report);
r.countDupWords(); // LEFT
r.countComments();
r.countDupWhiteSpace(); // RIGHT
}
}
6 changes: 6 additions & 0 deletions src/test/scala/br/ufpe/cin/soot/DFPTest.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package br.ufpe.cin.soot

import br.unb.cic.soot.graph.{NodeType, SimpleNode, SinkNode, SourceNode}
import br.unb.cic.soot.svfa.{CG, CHA, SPARK}
import soot.SootMethod

class DFPTest(leftchangedlines: Array[Int], rightchangedlines: Array[Int], className: String, mainMethod: String) extends JDFPTest {
override def getClassName(): String = className
override def getMainMethod(): String = mainMethod

override def callGraph(): CG = SPARK



// override def getClassName(): String = "samples.BlackBoard"
// override def getMainMethod(): String = "main"

Expand Down
58 changes: 57 additions & 1 deletion src/test/scala/br/ufpe/cin/soot/JDFPTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import br.ufpe.cin.soot.analysis.jimple.JDFP
import br.unb.cic.soot.svfa.jimple.{FieldSensitive, Interprocedural, PropagateTaint}
import soot.{Scene, SootMethod}

import java.util
import scala.collection.JavaConverters.collectionAsScalaIterableConverter

abstract class JDFPTest extends JDFP with Interprocedural with FieldSensitive with PropagateTaint{
def getClassName(): String
def getMainMethod(): String
Expand All @@ -13,12 +16,65 @@ abstract class JDFPTest extends JDFP with Interprocedural with FieldSensitive w
override def applicationClassPath(): List[String] = List("target/scala-2.12/test-classes", System.getProperty("user.home")+"/.m2/repository/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar")

override def getEntryPoints(): List[SootMethod] = {
var mainMethods: List[SootMethod] = findMainMethods()
if (mainMethods.isEmpty) {
mainMethods = findPublicMethods()
}
mainMethods
}

override def getAnalysisEntryPoint(): util.List[SootMethod] = {
val sootClass = Scene.v().getSootClass(getClassName())
List(sootClass.getMethodByName(getMainMethod()))
val method = sootClass.getMethodByName(getMainMethod())
val entryPoints = new util.ArrayList[SootMethod]()
entryPoints.add(method)
entryPoints
}

override def getIncludeList(): List[String] = List(
// "java.lang.*",
// "java.util.*"
)


def findMainMethods(): List[SootMethod] = {
val mainMethods = new util.ArrayList[SootMethod]()

val classes = Scene.v().getApplicationClasses
val it = classes.iterator()
while (it.hasNext) {
val sootClass = it.next()
for (method <- sootClass.getMethods.asScala) {
if (isMainMethod(method)) {
mainMethods.add(method)
}
}
}

mainMethods.asScala.toList
}

private def isMainMethod(method: SootMethod): Boolean = {
method.getName == "main" &&
method.isStatic &&
method.getReturnType.toString == "void" &&
method.getParameterCount == 1 &&
method.getParameterType(0).toString == "java.lang.String[]"
}

def findPublicMethods(): List[SootMethod] = {
val publicMethods = new util.ArrayList[SootMethod]()

val classes = Scene.v().getApplicationClasses
val it = classes.iterator()
while (it.hasNext) {
val sootClass = it.next()
for (method <- sootClass.getMethods.asScala) {
publicMethods.add(method)
}
}

publicMethods.asScala.toList
}

}
Loading