Skip to content

Commit 940f588

Browse files
committed
Add 'View DFG' queries for JS, Java, Ruby, C#, Rust
1 parent 3fd5e03 commit 940f588

File tree

5 files changed

+239
-0
lines changed

5 files changed

+239
-0
lines changed

csharp/ql/lib/printDfg.ql

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @name Print DFG
3+
* @description Produces a representation of a file's Data Flow Graph.
4+
* This query is used by the VS Code extension.
5+
* @id cs/print-dfg
6+
* @kind graph
7+
* @tags ide-contextual-queries/print-dfg
8+
*/
9+
10+
import csharp
11+
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific as DF
12+
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific as TT
13+
private import codeql.dataflow.PrintDfg
14+
private import MakePrintDfg<Location, DF::CsharpDataFlow, TT::CsharpTaintTracking>
15+
16+
external string selectedSourceFile();
17+
18+
private predicate selectedSourceFileAlias = selectedSourceFile/0;
19+
20+
external int selectedSourceLine();
21+
22+
private predicate selectedSourceLineAlias = selectedSourceLine/0;
23+
24+
external int selectedSourceColumn();
25+
26+
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
27+
28+
module ViewDfgQueryInput implements ViewGraphQueryInputSig<File> {
29+
predicate selectedSourceFile = selectedSourceFileAlias/0;
30+
31+
predicate selectedSourceLine = selectedSourceLineAlias/0;
32+
33+
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
34+
35+
predicate callableSpan(
36+
DF::CsharpDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn,
37+
int endLine, int endColumn
38+
) {
39+
exists(Callable c |
40+
c = callable.asCallable(_) and
41+
file = c.getFile() and
42+
callable.getLocation().getStartLine() = startLine and
43+
callable.getLocation().getStartColumn() = startColumn and
44+
exists(Location loc |
45+
loc.getEndLine() = endLine and
46+
loc.getEndColumn() = endColumn and
47+
loc = c.getBody().getLocation()
48+
)
49+
)
50+
}
51+
}
52+
53+
import ViewGraphQuery<File, ViewDfgQueryInput>

java/ql/lib/printDfg.ql

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @name Print DFG
3+
* @description Produces a representation of a file's Data Flow Graph.
4+
* This query is used by the VS Code extension.
5+
* @id java/print-cfg
6+
* @kind graph
7+
* @tags ide-contextual-queries/print-dfg
8+
*/
9+
10+
import java
11+
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific as DF
12+
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific as TT
13+
private import codeql.dataflow.PrintDfg
14+
private import MakePrintDfg<Location, DF::JavaDataFlow, TT::JavaTaintTracking>
15+
16+
external string selectedSourceFile();
17+
18+
private predicate selectedSourceFileAlias = selectedSourceFile/0;
19+
20+
external int selectedSourceLine();
21+
22+
private predicate selectedSourceLineAlias = selectedSourceLine/0;
23+
24+
external int selectedSourceColumn();
25+
26+
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
27+
28+
module ViewDfgQueryInput implements ViewGraphQueryInputSig<File> {
29+
predicate selectedSourceFile = selectedSourceFileAlias/0;
30+
31+
predicate selectedSourceLine = selectedSourceLineAlias/0;
32+
33+
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
34+
35+
predicate callableSpan(
36+
DF::JavaDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn,
37+
int endLine, int endColumn
38+
) {
39+
file = callable.asCallable().getFile() and
40+
callable.getLocation().getStartLine() = startLine and
41+
callable.getLocation().getStartColumn() = startColumn and
42+
exists(Location loc |
43+
loc.getEndLine() = endLine and
44+
loc.getEndColumn() = endColumn and
45+
loc = callable.asCallable().getBody().getLocation()
46+
)
47+
}
48+
}
49+
50+
import ViewGraphQuery<File, ViewDfgQueryInput>

