|
| 1 | +# Specification: Data Flow Graph - Function Summaries |
| 2 | + |
| 3 | +For functions and methods which are part of the analyzed codebase, the CPG can track data flows interprocedurally to some extent. |
| 4 | +However, for all functions and methods which cannot be analyzed, we have no information available. |
| 5 | +For this case, we provide the user a way to specify custom summaries of the data flows through the function. |
| 6 | +To do so, you need to fill a JSON file as follows: |
| 7 | + |
| 8 | +* The outer element is a list/array |
| 9 | +* In this list, you add elements, each of which summarizes the flows for one function/method |
| 10 | +* The element consists of two objects: The `functionDeclaration` and the `dataFlows` |
| 11 | +* The `functionDeclaration` consists of: |
| 12 | + * `language`: The FQN of the `Language` element which this function is relevant for. |
| 13 | + * `methodName`: The FQN of the function or method. We use this one to identify the relevant function/method. Do not forget to add the class name and use the separators as specified by the `Language`. |
| 14 | + * `signature` (*optional*): This optional element allows us to differentiate between overloaded functions (i.e., two functions have the same FQN but accept different arguments). If no `signature` is specified, it matches to any function/method with the name you specified. The `signature` is a list of FQNs of the types (as strings) |
| 15 | +* The `dataFlows` element is a list of objects with the following elements: |
| 16 | + * `from`: A description of the start-node of a DFG-edge. Valid options: |
| 17 | + * `paramX`: where `X` is the offset (we start counting with 0) |
| 18 | + * `base`: the receiver of the method (i.e., the object the method is called on) |
| 19 | + * `to`: A description of the end-node of the DFG-edge. Valid options: |
| 20 | + * `paramX` where `X` is the offset (we start counting with 0) |
| 21 | + * `base` the receiver of the method (i.e., the object the method is called on) |
| 22 | + * `return` the return value of the function |
| 23 | + * `returnX` where `X` is a number and specifies the index of the return value (if multiple values are returned). |
| 24 | + * `dfgType`: Here, you can give more information. Currently, this is unused but should later allow us to add the properties to the edge. |
| 25 | + |
| 26 | +An example of a file could look as follows: |
| 27 | +```json |
| 28 | +[ |
| 29 | + { |
| 30 | + "functionDeclaration": { |
| 31 | + "language": "de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage", |
| 32 | + "methodName": "java.util.List.addAll", |
| 33 | + "signature": ["int", "java.util.Object"] |
| 34 | + }, |
| 35 | + "dataFlows": [ |
| 36 | + { |
| 37 | + "from": "param1", |
| 38 | + "to": "base", |
| 39 | + "dfgType": "full" |
| 40 | + } |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "functionDeclaration": { |
| 45 | + "language": "de.fraunhofer.aisec.cpg.frontends.java.JavaLanguage", |
| 46 | + "methodName": "java.util.List.addAll", |
| 47 | + "signature": ["java.util.Object"] |
| 48 | + }, |
| 49 | + "dataFlows": [ |
| 50 | + { |
| 51 | + "from": "param0", |
| 52 | + "to": "base", |
| 53 | + "dfgType": "full" |
| 54 | + } |
| 55 | + ] |
| 56 | + }, |
| 57 | + { |
| 58 | + "functionDeclaration": { |
| 59 | + "language": "de.fraunhofer.aisec.cpg.frontends.cxx.CLanguage", |
| 60 | + "methodName": "memcpy" |
| 61 | + }, |
| 62 | + "dataFlows": [ |
| 63 | + { |
| 64 | + "from": "param1", |
| 65 | + "to": "param0", |
| 66 | + "dfgType": "full" |
| 67 | + } |
| 68 | + ] |
| 69 | + } |
| 70 | +] |
| 71 | +``` |
| 72 | +This file configures the following edges: |
| 73 | +* For a method declaration in Java `java.util.List.addAll(int, java.util.Object)`, the parameter 1 flows to the base (i.e., the list object) |
| 74 | +* For a method declaration in Java `java.util.List.addAll(java.util.Object)`, the parameter 0 flows to the base (i.e., the list object) |
| 75 | +* For a function declaration in C `memcpy` (and thus also CXX `std::memcpy`), the parameter 1 flows to parameter 0. |
0 commit comments