-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMain.scala
More file actions
52 lines (45 loc) · 1.6 KB
/
Copy pathMain.scala
File metadata and controls
52 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.codeminers.standalone
import io.joern.javasrc2cpg.{Config, JavaSrc2Cpg}
import io.joern.x2cpg.X2Cpg.applyDefaultOverlays
import io.shiftleft.codepropertygraph.generated.Cpg
import io.shiftleft.codepropertygraph.generated.nodes.NewMynodetype
import io.shiftleft.passes.CpgPass
import io.shiftleft.semanticcpg.language._
import flatgraph.DiffGraphBuilder
import scala.util.{Failure, Success}
/** Example program that makes use of Joern as a library */
object Main {
def main(args: Array[String]): Unit = {
println("Hello Joern")
print("Creating CPG... ")
val directory = "testprogram"
val config = Config().withInputPath(directory)
val cpgOrException = JavaSrc2Cpg().createCpg(config)
cpgOrException match {
case Success(cpg) =>
println("[DONE]")
println("Applying default overlays")
applyDefaultOverlays(cpg)
println("Printing all methods:")
println("=====================")
cpg.method.name.foreach(println)
println("=====================")
println("Running a custom pass to add some custom nodes")
new MyPass(cpg).createAndApply()
println("Running custom queries")
cpg.mynodetype.foreach(println)
cpg.mynodetype.myCustomStep.l
case Failure(exception) =>
println("[FAILED]")
println(exception)
}
}
}
/** Example of a custom pass that creates and stores a node in the CPG.
*/
class MyPass(cpg: Cpg) extends CpgPass(cpg) {
override def run(builder: DiffGraphBuilder): Unit = {
val n = NewMynodetype().myproperty("foo")
builder.addNode(n)
}
}