-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new Overlay and Concept nodes to the graph. (#1897)
- Loading branch information
1 parent
1f16d58
commit 698937e
Showing
8 changed files
with
301 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/OverlayNode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* $$$$$$\ $$$$$$$\ $$$$$$\ | ||
* $$ __$$\ $$ __$$\ $$ __$$\ | ||
* $$ / \__|$$ | $$ |$$ / \__| | ||
* $$ | $$$$$$$ |$$ |$$$$\ | ||
* $$ | $$ ____/ $$ |\_$$ | | ||
* $$ | $$\ $$ | $$ | $$ | | ||
* \$$$$$ |$$ | \$$$$$ | | ||
* \______/ \__| \______/ | ||
* | ||
*/ | ||
package de.fraunhofer.aisec.cpg.graph | ||
|
||
import de.fraunhofer.aisec.cpg.graph.edges.overlay.OverlaySingleEdge | ||
import de.fraunhofer.aisec.cpg.graph.edges.unwrapping | ||
import org.neo4j.ogm.annotation.Relationship | ||
|
||
/** | ||
* Represents an extra node added to the CPG. These nodes can live next to the regular nodes, | ||
* typically having shared edges to extend the original graph. | ||
*/ | ||
abstract class OverlayNode() : Node() { | ||
@Relationship(value = "OVERLAY", direction = Relationship.Direction.INCOMING) | ||
/** All [OverlayNode]s nodes are connected to an original cpg [Node] by this. */ | ||
val underlyingNodeEdge: OverlaySingleEdge = | ||
OverlaySingleEdge( | ||
this, | ||
of = null, | ||
mirrorProperty = Node::overlayEdges, | ||
outgoing = false, | ||
) | ||
var underlyingNode by unwrapping(OverlayNode::underlyingNodeEdge) | ||
} |
38 changes: 38 additions & 0 deletions
38
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/concepts/Concept.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* $$$$$$\ $$$$$$$\ $$$$$$\ | ||
* $$ __$$\ $$ __$$\ $$ __$$\ | ||
* $$ / \__|$$ | $$ |$$ / \__| | ||
* $$ | $$$$$$$ |$$ |$$$$\ | ||
* $$ | $$ ____/ $$ |\_$$ | | ||
* $$ | $$\ $$ | $$ | $$ | | ||
* \$$$$$ |$$ | \$$$$$ | | ||
* \______/ \__| \______/ | ||
* | ||
*/ | ||
package de.fraunhofer.aisec.cpg.graph.concepts | ||
|
||
import de.fraunhofer.aisec.cpg.graph.OverlayNode | ||
|
||
/** | ||
* Represents a new concept added to the CPG. This is intended for modelling "concepts" like | ||
* logging, files, databases. The relevant operations on this concept are modeled as [Operation]s | ||
* and stored in [ops]. | ||
*/ | ||
abstract class Concept<T : Operation>() : OverlayNode() { | ||
/** All [Operation]s belonging to this concept. */ | ||
val ops: MutableSet<T> = mutableSetOf() | ||
} |
37 changes: 37 additions & 0 deletions
37
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/concepts/Operation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* $$$$$$\ $$$$$$$\ $$$$$$\ | ||
* $$ __$$\ $$ __$$\ $$ __$$\ | ||
* $$ / \__|$$ | $$ |$$ / \__| | ||
* $$ | $$$$$$$ |$$ |$$$$\ | ||
* $$ | $$ ____/ $$ |\_$$ | | ||
* $$ | $$\ $$ | $$ | $$ | | ||
* \$$$$$ |$$ | \$$$$$ | | ||
* \______/ \__| \______/ | ||
* | ||
*/ | ||
package de.fraunhofer.aisec.cpg.graph.concepts | ||
|
||
import de.fraunhofer.aisec.cpg.graph.OverlayNode | ||
|
||
/** | ||
* Represents an operation executed on/with a [Concept] (stored in [concept]). This is typically a | ||
* `write` on a file or log object or an `execute` on a database. | ||
*/ | ||
abstract class Operation( | ||
/** The [Concept] this operation belongs to. */ | ||
val concept: Concept<*> | ||
) : OverlayNode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/edges/overlay/Overlay.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* $$$$$$\ $$$$$$$\ $$$$$$\ | ||
* $$ __$$\ $$ __$$\ $$ __$$\ | ||
* $$ / \__|$$ | $$ |$$ / \__| | ||
* $$ | $$$$$$$ |$$ |$$$$\ | ||
* $$ | $$ ____/ $$ |\_$$ | | ||
* $$ | $$\ $$ | $$ | $$ | | ||
* \$$$$$ |$$ | \$$$$$ | | ||
* \______/ \__| \______/ | ||
* | ||
*/ | ||
package de.fraunhofer.aisec.cpg.graph.edges.overlay | ||
|
||
import de.fraunhofer.aisec.cpg.graph.Node | ||
import de.fraunhofer.aisec.cpg.graph.edges.Edge | ||
import de.fraunhofer.aisec.cpg.graph.edges.collections.EdgeSet | ||
import de.fraunhofer.aisec.cpg.graph.edges.collections.EdgeSingletonList | ||
import de.fraunhofer.aisec.cpg.graph.edges.collections.MirroredEdgeCollection | ||
import kotlin.reflect.KProperty | ||
|
||
/** | ||
* Represents an edge in a graph specifically used for overlay purposes. | ||
* | ||
* @param start The starting node of the edge. | ||
* @param end The ending node of the edge. | ||
* @constructor Constructs an [OverlayEdge] with a specified [start] and [end] node. | ||
* @property labels A predefined set of labels associated with the OverlayEdge. By default, it is | ||
* initialized with the label "OVERLAY". | ||
*/ | ||
class OverlayEdge(start: Node, end: Node) : Edge<Node>(start, end) { | ||
override var labels: Set<String> = setOf("OVERLAY") | ||
} | ||
|
||
/** | ||
* Represents a single edge in an overlay graph structure, linking nodes with specific properties. | ||
* | ||
* @param thisRef The current node that the edge originates from or is associated with. | ||
* @param of The optional target node of the edge. | ||
* @param mirrorProperty The property representing a mutable collection of mirrored overlay edges. | ||
* @param outgoing A flag indicating whether the edge is outgoing (default is true). | ||
* @constructor Initializes the [OverlaySingleEdge] instance with the provided parameters. | ||
*/ | ||
class OverlaySingleEdge( | ||
thisRef: Node, | ||
of: Node?, | ||
override var mirrorProperty: KProperty<MutableCollection<OverlayEdge>>, | ||
outgoing: Boolean = true, | ||
) : | ||
EdgeSingletonList<Node, Node?, OverlayEdge>( | ||
thisRef = thisRef, | ||
init = ::OverlayEdge, | ||
outgoing = outgoing, | ||
of = of, | ||
), | ||
MirroredEdgeCollection<Node, OverlayEdge> | ||
|
||
/** | ||
* Represents a collection of overlay edges connected to a specific node. This class is used to | ||
* manage and define relationships between nodes through overlay edges, providing both outgoing and | ||
* incoming edge handling capabilities. | ||
* | ||
* @param thisRef The reference node that the overlays are associated with. | ||
* @param mirrorProperty A reference to a property that mirrors the collection of overlay edges. | ||
* @param outgoing A boolean indicating whether the edges managed by this collection are outgoing. | ||
* @constructor Initializes the [Overlays] object with a reference node, a property for edge | ||
* mirroring, and a direction to specify outgoing or incoming edges. | ||
*/ | ||
class Overlays( | ||
thisRef: Node, | ||
override var mirrorProperty: KProperty<MutableCollection<OverlayEdge>>, | ||
outgoing: Boolean, | ||
) : | ||
EdgeSet<Node, OverlayEdge>(thisRef = thisRef, init = ::OverlayEdge, outgoing = outgoing), | ||
MirroredEdgeCollection<Node, OverlayEdge> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.