Skip to content

Commit 87d1137

Browse files
committed
Closes: epicosy#5. graph-for-funcs.sc script update
1 parent e7377dd commit 87d1137

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

joern/graph-for-funcs.sc

+15-18
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ import io.shiftleft.semanticcpg.language.types.expressions.generalizations.CfgNo
3030
import io.shiftleft.codepropertygraph.generated.EdgeTypes
3131
import io.shiftleft.codepropertygraph.generated.NodeTypes
3232
import io.shiftleft.codepropertygraph.generated.nodes
33-
import io.shiftleft.dataflowengine.language._
33+
import io.shiftleft.dataflowengineoss.language._
3434
import io.shiftleft.semanticcpg.language._
3535
import io.shiftleft.semanticcpg.language.types.expressions.Call
3636
import io.shiftleft.semanticcpg.language.types.structure.Local
3737
import io.shiftleft.codepropertygraph.generated.nodes.MethodParameterIn
3838

39-
import gremlin.scala._
40-
import org.apache.tinkerpop.gremlin.structure.Edge
41-
import org.apache.tinkerpop.gremlin.structure.VertexProperty
39+
import overflowdb._
40+
import overflowdb.traversal._
4241

4342
final case class GraphForFuncsFunction(function: String,
4443
file: String,
@@ -48,12 +47,12 @@ final case class GraphForFuncsFunction(function: String,
4847
PDG: List[nodes.AstNode])
4948
final case class GraphForFuncsResult(functions: List[GraphForFuncsFunction])
5049

51-
implicit val encodeEdge: Encoder[Edge] =
52-
(edge: Edge) =>
50+
implicit val encodeEdge: Encoder[OdbEdge] =
51+
(edge: OdbEdge) =>
5352
Json.obj(
5453
("id", Json.fromString(edge.toString)),
55-
("in", Json.fromString(edge.inVertex().toString)),
56-
("out", Json.fromString(edge.outVertex().toString))
54+
("in", Json.fromString(edge.inNode.toString)),
55+
("out", Json.fromString(edge.outNode.toString))
5756
)
5857

5958
implicit val encodeNode: Encoder[nodes.AstNode] =
@@ -62,10 +61,10 @@ implicit val encodeNode: Encoder[nodes.AstNode] =
6261
("id", Json.fromString(node.toString)),
6362
("edges",
6463
Json.fromValues((node.inE("AST", "CFG").l ++ node.outE("AST", "CFG").l).map(_.asJson))),
65-
("properties", Json.fromValues(node.properties().asScala.toList.map { p: VertexProperty[_] =>
64+
("properties", Json.fromValues(node.propertyMap.asScala.toList.map { case (key, value) =>
6665
Json.obj(
67-
("key", Json.fromString(p.key())),
68-
("value", Json.fromString(p.value().toString))
66+
("key", Json.fromString(key)),
67+
("value", Json.fromString(value.toString))
6968
)
7069
}))
7170
)
@@ -77,24 +76,22 @@ implicit val encodeFuncResult: Encoder[GraphForFuncsResult] = deriveEncoder
7776
GraphForFuncsResult(
7877
cpg.method.map { method =>
7978
val methodName = method.fullName
80-
val methodFile = method.location.filename
8179
val methodId = method.toString
80+
val methodFile = method.location.filename
81+
val methodVertex: Vertex = method //TODO MP drop as soon as we have the remainder of the below in ODB graph api
8282

8383
val astChildren = method.astMinusRoot.l
84-
85-
val cfgChildren = new NodeSteps(
86-
method.out(EdgeTypes.CONTAINS).filterOnEnd(_.isInstanceOf[nodes.CfgNode]).cast[nodes.CfgNode]
87-
).l
84+
val cfgChildren = method.out(EdgeTypes.CONTAINS).asScala.collect { case node: nodes.CfgNode => node }.toList
8885

8986
val local = new NodeSteps(
90-
method
87+
methodVertex
9188
.out(EdgeTypes.CONTAINS)
9289
.hasLabel(NodeTypes.BLOCK)
9390
.out(EdgeTypes.AST)
9491
.hasLabel(NodeTypes.LOCAL)
9592
.cast[nodes.Local])
9693
val sink = local.evalType(".*").referencingIdentifiers.dedup
97-
val source = new NodeSteps(method.out(EdgeTypes.CONTAINS).hasLabel(NodeTypes.CALL).cast[nodes.Call]).nameNot("<operator>.*").dedup
94+
val source = new NodeSteps(methodVertex.out(EdgeTypes.CONTAINS).hasLabel(NodeTypes.CALL).cast[nodes.Call]).nameNot("<operator>.*").dedup
9895

9996
val pdgChildren = sink
10097
.reachableByFlows(source)

0 commit comments

Comments
 (0)