Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions csharp/ql/lib/printDfg.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @name Print DFG
* @description Produces a representation of a file's Data Flow Graph.
* This query is used by the VS Code extension.
* @id cs/print-dfg
* @kind graph
* @tags ide-contextual-queries/print-dfg
*/

import csharp
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific as DF
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific as TT
private import codeql.dataflow.PrintDfg
private import MakePrintDfg<Location, DF::CsharpDataFlow, TT::CsharpTaintTracking>

external string selectedSourceFile();

private predicate selectedSourceFileAlias = selectedSourceFile/0;

external int selectedSourceLine();

private predicate selectedSourceLineAlias = selectedSourceLine/0;

external int selectedSourceColumn();

private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

module ViewDfgQueryInput implements ViewGraphQueryInputSig<File> {
predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

predicate callableSpan(
DF::CsharpDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn,
int endLine, int endColumn
) {
exists(Callable c |
c = callable.asCallable(_) and
file = c.getFile() and
callable.getLocation().getStartLine() = startLine and
callable.getLocation().getStartColumn() = startColumn and
exists(Location loc |
loc.getEndLine() = endLine and
loc.getEndColumn() = endColumn and
loc = c.getBody().getLocation()
)
)
}
}

import ViewGraphQuery<File, ViewDfgQueryInput>
7 changes: 4 additions & 3 deletions java/ql/lib/printCfg.ql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import java
import PrintCfg

external string selectedSourceFile();

Expand All @@ -21,14 +22,14 @@ external int selectedSourceColumn();

