Packages

  • package root
    Definition Classes
    root
  • package io
    Definition Classes
    root
  • package shiftleft
    Definition Classes
    io
  • package queryprimitives

    Domain specific language for querying code property graphs

    Domain specific language for querying code property graphs

    This is the API reference for the CPG query language, a language to mine code for defects and vulnerabilities both interactively on a code analysis shell (REPL), or using non-interactive scripts.

    Queries written in the CPG query language express graph traversals (see https://en.wikipedia.org/wiki/Graph_traversal). Similar to the standard graph traversal language "Gremlin" (see https://en.wikipedia.org/wiki/Gremlin_(programming_language))) these traversals are formulated as sequences of primitive language elements referred to as "steps". You can think of a step as a small program, similar to a unix shell utility, however, instead of processing lines one by one, the step processes nodes of the graph.

    Starting a traversal

    All traversals begin by selecting a set of start nodes, e.g.,

    cpg.method

    will start the traversal at all methods, while

    cpg.local

    will start at all local variables. The complete list of starting points can be found here: io.shiftleft.queryprimitives.steps.starters.Cpg

    Lazy evaluation

    Queries are lazily evaluated, e.g., cpg.method creates a traversal which you can add more steps to. You can, for example, evaluate the traversal by converting it to a list:

    cpg.method.toList

    Since toList is such a common operation, we provide the shorthand l, meaning that

    cpg.method.l

    provides the same result as the former query.

    Properties

    Nodes have "properties", key-value pairs where keys are strings and values are primitive data types such as strings, integers, or Booleans. Properties of nodes can be selected based on their key, e.g.,

    cpg.method.name

    traverses to all method names. Nodes can also be filtered based on properties, e.g.,

    cpg.method.name(".*exec.*")

    traverse to all methods where name matches the regular expression ".*exec.*". You can see a complete list of properties by browsing to the API documentation of the corresponding step. For example, you can find the properties of method nodes at io.shiftleft.queryprimitives.steps.types.structure.Method.

    Side effects

    Useful if you want to mutate something outside the traversal, or simply debug it: This prints all typeDecl names as it traverses the graph and increments i for each one.

    var i = 0
    cpg.typeDecl.sideEffect{typeTemplate => println(typeTemplate.name); i = i + 1}.exec

    [advanced] Selecting multiple things from your traversal

    If you are interested in multiple things along the way of your traversal, you label anything using the as modulator, and use select at the end. Note that the compiler automatically derived the correct return type as a tuple of the labelled steps, in this case with two elements.

    cpg.method.as("method").definingTypeDecl.as("classDef").select.toList
    // return type: List[(nodes.Method, nodes.TypeDecl)]

    [advanced] For comprehensions

    You can always start a new traversal from a node, e.g.,

    val someMethod = cpg.method.head
    someMethod.start.parameter.toList

    You can use this e.g. in a for comprehension, which is (in this context) essentially an alternative way to select multiple intermediate things. It is more expressive, but more computationally expensive.

    val query = for {
      method <- cpg.method
      param <- method.start.parameter
    } yield (method.name, param.name)
    
    query.toList
    Definition Classes
    shiftleft
  • package steps

    Steps for traversing the code property graph

    Steps for traversing the code property graph

    All traversal start at io.shiftleft.queryprimitives.starters.Cpg.

    Definition Classes
    queryprimitives
  • package types
    Definition Classes
    steps
  • package structure
    Definition Classes
    types
  • File
  • Local
  • Member
  • Method
  • MethodInst
  • MethodParameter
  • MethodParameterOut
  • MethodReturn
  • Namespace
  • NamespaceBlock
  • Type
  • TypeDecl

class MethodReturn[Labels <: HList] extends CpgSteps[codepropertygraph.generated.nodes.MethodReturn, Labels] with CodeAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels] with LineNumberAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels] with EvalTypeAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels]

