Skip to content

Commit

Permalink
Upgrade CPG and Add Soot Only Projection (#209)
Browse files Browse the repository at this point in the history
* Upgraded CPG

* Soot only configuration for the metrics
  • Loading branch information
DavidBakerEffendi authored Sep 22, 2021
1 parent f4b78a4 commit e16a2d7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 38 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.6.0-SNAPSHOT
30 changes: 3 additions & 27 deletions cpgconv/src/main/scala/io/github/plume/oss/Traversals.scala
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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] = {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions plume/src/main/kotlin/io/github/plume/oss/Extractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) }
Expand Down
4 changes: 0 additions & 4 deletions plume/src/test/resources/extractor_tests/Test4.py

This file was deleted.

3 changes: 0 additions & 3 deletions plume/src/test/resources/extractor_tests/Test5.js

This file was deleted.

0 comments on commit e16a2d7

Please sign in to comment.