javascript/ql/lib/printDfg.ql

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @name Print DFG
3+
* @description Produces a representation of a file's Data Flow Graph.
4+
* This query is used by the VS Code extension.
5+
* @id js/print-dfg
6+
* @kind graph
7+
* @tags ide-contextual-queries/print-dfg
8+
*/
9+
10+
private import javascript
11+
private import semmle.javascript.dataflow.internal.sharedlib.DataFlowArg
12+
private import codeql.dataflow.PrintDfg
13+
import MakePrintDfg<Location, JSDataFlow, JSTaintFlow>
14+
15+
external string selectedSourceFile();
16+
17+
private predicate selectedSourceFileAlias = selectedSourceFile/0;
18+
19+
external int selectedSourceLine();
20+
21+
private predicate selectedSourceLineAlias = selectedSourceLine/0;
22+
23+
external int selectedSourceColumn();
24+
25+
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
26+
27+
module ViewGraphInput implements ViewGraphQueryInputSig<File> {
28+
predicate selectedSourceFile = selectedSourceFileAlias/0;
29+
30+
predicate selectedSourceLine = selectedSourceLineAlias/0;
31+
32+
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
33+
34+
/**
35+
* Holds if `callable` spans column `startColumn` of line `startLine` to
36+
* column `endColumn` of line `endLine` in `file`.
37+
*/
38+
predicate callableSpan(
39+
JSDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn, int endLine,
40+
int endColumn
41+
) {
42+
callable
43+
.getLocation()
44+
.hasLocationInfo(file.getAbsolutePath(), startLine, startColumn, endLine, endColumn)
45+
}
46+
}
47+
48+
import ViewGraphQuery<File, ViewGraphInput>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @name Print DFG
3+
* @description Produces a representation of a file's Data Flow Graph.
4+
* This query is used by the VS Code extension.
5+
* @id rb/print-dfg
6+
* @kind graph
7+
* @tags ide-contextual-queries/print-dfg
8+
*/
9+
10+
private import codeql.Locations
11+
private import codeql.ruby.dataflow.internal.DataFlowImplSpecific as DF
12+
private import codeql.ruby.dataflow.internal.TaintTrackingImplSpecific as TT
13+
private import codeql.dataflow.PrintDfg
14+
private import MakePrintDfg<Location, DF::RubyDataFlow, TT::RubyTaintTracking>
15+
16+
external string selectedSourceFile();
17+
18+
private predicate selectedSourceFileAlias = selectedSourceFile/0;
19+
20+
external int selectedSourceLine();
21+
22+
private predicate selectedSourceLineAlias = selectedSourceLine/0;
23+
24+
external int selectedSourceColumn();
25+
26+
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
27+
28+
module ViewDfgQueryInput implements ViewGraphQueryInputSig<File> {
29+
predicate selectedSourceFile = selectedSourceFileAlias/0;
30+
31+
predicate selectedSourceLine = selectedSourceLineAlias/0;
32+
33+
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
34+
35+
predicate callableSpan(
36+
DF::RubyDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn,
37+
int endLine, int endColumn
38+
) {
39+
file = callable.asCfgScope().getFile() and
40+
callable.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
41+
}
42+
}
43+
44+
import ViewGraphQuery<File, ViewDfgQueryInput>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @name Print DFG
3+
* @description Produces a representation of a file's Data Flow Graph.
4+
* This query is used by the VS Code extension.
5+
* @id rust/print-dfg
6+
* @kind graph
7+
* @tags ide-contextual-queries/print-dfg
8+
*/
9+
10+
private import rust
11+
private import codeql.rust.dataflow.internal.DataFlowImpl as DF
12+
private import codeql.rust.dataflow.internal.TaintTrackingImpl as TT
13+
private import codeql.dataflow.PrintDfg
14+
private import MakePrintDfg<Location, DF::RustDataFlow, TT::RustTaintTracking>
15+
16+
external string selectedSourceFile();
17+
18+
private predicate selectedSourceFileAlias = selectedSourceFile/0;
19+
20+
external int selectedSourceLine();
21+
22+
private predicate selectedSourceLineAlias = selectedSourceLine/0;
23+
24+
external int selectedSourceColumn();
25+
26+
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
27+
28+
private module ViewDfgQueryInput implements ViewGraphQueryInputSig<File> {
29+
predicate selectedSourceFile = selectedSourceFileAlias/0;
30+
31+
predicate selectedSourceLine = selectedSourceLineAlias/0;
32+
33+
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
34+
35+
predicate callableSpan(
36+
DF::RustDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn,
37+
int endLine, int endColumn
38+
) {
39+
file = callable.asCfgScope().getFile() and
40+
callable.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
41+
}
42+
}
43+
44+
import ViewGraphQuery<File, ViewDfgQueryInput>

0 commit comments

Comments
 (0)