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

Feature/metaproject #86

Draft
wants to merge 80 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
3b3e206
Improved IFDS analysis, including demos and tests; by Mario Trageser
errt Mar 5, 2021
eb91c75
Merge branch 'develop' into feature/IDFS-improvements
errt May 27, 2021
31c4c6b
Create new project "ll"
buenaventure Jun 29, 2021
a26ee83
Add llvm bindings dependency
buenaventure Jun 29, 2021
9490098
Merge branch 'develop' into feature/IDFS-improvements
TorunR Jun 30, 2021
1a3b939
Read and dump module
buenaventure Jul 5, 2021
34d4e25
Begin implementing wrappers
buenaventure Jul 6, 2021
53da4de
Read instructions
buenaventure Jul 7, 2021
283ef68
AndroidEntryPointFinder added
Diarilex Jul 14, 2021
c88385a
Implement SimplePurityAnalysis which assumes everything to be Impure
buenaventure Nov 8, 2021
bca47d7
Merge branch 'develop' into feature/IDFS-improvements
TorunR Nov 10, 2021
c87f9ac
Implement SimplePurityAnalysis
buenaventure Nov 12, 2021
df11561
Implement viewCFG
buenaventure Nov 12, 2021
75f01ea
Merge pull request #3 from buenaventure/develop
buenaventure Dec 2, 2021
79cf52a
Merge remote-tracking branch 'upstream/develop' into ll
buenaventure Jan 5, 2022
905ad98
Add simple multilingual test project
buenaventure Jan 6, 2022
c624d84
Merge remote-tracking branch 'upstream/develop' into feature/IDFS-imp…
buenaventure Feb 17, 2022
bb079fd
Merge branch 'develop' into ll
buenaventure Feb 17, 2022
9ccee79
Add taint testcase
buenaventure Feb 5, 2022
6ab61f6
Merge branch 'feature/IDFS-improvements' into ll_multiling_ifds
buenaventure Feb 18, 2022
b99997c
Format code
buenaventure Feb 18, 2022
90c179a
Adapt new ifds to new call graph (with context)
buenaventure Feb 21, 2022
a464309
Add multilingual taint test
buenaventure Feb 23, 2022
7d00973
Extract IFDSProblem(flow functions etc) from IFDSAnalysis
buenaventure Mar 2, 2022
e3838cf
Replace specialized ifds analysis classes with parameter
buenaventure Mar 2, 2022
633c377
WIP
buenaventure Mar 5, 2022
cc84ea1
WIP
buenaventure Mar 10, 2022
cb4f4f7
WIP
buenaventure Mar 10, 2022
41d949c
WIP
buenaventure Mar 11, 2022
0b40422
WIP
buenaventure Mar 16, 2022
54bb807
WIP
buenaventure Mar 16, 2022
76a1c27
WIP (compiles)
buenaventure Mar 17, 2022
2bfaeea
Initialization fix
buenaventure Mar 17, 2022
6df8fab
Implement LLVM Argument, Type(s); Better Function/Instruction represe…
buenaventure Mar 18, 2022
f92c953
Move IFDS into separate project; Refactor handling of calls outside o…
buenaventure Mar 18, 2022
3931605
Re-implement ifds solver
buenaventure Mar 24, 2022
3ee3a04
Use new implementation for native part
buenaventure Mar 24, 2022
25d0f19
Implement forward taint analysis as test for new ifds solver
buenaventure Mar 25, 2022
3283b03
Fix new forward taint analysis
buenaventure Mar 31, 2022
313fd9a
Fix scalariformat and other compile errors
buenaventure Mar 31, 2022
75be229
Refactor: Move old code to .old, remove New prefix
buenaventure Apr 1, 2022
847baa5
First native flows working
buenaventure Apr 1, 2022
7d47c14
Fix native flows
buenaventure Apr 13, 2022
5e9cfaf
Cleanup
buenaventure May 6, 2022
16a99ae
Include llvm dependency using special sbt plugin
buenaventure May 6, 2022
89c1ff7
Fix sbt assembly
buenaventure May 11, 2022
89b91ca
Reverst scalastyle change
buenaventure May 11, 2022
91bae7d
Improve test case
buenaventure Jun 8, 2022
ed4ee71
Fix test
buenaventure Jun 9, 2022
626cce9
Fix wrong flow by adding successor to return flow and checking for ab…
buenaventure Jun 9, 2022
f34443b
Fix return flow of native code
buenaventure Jun 9, 2022
7284093
Format
buenaventure Jun 9, 2022
ab242a9
Add native to java calls to TaintTest
buenaventure Jun 16, 2022
c53aa61
Fix crashes and old tests
buenaventure Jun 17, 2022
943d7a1
Add debugData for ifds; Add simple GetElementPointer handling
buenaventure Jun 18, 2022
cb0be34
Native to Java calls WIP
buenaventure Jun 19, 2022
d3ab854
Small fixes
buenaventure Jun 22, 2022
b6a2202
JNI call analysis WIP
buenaventure Jun 25, 2022
e5d34a1
JNI call analysis WIP
buenaventure Jun 26, 2022
ec8c05a
Merge remote-tracking branch 'upstream/develop' into llvm_xlang_ifds
buenaventure Jun 30, 2022
ad65890
Fix most errors after merge
buenaventure Jun 30, 2022
c050890
Fix remaining errors after merge
buenaventure Jul 1, 2022
655d22a
Implement VTA in new IFDS for evaluation
buenaventure Jul 2, 2022
b844920
Implement Subsuming and add to evaluation
buenaventure Jul 2, 2022
d43fb11
x-lang working in simple case
buenaventure Jul 2, 2022
630162d
Bump javacpp version to work on M1 Macs.
Oct 4, 2022
52ac95c
Merge branch 'develop' into llvm_xlang_ifds
Oct 4, 2022
9786859
Remove old stuff, which should be superseded
Oct 4, 2022
91e92fa
Readd some not so obsolete Files and adapt to new IFDS Analysis
TorunR Oct 7, 2022
2d38159
Narfi ... fix Scala3 Syntax
TorunR Oct 7, 2022
4c93757
Autoformat and another backward hiccup
TorunR Oct 7, 2022
f67b853
Fix 2 small errors in llvm analysis
TorunR Oct 7, 2022
f766abb
Fix 2 other cases of scala 3 syntax.
TorunR Oct 7, 2022
55fea42
Move IFDS to si
TorunR Oct 11, 2022
42fa220
Add a language agnostic Metaproject
TorunR Oct 26, 2022
3848594
Merge branch 'develop' into feature/metaproject
TorunR Oct 27, 2022
7800e6f
Migrate TAC & AI to MetaProject
TorunR Oct 27, 2022
942f1ef
Adapt the other sub projects
TorunR Oct 28, 2022
9399a51
Fix Validate
TorunR Oct 28, 2022
e730d83
Merge branch 'develop' into feature/metaproject
TorunR Nov 15, 2022
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
Prev Previous commit
Next Next commit
Implement VTA in new IFDS for evaluation
  • Loading branch information