private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
module ViewCfgQueryInput implements ViewGraphQueryInputSig<File> {
predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

predicate cfgScopeSpan(
predicate callableSpan(
Callable callable, File file, int startLine, int startColumn, int endLine, int endColumn
) {
file = callable.getFile() and
Expand All @@ -42,4 +43,4 @@ module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
}
}

import ViewCfgQuery<File, ViewCfgQueryInput>
import ViewGraphQuery<File, ViewCfgQueryInput>
50 changes: 50 additions & 0 deletions java/ql/lib/printDfg.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @name Print DFG
* @description Produces a representation of a file's Data Flow Graph.
* This query is used by the VS Code extension.
* @id java/print-cfg
* @kind graph
* @tags ide-contextual-queries/print-dfg
*/

import java
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific as DF
private import semmle.code.java.dataflow.internal.TaintTrackingImplSpecific as TT
private import codeql.dataflow.PrintDfg
private import MakePrintDfg<Location, DF::JavaDataFlow, TT::JavaTaintTracking>

external string selectedSourceFile();

private predicate selectedSourceFileAlias = selectedSourceFile/0;

external int selectedSourceLine();

private predicate selectedSourceLineAlias = selectedSourceLine/0;

external int selectedSourceColumn();

private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

module ViewDfgQueryInput implements ViewGraphQueryInputSig<File> {
predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

predicate callableSpan(
DF::JavaDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn,
int endLine, int endColumn
) {
file = callable.asCallable().getFile() and
callable.getLocation().getStartLine() = startLine and
callable.getLocation().getStartColumn() = startColumn and
exists(Location loc |
loc.getEndLine() = endLine and
loc.getEndColumn() = endColumn and
loc = callable.asCallable().getBody().getLocation()
)
}
}

import ViewGraphQuery<File, ViewDfgQueryInput>
20 changes: 16 additions & 4 deletions java/ql/lib/semmle/code/java/ControlFlowGraph.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1776,16 +1776,28 @@ class ConditionNode extends ControlFlow::Node {
ExprParent getCondition() { result = this.asExpr() or result = this.asStmt() }
}

private import codeql.controlflow.PrintGraph as PrintGraph
private import codeql.util.PrintGraph as PrintGraph

private module PrintGraphInput implements PrintGraph::InputSig<Location> {
private import java as J

class Callable = J::Callable;

class ControlFlowNode = J::ControlFlowNode;
final private class FinalControlFlowNode = J::ControlFlowNode;

ControlFlowNode getASuccessor(ControlFlowNode n, SuccessorType t) { result = n.getASuccessor(t) }
class Node extends FinalControlFlowNode {
string getOrderDisambiguation() { result = "" }
}

predicate edge(Node node1, string s, Node node2) {
exists(SuccessorType t |
node2 = node1.getASuccessor(t) and
if t instanceof DirectSuccessor then s = "" else s = t.toString()
)
}
}

import PrintGraph::PrintGraph<Location, PrintGraphInput>
/** Provides utilities for visualising the CFG. */
module PrintCfg {
import PrintGraph::PrintGraph<Location, PrintGraphInput>
}
48 changes: 48 additions & 0 deletions javascript/ql/lib/printDfg.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @name Print DFG
* @description Produces a representation of a file's Data Flow Graph.
* This query is used by the VS Code extension.
* @id js/print-dfg
* @kind graph
* @tags ide-contextual-queries/print-dfg
*/

private import javascript
private import semmle.javascript.dataflow.internal.sharedlib.DataFlowArg
private import codeql.dataflow.PrintDfg
import MakePrintDfg<Location, JSDataFlow, JSTaintFlow>

external string selectedSourceFile();

Check warning

Code scanning / CodeQL

Dead code Warning

This code is never used, and it's not publicly exported.

private predicate selectedSourceFileAlias = selectedSourceFile/0;

Check warning

Code scanning / CodeQL

Dead code Warning

This code is never used, and it's not publicly exported.

external int selectedSourceLine();

Check warning

Code scanning / CodeQL

Dead code Warning

This code is never used, and it's not publicly exported.

private predicate selectedSourceLineAlias = selectedSourceLine/0;

Check warning

Code scanning / CodeQL

Dead code Warning

This code is never used, and it's not publicly exported.

external int selectedSourceColumn();

Check warning

Code scanning / CodeQL

Dead code Warning

This code is never used, and it's not publicly exported.

private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

Check warning

Code scanning / CodeQL

Dead code Warning

This code is never used, and it's not publicly exported.

module ViewCfgQueryInput implements ViewGraphQueryInputSig<File> {

Check warning

Code scanning / CodeQL

Dead code Warning

This code is never used, and it's not publicly exported.
predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

/**
* Holds if `callable` spans column `startColumn` of line `startLine` to
* column `endColumn` of line `endLine` in `file`.
*/
predicate callableSpan(
JSDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn, int endLine,
int endColumn
) {
callable
.getLocation()
.hasLocationInfo(file.getAbsolutePath(), startLine, startColumn, endLine, endColumn)
}
}

import ViewGraphQuery<File, ViewGraphInput>
7 changes: 4 additions & 3 deletions ruby/ql/lib/ide-contextual-queries/printCfg.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
private import codeql.Locations
private import codeql.ruby.controlflow.internal.ControlFlowGraphImpl
private import codeql.ruby.controlflow.ControlFlowGraph
private import PrintCfg

external string selectedSourceFile();

Expand All @@ -23,19 +24,19 @@

private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
module ViewCfgQueryInput implements ViewGraphQueryInputSig<File> {
predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

predicate cfgScopeSpan(
predicate callableSpan(

Check warning

Code scanning / CodeQL

Dead code Warning

This code is never used, and it's not publicly exported.
CfgScope scope, File file, int startLine, int startColumn, int endLine, int endColumn
) {
file = scope.getFile() and
scope.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
}
}

import ViewCfgQuery<File, ViewCfgQueryInput>
import ViewGraphQuery<File, ViewCfgQueryInput>
44 changes: 44 additions & 0 deletions ruby/ql/lib/ide-contextual-queries/printDfg.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @name Print DFG
* @description Produces a representation of a file's Data Flow Graph.
* This query is used by the VS Code extension.
* @id rb/print-dfg
* @kind graph
* @tags ide-contextual-queries/print-dfg
*/

private import codeql.Locations
private import codeql.ruby.dataflow.internal.DataFlowImplSpecific as DF
private import codeql.ruby.dataflow.internal.TaintTrackingImplSpecific as TT
private import codeql.dataflow.PrintDfg
private import MakePrintDfg<Location, DF::RubyDataFlow, TT::RubyTaintTracking>

external string selectedSourceFile();

private predicate selectedSourceFileAlias = selectedSourceFile/0;

external int selectedSourceLine();

private predicate selectedSourceLineAlias = selectedSourceLine/0;

external int selectedSourceColumn();

private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

module ViewDfgQueryInput implements ViewGraphQueryInputSig<File> {
predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

predicate callableSpan(
DF::RubyDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn,
int endLine, int endColumn
) {
file = callable.asCfgScope().getFile() and
callable.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
}
}

import ViewGraphQuery<File, ViewDfgQueryInput>
7 changes: 4 additions & 3 deletions rust/ql/lib/ide-contextual-queries/PrintCfg.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
private import codeql.files.FileSystem
private import codeql.rust.controlflow.internal.ControlFlowGraphImpl
private import codeql.rust.controlflow.ControlFlowGraph
private import PrintCfg

/**
* Gets the source file to generate a CFG from.
Expand All @@ -32,19 +33,19 @@ external int selectedSourceColumn();

private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

private module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
private module ViewCfgQueryInput implements ViewGraphQueryInputSig<File> {
predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

predicate cfgScopeSpan(
predicate callableSpan(
CfgScope scope, File file, int startLine, int startColumn, int endLine, int endColumn
) {
file = scope.getFile() and
scope.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
}
}

import ViewCfgQuery<File, ViewCfgQueryInput>
import ViewGraphQuery<File, ViewCfgQueryInput>
44 changes: 44 additions & 0 deletions rust/ql/lib/ide-contextual-queries/PrintDfg.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @name Print DFG
* @description Produces a representation of a file's Data Flow Graph.
* This query is used by the VS Code extension.
* @id rust/print-dfg
* @kind graph
* @tags ide-contextual-queries/print-dfg
*/

private import rust
private import codeql.rust.dataflow.internal.DataFlowImpl as DF
private import codeql.rust.dataflow.internal.TaintTrackingImpl as TT
private import codeql.dataflow.PrintDfg
private import MakePrintDfg<Location, DF::RustDataFlow, TT::RustTaintTracking>

external string selectedSourceFile();

private predicate selectedSourceFileAlias = selectedSourceFile/0;

external int selectedSourceLine();

private predicate selectedSourceLineAlias = selectedSourceLine/0;

external int selectedSourceColumn();

private predicate selectedSourceColumnAlias = selectedSourceColumn/0;

private module ViewDfgQueryInput implements ViewGraphQueryInputSig<File> {
predicate selectedSourceFile = selectedSourceFileAlias/0;

predicate selectedSourceLine = selectedSourceLineAlias/0;

predicate selectedSourceColumn = selectedSourceColumnAlias/0;

predicate callableSpan(
DF::RustDataFlow::DataFlowCallable callable, File file, int startLine, int startColumn,
int endLine, int endColumn
) {
file = callable.asCfgScope().getFile() and
callable.getLocation().hasLocationInfo(_, startLine, startColumn, endLine, endColumn)
}
}

import ViewGraphQuery<File, ViewDfgQueryInput>
Loading
Loading