diff --git a/CHANGELOG.md b/CHANGELOG.md index 144437fd..3d0cd6d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Added +- Soot only configuration for the metrics + +### Changed + +- Upgraded CPG to latest version before IDs were removed again +- Removed unused methods in ODB `Traversals` + ## [0.6.0] - 2021-09-14 ### Changed diff --git a/VERSION.md b/VERSION.md index 09a3acfa..e75e2434 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -0.6.0 \ No newline at end of file +0.6.0-SNAPSHOT \ No newline at end of file diff --git a/cpgconv/src/main/scala/io/github/plume/oss/Traversals.scala b/cpgconv/src/main/scala/io/github/plume/oss/Traversals.scala index 3edb8f42..b95866ee 100644 --- a/cpgconv/src/main/scala/io/github/plume/oss/Traversals.scala +++ b/cpgconv/src/main/scala/io/github/plume/oss/Traversals.scala @@ -1,13 +1,13 @@ package io.github.plume.oss -import java.util import io.shiftleft.codepropertygraph.Cpg -import io.shiftleft.codepropertygraph.generated.{EdgeTypes, nodes} -import io.shiftleft.codepropertygraph.generated.nodes.{AstNode, File, MetaData, Method, NamespaceBlock, StoredNode, TypeDecl} +import io.shiftleft.codepropertygraph.generated.EdgeTypes +import io.shiftleft.codepropertygraph.generated.nodes.{AstNode, MetaData, StoredNode} import io.shiftleft.dataflowengineoss.passes.reachingdef.{ReachingDefProblem, ReachingDefTransferFunction} import io.shiftleft.semanticcpg.language._ import overflowdb.{Edge, Graph} +import java.util import scala.jdk.CollectionConverters._ object Traversals { @@ -34,30 +34,6 @@ object Traversals { .asJava } - import overflowdb.traversal._ - def getProgramStructure(graph: Graph): util.List[Edge] = { - val edgesFromFile: List[Edge] = Cpg(graph).file - .outE(EdgeTypes.AST) - .filter(_.inNode().isInstanceOf[nodes.NamespaceBlock]) - .l - val edgesFromNamespaceBlock: List[Edge] = edgesFromFile - .to(Traversal) - .inV - .collect { - case x: nodes.NamespaceBlock => - x.outE(EdgeTypes.AST).filter(_.inNode().isInstanceOf[nodes.NamespaceBlock]).l - } - .l - .flatten - (edgesFromFile ++ edgesFromNamespaceBlock).asJava - } - - def getTypeDecls(graph: Graph):util.List[TypeDecl] = Cpg(graph).typeDecl.l.asJava - - def getFiles(graph: Graph):util.List[File] = Cpg(graph).file.l.asJava - - def getNamespaceBlocks(graph: Graph):util.List[NamespaceBlock] = Cpg(graph).namespaceBlock.l.asJava - def getMetaData(graph: Graph):Option[MetaData] = Cpg(graph).metaData.nextOption() def getNeighbours(graph: Graph, nodeId: Long): util.List[Edge] = { diff --git a/gradle.properties b/gradle.properties index 0e6ec6e9..a835ffdf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ neo4jDriverVersion=4.2.0 tigerGraphVersion=3.1.0 khttpVersion=1.0.0 jacksonVersion=2.12.0 -shiftleftVersion=1.3.314 +shiftleftVersion=1.3.336 sootVersion=4.2.1 lz4Version=1.7.1 cache2kVersion=2.0.0.Final diff --git a/plume/src/main/kotlin/io/github/plume/oss/Extractor.kt b/plume/src/main/kotlin/io/github/plume/oss/Extractor.kt index f81237c4..0c380519 100644 --- a/plume/src/main/kotlin/io/github/plume/oss/Extractor.kt +++ b/plume/src/main/kotlin/io/github/plume/oss/Extractor.kt @@ -182,10 +182,12 @@ class Extractor(val driver: IDriver) { * are loaded. * * @param includeReachingDefs if true, will include calculating REACHING_DEF chains. If false, will keep method CPGs - * in memory storage. + * in memory storage. Default is true. + * @param sootOnly if true, will only load files into Soot and clear - this is mostly used for benchmarking. Default + * false. */ @JvmOverloads - fun project(includeReachingDefs: Boolean = true): Extractor { + fun project(includeReachingDefs: Boolean = true, sootOnly: Boolean = false): Extractor { /* Load and compile files then feed them into Soot */ @@ -210,6 +212,11 @@ class Extractor(val driver: IDriver) { ms.map { it.declaringClass }.distinct().forEach(cs::add) // Make sure to build types of called types } compiledFiles.clear() // Done using compiledFiles + if (sootOnly) return apply { + FastHierarchy() // Run this here for completeness + logger.info("Early stopping due to Soot only flag set.") + earlyStopCleanUp() + } /* Build program structure and remove sub-graphs which need to be rebuilt */ diff --git a/plume/src/test/kotlin/io/github/plume/oss/extractor/BasicExtractorTest.kt b/plume/src/test/kotlin/io/github/plume/oss/extractor/BasicExtractorTest.kt index 9b023fa5..db45ea89 100644 --- a/plume/src/test/kotlin/io/github/plume/oss/extractor/BasicExtractorTest.kt +++ b/plume/src/test/kotlin/io/github/plume/oss/extractor/BasicExtractorTest.kt @@ -130,6 +130,15 @@ class BasicExtractorTest { } } + @Test + fun sootOnlyTest() { + extractor.load(validJarFile) + extractor.project(sootOnly = true) + g = driver.getWholeGraph() + // Only metadata will be inserted + assertEquals(1, g.nodeCount()) + } + @Test fun loadFileThatDoesNotExistTest() { assertThrows(NullPointerException::class.java) { extractor.load(File("dne.class")) } diff --git a/plume/src/test/resources/extractor_tests/Test4.py b/plume/src/test/resources/extractor_tests/Test4.py deleted file mode 100644 index ee77cf2e..00000000 --- a/plume/src/test/resources/extractor_tests/Test4.py +++ /dev/null @@ -1,4 +0,0 @@ - -a = 1 -b = 2 -c = a + b \ No newline at end of file diff --git a/plume/src/test/resources/extractor_tests/Test5.js b/plume/src/test/resources/extractor_tests/Test5.js deleted file mode 100644 index 45afb807..00000000 --- a/plume/src/test/resources/extractor_tests/Test5.js +++ /dev/null @@ -1,3 +0,0 @@ -var a = 1; -var b = 2; -var c = a + b; \ No newline at end of file