buenaventure committed Jul 2, 2022
commit 655d22aee112c0f4bafd36c7fc950ee97e5c3fe4
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* BSD 2-Clause License - see OPAL/LICENSE for details. */
package org.opalj.tac.fpcf.analyses

import java.io.File

import org.opalj.tac.fpcf.analyses.heros.analyses.HerosVariableTypeAnalysisRunner
import org.opalj.tac.fpcf.analyses.ifds.old
import org.opalj.tac.fpcf.analyses.ifds.IFDSBasedVariableTypeAnalysisRunner

/**
* Generates some evaluation files related to the AbstractIFDSAnalysis.
*
* @author Mario Trageser
*/
object NewIFDSEvaluation {

/**
* args should contain exactly one parameter:
* A directory, which will contain the evaluation files; terminated with a '/'.
*
*/
def main(args: Array[String]): Unit = {
val dir = args(0)
new File(dir).mkdirs

old.IFDSBasedVariableTypeAnalysisRunner.main(Array("-seq", "-l2", "-f", dir+"OldIFDSBasedVariableTypeAnalysis.txt"))
HerosVariableTypeAnalysisRunner.main(Array("-f", dir+"HerosVariableTypeAnalysis.txt"))
IFDSBasedVariableTypeAnalysisRunner.main(Array("-seq", "-l2", "-f", dir+"IFDSBasedVariableTypeAnalysis.txt"))
}

}
18 changes: 11 additions & 7 deletions OPAL/ifds/src/main/scala/org/opalj/ifds/IFDSAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ case class PathEdges[IFDSFact <: AbstractIFDSFact, S <: Statement[_ <: C, _], C]
true
case Some(Left(existingFacts)) =>
if (predecessor.isDefined) throw new IllegalArgumentException(s"${statement} does not accept a predecessor")
val isNew = !existingFacts.contains(fact)
edges = edges.updated(statement, Left(existingFacts + fact))
isNew
if (isNew(existingFacts, fact)) {
edges = edges.updated(statement, Left(existingFacts + fact))
true
} else false
case Some(Right(existingFacts)) =>
predecessor match {
case None => throw new IllegalArgumentException(s"${statement} requires a predecessor")
case Some(predecessor) => existingFacts.get(statement) match {
case Some(existingPredecessorFacts) => {
val isNew = !existingPredecessorFacts.contains(fact)
edges = edges.updated(statement, Right(existingFacts.updated(predecessor, existingPredecessorFacts + fact)))
isNew
if (isNew(existingPredecessorFacts, fact)) {
edges = edges.updated(statement, Right(existingFacts.updated(predecessor, existingPredecessorFacts + fact)))
true
} else false
}
case None => {
edges = edges.updated(statement, Right(existingFacts.updated(predecessor, Set(fact))))
Expand All @@ -89,6 +91,8 @@ case class PathEdges[IFDSFact <: AbstractIFDSFact, S <: Statement[_ <: C, _], C]
}
}

private def isNew(existingFacts: Set[IFDSFact], newFact: IFDSFact): Boolean = !existingFacts.contains(newFact)

/**
* @param statement
* @return The edges reaching statement if any. In case the statement minds about predecessors it is a map with an entry for each predecessor
Expand Down Expand Up @@ -121,7 +125,7 @@ protected class IFDSState[IFDSFact <: AbstractIFDSFact, C <: AnyRef, S <: Statem
/**
* Contains int variables, which count, how many times some method was called.
*/
protected class Statistics {
class Statistics {
var normalFlow = 0
var callFlow = 0
var returnFlow = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/* BSD 2-Clause License - see OPAL/LICENSE for details. */
package org.opalj.tac.fpcf.analyses.ifds

import java.io.File
import java.io.PrintWriter
import scala.language.existentials
import com.typesafe.config.ConfigValueFactory
import org.opalj.bytecode
import org.opalj.ifds.Statistics
import org.opalj.ifds.IFDSAnalysis
import org.opalj.ifds.IFDSAnalysisScheduler

import org.opalj.util.Milliseconds
import org.opalj.util.PerformanceEvaluation.time
import org.opalj.fpcf.FinalEP
import org.opalj.fpcf.PropertyStore
import org.opalj.fpcf.seq.PKESequentialPropertyStore
import org.opalj.br.fpcf.FPCFAnalysesManagerKey
import org.opalj.br.DeclaredMethod
import org.opalj.br.analyses.Project
import org.opalj.br.analyses.SomeProject
import org.opalj.br.fpcf.PropertyStoreKey
import org.opalj.ai.domain.l0.PrimitiveTACAIDomain
import org.opalj.ai.domain.l2
import org.opalj.ai.fpcf.properties.AIDomainFactoryKey
import org.opalj.tac.cg.RTACallGraphKey
import org.opalj.tac.fpcf.properties.cg.Callers

abstract class EvaluationRunner {

protected def analysisClass: IFDSAnalysisScheduler[_, _, _]

protected def printAnalysisResults(analysis: IFDSAnalysis[_, _, _], ps: PropertyStore): Unit = ()

protected def run(
debug: Boolean,
useL2: Boolean,
delay: Boolean,
evalSchedulingStrategies: Boolean,
evaluationFile: Option[File]
): Unit = {

if (debug) {
PropertyStore.updateDebug(true)
}

def evalProject(p: SomeProject): (Milliseconds, Statistics, Option[Object]) = {
if (useL2) {
p.updateProjectInformationKeyInitializationData(AIDomainFactoryKey) {
case None => Set(classOf[l2.DefaultPerformInvocationsDomainWithCFGAndDefUse[_]])
case Some(requirements) =>
requirements + classOf[l2.DefaultPerformInvocationsDomainWithCFGAndDefUse[_]]
}
} else {
p.updateProjectInformationKeyInitializationData(AIDomainFactoryKey) {
case None => Set(classOf[PrimitiveTACAIDomain])
case Some(requirements) => requirements + classOf[PrimitiveTACAIDomain]
}
}

val ps = p.get(PropertyStoreKey)
var analysisTime: Milliseconds = Milliseconds.None
p.get(RTACallGraphKey)
println("Start: "+new java.util.Date)
org.opalj.util.gc()
val analysis =
time {
p.get(FPCFAnalysesManagerKey).runAll(analysisClass)._2
}(t => analysisTime = t.toMilliseconds).collect {
case (_, a: IFDSAnalysis[_, _, _]) => a
}.head

printAnalysisResults(analysis, ps)
println(s"The analysis took $analysisTime.")
println(
ps.statistics.iterator
.map(_.toString())
.toList
.sorted
.mkString("PropertyStore Statistics:\n\t", "\n\t", "\n")
)
(
analysisTime,
analysis.statistics,
additionalEvaluationResult(analysis)
)
}

val p = Project(bytecode.RTJar)

if (delay) {
println("Sleeping for three seconds.")
Thread.sleep(3000)
}

if (evalSchedulingStrategies) {
val results = for {
i <- 1 to EvaluationRunner.NUM_EXECUTIONS_EVAL_SCHEDULING_STRATEGIES
strategy <- PKESequentialPropertyStore.Strategies
} yield {
println(s"Round: $i - $strategy")
val strategyValue = ConfigValueFactory.fromAnyRef(strategy)
val newConfig =
p.config.withValue(PKESequentialPropertyStore.TasksManagerKey, strategyValue)
val evaluationResult = evalProject(Project.recreate(p, newConfig))
org.opalj.util.gc()
(i, strategy, evaluationResult._1, evaluationResult._2)
}
println(results.mkString("AllResults:\n\t", "\n\t", "\n"))
if (evaluationFile.nonEmpty) {
val pw = new PrintWriter(evaluationFile.get)
PKESequentialPropertyStore.Strategies.foreach { strategy =>
val strategyResults = results.filter(_._2 == strategy)
val averageTime = strategyResults.map(_._3.timeSpan).sum / strategyResults.size
val (normalFlow, callToStart, exitToReturn, callToReturn) =
computeAverageStatistics(strategyResults.map(_._4))
pw.println(s"Strategy $strategy:")
pw.println(s"Average time: ${averageTime}ms")
pw.println(s"Average calls of normalFlow: $normalFlow")
pw.println(s"Average calls of callToStart: $callToStart")
pw.println(s"Average calls of exitToReturn: $exitToReturn")
pw.println(s"Average calls of callToReturn: $callToReturn")
pw.println()
}
pw.close()
}
} else {
var times = Seq.empty[Milliseconds]
var statistics = Seq.empty[Statistics]
var additionalEvaluationResults = Seq.empty[Object]
for {
_ <- 1 to EvaluationRunner.NUM_EXECUTIONS
} {
val evaluationResult = evalProject(Project.recreate(p))
val additionalEvaluationResult = evaluationResult._3
times :+= evaluationResult._1
statistics :+= evaluationResult._2
if (additionalEvaluationResult.isDefined)
additionalEvaluationResults :+= additionalEvaluationResult.get
}
if (evaluationFile.nonEmpty) {
val (normalFlow, callFlow, returnFlow, callToReturnFlow) = computeAverageStatistics(
statistics
)
val time = times.map(_.timeSpan).sum / times.size
val pw = new PrintWriter(evaluationFile.get)
pw.println(s"Average time: ${time}ms")
pw.println(s"Average calls of normalFlow: $normalFlow")
pw.println(s"Average calls of callFlow: $callFlow")
pw.println(s"Average calls of returnFlow: $returnFlow")
pw.println(s"Average calls of callToReturnFlow: $callToReturnFlow")
if (additionalEvaluationResults.nonEmpty)
writeAdditionalEvaluationResultsToFile(pw, additionalEvaluationResults)
pw.close()
}
}
}

protected def additionalEvaluationResult(analysis: IFDSAnalysis[_, _, _]): Option[Object] = None

protected def writeAdditionalEvaluationResultsToFile(
writer: PrintWriter,
additionalEvaluationResults: Seq[Object]
): Unit = {}

protected def canBeCalledFromOutside(
method: DeclaredMethod,
propertyStore: PropertyStore
): Boolean =
propertyStore(method, Callers.key) match {
// This is the case, if the method may be called from outside the library.
case FinalEP(_, p: Callers) => p.hasCallersWithUnknownContext
case _ =>
throw new IllegalStateException(
"call graph mut be computed before the analysis starts"
)
}

private def computeAverageStatistics(statistics: Seq[Statistics]): (Int, Int, Int, Int) = {
val length = statistics.length
val normalFlow = statistics.map(_.normalFlow).sum / length
val callFlow = statistics.map(_.callFlow).sum / length
val returnFlow = statistics.map(_.returnFlow).sum / length
val callToReturnFlow = statistics.map(_.callToReturnFlow).sum / length
(normalFlow, callFlow, returnFlow, callToReturnFlow)
}
}

object EvaluationRunner {
var NUM_EXECUTIONS = 10
var NUM_EXECUTIONS_EVAL_SCHEDULING_STRATEGIES = 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* BSD 2-Clause License - see OPAL/LICENSE for details. */
package org.opalj.tac.fpcf.analyses.ifds

import org.opalj.br.analyses.SomeProject
import org.opalj.fpcf.{PropertyBounds, PropertyKey, PropertyStore}
import org.opalj.ifds.old.{NumberOfSubsumptions, Subsuming}
import org.opalj.ifds.{IFDSProperty, IFDSPropertyMetaInformation}

import org.opalj.tac.fpcf.properties.TACAI
import org.opalj.tac.fpcf.properties.cg.Callers
import java.io.{File, PrintWriter}

import org.opalj.ifds.IFDSAnalysis
import org.opalj.ifds.IFDSAnalysisScheduler

import org.opalj.br.Method
import org.opalj.br.analyses.DeclaredMethodsKey
import org.opalj.br.analyses.ProjectInformationKeys
import org.opalj.br.fpcf.PropertyStoreKey
import org.opalj.tac.cg.TypeProviderKey

/**
* A variable type analysis implemented as an IFDS analysis.
* In contrast to an ordinary variable type analysis, which also determines types of fields,
* this analysis only determines the types of local variables.
* The subsuming taint can be mixed in to enable subsuming.
*
* @param project The analyzed project.
* @author Mario Trageser
*/
class IFDSBasedVariableTypeAnalysis(project: SomeProject)
extends IFDSAnalysis()(project, new VariableTypeProblem(project), VTAResult)

object IFDSBasedVariableTypeAnalysisScheduler extends IFDSAnalysisScheduler[VTAFact, Method, JavaStatement] {
override def init(p: SomeProject, ps: PropertyStore) = new IFDSBasedVariableTypeAnalysis(p)
override def property: IFDSPropertyMetaInformation[JavaStatement, VTAFact] = VTAResult
override val uses: Set[PropertyBounds] = Set(PropertyBounds.finalP(TACAI), PropertyBounds.finalP(Callers))
override def requiredProjectInformation: ProjectInformationKeys = Seq(DeclaredMethodsKey, TypeProviderKey, PropertyStoreKey)
}

/**
* The IFDSProperty for this analysis.
*/
case class VTAResult(flows: Map[JavaStatement, Set[VTAFact]], debugData: Map[JavaStatement, Set[VTAFact]] = Map.empty) extends IFDSProperty[JavaStatement, VTAFact] {

override type Self = VTAResult
override def create(result: Map[JavaStatement, Set[VTAFact]]): IFDSProperty[JavaStatement, VTAFact] = new VTAResult(result)
override def create(result: Map[JavaStatement, Set[VTAFact]], debugData: Map[JavaStatement, Set[VTAFact]]): IFDSProperty[JavaStatement, VTAFact] = new VTAResult(result, debugData)

override def key: PropertyKey[VTAResult] = VTAResult.key
}

object VTAResult extends IFDSPropertyMetaInformation[JavaStatement, VTAFact] {

override type Self = VTAResult
override def create(result: Map[JavaStatement, Set[VTAFact]]): IFDSProperty[JavaStatement, VTAFact] = new VTAResult(result)
override def create(result: Map[JavaStatement, Set[VTAFact]], debugData: Map[JavaStatement, Set[VTAFact]]): IFDSProperty[JavaStatement, VTAFact] = new VTAResult(result, debugData)

val key: PropertyKey[VTAResult] = PropertyKey.create("VTAnew", new VTAResult(Map.empty))
}

class IFDSBasedVariableTypeAnalysisRunner extends EvaluationRunner {

override def analysisClass: IFDSBasedVariableTypeAnalysisScheduler.type = IFDSBasedVariableTypeAnalysisScheduler

override protected def additionalEvaluationResult(
analysis: IFDSAnalysis[_, _, _]
): Option[Object] =
analysis match {
case subsuming: Subsuming[_, _] => Some(subsuming.numberOfSubsumptions)
case _ => None
}

override protected def writeAdditionalEvaluationResultsToFile(
writer: PrintWriter,
additionalEvaluationResults: Seq[Object]
): Unit = {
val numberOfSubsumptions = additionalEvaluationResults.map(_.asInstanceOf[NumberOfSubsumptions])
val length = additionalEvaluationResults.length
val tries = numberOfSubsumptions.map(_.triesToSubsume).sum / length
val successes = numberOfSubsumptions.map(_.successfulSubsumes).sum / length
writer.println(s"Average tries to subsume: $tries")
writer.println(s"Average successful subsumes: $successes")
}
}

object IFDSBasedVariableTypeAnalysisRunner {
def main(args: Array[String]): Unit = {
if (args.contains("--help")) {
println("Potential parameters:")
println(" -seq (to use the SequentialPropertyStore)")
println(" -l2 (to use the l2 domain instead of the default l1 domain)")
println(" -delay (for a three seconds delay before the taint flow analysis is started)")
println(" -debug (for debugging mode in the property store)")
println(" -evalSchedulingStrategies (evaluates all available scheduling strategies)")
println(" -f <file> (Stores the average runtime to this file)")
} else {
val fileIndex = args.indexOf("-f")
new IFDSBasedVariableTypeAnalysisRunner().run(
args.contains("-debug"),
args.contains("-l2"),
args.contains("-delay"),
args.contains("-evalSchedulingStrategies"),
if (fileIndex >= 0) Some(new File(args(fileIndex + 1))) else None
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ object JavaStatement {

abstract class JavaIFDSProblem[Fact <: AbstractIFDSFact](project: SomeProject)
extends IFDSProblem[Fact, Method, JavaStatement](new ForwardICFG()(project)) {

override def needsPredecessor(statement: JavaStatement): Boolean = false

/**
* Gets the call object for a statement that contains a call.
*
Expand Down
Loading