Linear Supertypes
EvalTypeAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels], LineNumberAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels], PropertyAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels], CodeAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels], StringPropertyAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels], CpgSteps[codepropertygraph.generated.nodes.MethodReturn, Labels], NodeSteps[codepropertygraph.generated.nodes.MethodReturn, Labels], Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels], StepsRoot, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. MethodReturn
  2. EvalTypeAccessors
  3. LineNumberAccessors
  4. PropertyAccessors
  5. CodeAccessors
  6. StringPropertyAccessors
  7. CpgSteps
  8. NodeSteps
  9. Steps
  10. StepsRoot
  11. AnyRef
  12. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new MethodReturn(raw: GremlinScala[Vertex])

Type Members

  1. type EndDomain0 = codepropertygraph.generated.nodes.MethodReturn
    Definition Classes
    Steps → StepsRoot
  2. type EndGraph0 = Vertex
    Definition Classes
    Steps → StepsRoot

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def _toJson(pretty: Boolean): String
    Attributes
    protected
    Definition Classes
    CpgSteps
  5. def aggregate(into: Buffer[codepropertygraph.generated.nodes.MethodReturn]): NodeSteps[codepropertygraph.generated.nodes.MethodReturn, Labels]
    Definition Classes
    NodeSteps
  6. def and(andTraversals: (Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, HNil]) ⇒ Steps[_, _, _]*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  7. def as[NewLabels <: HList](stepLabel: StepLabel[codepropertygraph.generated.nodes.MethodReturn])(implicit prependDomain: shapeless.ops.hlist.Prepend.Aux[Labels, ::[codepropertygraph.generated.nodes.MethodReturn, HNil], NewLabels]): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, NewLabels]
    Definition Classes
    Steps
  8. def as[NewLabels <: HList](stepLabel: String)(implicit prependDomain: shapeless.ops.hlist.Prepend.Aux[Labels, ::[codepropertygraph.generated.nodes.MethodReturn, HNil], NewLabels]): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, NewLabels]
    Definition Classes
    Steps
  9. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  10. def cfgLast: Expression[Labels]

    Traverse to last expressions in CFG.

    Traverse to last expressions in CFG. Can be multiple.

  11. def clone(): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps → AnyRef
  12. def code(value: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    CodeAccessors
  13. def code(value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    CodeAccessors
  14. def code(): Steps[String, String, Labels]
    Definition Classes
    CodeAccessors
  15. def codeExact(values: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    CodeAccessors
  16. def codeExact(value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    CodeAccessors
  17. def codeNot(values: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    CodeAccessors
  18. def codeNot(value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    CodeAccessors
  19. val converter: Converter[codepropertygraph.generated.nodes.MethodReturn] { type GraphType = gremlin.scala.Vertex }
  20. def count(): Long
    Definition Classes
    Steps
  21. def dedup(): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  22. def emit(emitTraversal: (Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, HNil]) ⇒ Steps[_, _, _]): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  23. def emit(): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  24. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  26. def evalType(_values: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    EvalTypeAccessors
  27. def evalType(_value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    EvalTypeAccessors
  28. def evalType(): Steps[String, String, Labels]
    Definition Classes
    EvalTypeAccessors
  29. def evalTypeExact(_values: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    EvalTypeAccessors
  30. def evalTypeExact(_value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    EvalTypeAccessors
  31. def evalTypeNot(_values: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    EvalTypeAccessors
  32. def evalTypeNot(_value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    EvalTypeAccessors
  33. def exec(): Unit
    Definition Classes
    Steps
  34. def file: File[Labels]

    Traverse to source file

    Traverse to source file

    Definition Classes
    CpgSteps
  35. def filter(predicate: (Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]) ⇒ Steps[_, _, _]): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  36. def filterNot(predicate: (Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]) ⇒ Steps[_, _, _]): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  37. def filterOnEnd(predicate: (codepropertygraph.generated.nodes.MethodReturn) ⇒ Boolean): NodeSteps[codepropertygraph.generated.nodes.MethodReturn, Labels]
    Definition Classes
    NodeSteps
  38. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  39. def flatMap[NewSteps <: StepsRoot](fun: (codepropertygraph.generated.nodes.MethodReturn) ⇒ NewSteps)(implicit constr: Aux[gremlin.scala.dsl.Steps.flatMap.NewSteps.EndDomain0, Labels, gremlin.scala.dsl.Steps.flatMap.NewSteps.EndGraph0, NewSteps], newConverter: Converter[gremlin.scala.dsl.Steps.flatMap.NewSteps.EndDomain0]): NewSteps
    Definition Classes
    Steps
  40. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  41. implicit val graph: Graph
    Definition Classes
    CpgSteps
  42. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  43. def head(): codepropertygraph.generated.nodes.MethodReturn
    Definition Classes
    Steps
  44. def headOption(): Option[codepropertygraph.generated.nodes.MethodReturn]
    Definition Classes
    Steps
  45. def id(ids: AnyRef*): NodeSteps[codepropertygraph.generated.nodes.MethodReturn, Labels]
    Definition Classes
    NodeSteps
  46. def isDefined: Boolean
    Definition Classes
    Steps
  47. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  48. def iterate(): Unit
    Definition Classes
    Steps
  49. def l: List[codepropertygraph.generated.nodes.MethodReturn]
    Definition Classes
    Steps
  50. def lineNumber(value: Integer*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    LineNumberAccessors
  51. def lineNumber(value: Integer): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    LineNumberAccessors
  52. def lineNumber(): Steps[Integer, Integer, Labels]
    Definition Classes
    LineNumberAccessors
  53. def lineNumberNot(values: Integer*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    LineNumberAccessors
  54. def lineNumberNot(value: Integer): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    LineNumberAccessors
  55. def map[NewEndDomain, NewEndGraph, NewSteps <: StepsRoot](fun: (codepropertygraph.generated.nodes.MethodReturn) ⇒ NewEndDomain)(implicit newConverter: Aux[NewEndDomain, NewEndGraph], constr: Aux[NewEndDomain, Labels, NewEndGraph, NewSteps]): NewSteps
    Definition Classes
    Steps
  56. def method: Method[Labels]
  57. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  58. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  59. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  60. def onRaw(fun: (GremlinScala[Vertex]) ⇒ GremlinScala[Vertex]): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  61. def or(orTraversals: (Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, HNil]) ⇒ Steps[_, _, _]*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  62. def orderBy[A](fun: (codepropertygraph.generated.nodes.MethodReturn) ⇒ A): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  63. def p(): Unit
    Definition Classes
    Steps
  64. def property[P](property: Key[P]): Steps[P, P, Labels]
    Definition Classes
    PropertyAccessors
  65. def propertyFilter[Out, P](property: Key[P], value: P): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    PropertyAccessors
  66. def propertyFilterMultiple[Out, P](property: Key[P], values: P*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    PropertyAccessors
  67. def propertyFilterNot[Out, P](property: Key[P], value: P): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    PropertyAccessors
  68. def propertyFilterNotMultiple[Out, P](property: Key[P], values: P*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    PropertyAccessors
  69. val raw: GremlinScala[Vertex]
    Definition Classes
    CpgSteps → NodeSteps → Steps → StepsRoot
  70. def repeat[NewEndDomain >: codepropertygraph.generated.nodes.MethodReturn](repeatTraversal: (Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, HNil]) ⇒ Steps[NewEndDomain, Vertex, _])(implicit newConverter: Aux[NewEndDomain, Vertex]): Steps[NewEndDomain, Vertex, Labels]
    Definition Classes
    Steps
  71. def returnUser: Call[Labels]
  72. def s(): Stream[codepropertygraph.generated.nodes.MethodReturn]
    Definition Classes
    Steps
  73. def select[StepLabelsTuple <: Product, StepLabels <: HList, H0, T0 <: HList, SelectedTypes <: HList, SelectedTypesTuple <: Product, SelectedGraphTypesTuple <: Product, LabelNames <: HList, Z](stepLabelsTuple: StepLabelsTuple)(implicit toHList: Aux[StepLabelsTuple, StepLabels], hasOne: Aux[StepLabels, H0, T0], hasTwo: IsHCons[T0], extractLabelType: Aux[StepLabels, SelectedTypes], tupler: shapeless.ops.hlist.Tupler.Aux[SelectedTypes, SelectedTypesTuple], conv: Aux[SelectedTypesTuple, SelectedGraphTypesTuple], stepLabelToString: Aux[GetLabelName.type, StepLabels, LabelNames], trav: Aux[LabelNames, List, String], folder: Aux[StepLabels, (HNil, Map[String, Any]), combineLabelWithValue.type, (SelectedTypes, Z)]): Steps[SelectedTypesTuple, SelectedGraphTypesTuple, Labels]
    Definition Classes
    Steps
  74. def select[Label, LabelGraph](label: StepLabel[Label])(implicit conv1: Aux[Label, LabelGraph]): Steps[Label, LabelGraph, Labels]
    Definition Classes
    Steps
  75. def select[LabelsGraph <: HList, LabelsGraphTuple, LabelsTuple]()(implicit conv1: Aux[Labels, LabelsGraph], tupler1: shapeless.ops.hlist.Tupler.Aux[LabelsGraph, LabelsGraphTuple], tupler2: shapeless.ops.hlist.Tupler.Aux[Labels, LabelsTuple], conv2: Aux[LabelsTuple, LabelsGraphTuple]): Steps[LabelsTuple, LabelsGraphTuple, Labels]
    Definition Classes
    Steps
  76. def sideEffect(fun: (codepropertygraph.generated.nodes.MethodReturn) ⇒ Any): NodeSteps[codepropertygraph.generated.nodes.MethodReturn, Labels]
    Definition Classes
    NodeSteps
  77. def stringProperty(property: Key[String]): Steps[String, String, Labels]
    Attributes
    protected
    Definition Classes
    StringPropertyAccessors
  78. def stringPropertyFilter(property: Key[String], value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Attributes
    protected
    Definition Classes
    StringPropertyAccessors
  79. def stringPropertyFilterExact[Out](property: Key[String], _value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Attributes
    protected
    Definition Classes
    StringPropertyAccessors
  80. def stringPropertyFilterExactMultiple[Out](property: Key[String], values: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Attributes
    protected
    Definition Classes
    StringPropertyAccessors
  81. def stringPropertyFilterMultiple(property: Key[String], values: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Attributes
    protected
    Definition Classes
    StringPropertyAccessors
  82. def stringPropertyFilterNot[Out](property: Key[String], value: String): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Attributes
    protected
    Definition Classes
    StringPropertyAccessors
  83. def stringPropertyFilterNotMultiple[Out](property: Key[String], values: String*): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Attributes
    protected
    Definition Classes
    StringPropertyAccessors
  84. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  85. def times(maxLoops: Int): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  86. def toBuffer(): Buffer[codepropertygraph.generated.nodes.MethodReturn]
    Definition Classes
    Steps
  87. def toJson: String

    Execute traversal and convert the result to json.

    Execute traversal and convert the result to json.

    Definition Classes
    CpgSteps
  88. def toJsonPretty: String
    Definition Classes
    CpgSteps
  89. def toList(): List[codepropertygraph.generated.nodes.MethodReturn]
    Definition Classes
    Steps
  90. def toMaps(): Steps[Map[String, AnyRef], Map[String, AnyRef], Labels]
    Definition Classes
    CpgSteps
  91. def toSet(): Set[codepropertygraph.generated.nodes.MethodReturn]
    Definition Classes
    Steps
  92. def toStream(): Stream[codepropertygraph.generated.nodes.MethodReturn]
    Definition Classes
    Steps
  93. def toString(): String
    Definition Classes
    Steps → AnyRef → Any
  94. def until(untilTraversal: (Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, HNil]) ⇒ Steps[_, _, _]): Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]
    Definition Classes
    Steps
  95. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  96. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  97. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  98. def walkIn(edgeType: String): GremlinScala[Vertex]
    Definition Classes
    NodeSteps

Inherited from EvalTypeAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels]

Inherited from LineNumberAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels]

Inherited from PropertyAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels]

Inherited from CodeAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels]

Inherited from StringPropertyAccessors[codepropertygraph.generated.nodes.MethodReturn, Labels]

Inherited from CpgSteps[codepropertygraph.generated.nodes.MethodReturn, Labels]

Inherited from NodeSteps[codepropertygraph.generated.nodes.MethodReturn, Labels]

Inherited from Steps[codepropertygraph.generated.nodes.MethodReturn, Vertex, Labels]

Inherited from StepsRoot

Inherited from AnyRef

Inherited from Any

Ungrouped