Skip to content

Commit 9f09b0d

Browse files
committed
more wip
1 parent 42b01bf commit 9f09b0d

35 files changed

+479
-7852
lines changed

csharp/ql/campaigns/Solorigate/src/ModifiedFnvFunctionDetection.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ import csharp
1313
import Solorigate
1414
import experimental.code.csharp.Cryptography.NonCryptographicHashes
1515

16+
ControlFlowNode loopExitNode(LoopStmt loop) { result.isAfter(loop) }
17+
1618
from Variable v, Literal l, LoopStmt loop, Expr additional_xor
1719
where
1820
maybeUsedInFnvFunction(v, _, _, loop) and
1921
(
2022
exists(BitwiseXorExpr xor2 | xor2.getAnOperand() = l and additional_xor = xor2 |
21-
loop.getAControlFlowExitNode().getASuccessor*() = xor2.getAControlFlowNode() and
23+
loopExitNode(loop).getASuccessor*() = xor2.getAControlFlowNode() and
2224
xor2.getAnOperand() = v.getAnAccess()
2325
)
2426
or
2527
exists(AssignXorExpr xor2 | xor2.getAnOperand() = l and additional_xor = xor2 |
26-
loop.getAControlFlowExitNode().getASuccessor*() = xor2.getAControlFlowNode() and
28+
loopExitNode(loop).getASuccessor*() = xor2.getAControlFlowNode() and
2729
xor2.getAnOperand() = v.getAnAccess()
2830
)
2931
)
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
import csharp
2-
import semmle.code.csharp.controlflow.internal.Completion
3-
import ControlFlow
4-
import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl::Consistency
5-
import semmle.code.csharp.controlflow.internal.Splitting
2+
import ControlFlow::Consistency

csharp/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
import csharp
2-
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl as ControlFlowGraphImpl
32
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
43
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific
54
private import codeql.dataflow.internal.DataFlowImplConsistency
65

76
private module Input implements InputSig<Location, CsharpDataFlow> {
87
private import CsharpDataFlow
98

10-
private predicate isStaticAssignable(Assignable a) { a.(Modifiable).isStatic() }
11-
12-
predicate uniqueEnclosingCallableExclude(Node node) {
13-
// TODO: Remove once static initializers are folded into the
14-
// static constructors
15-
isStaticAssignable(ControlFlowGraphImpl::getNodeCfgScope(node.getControlFlowNode()))
16-
}
17-
18-
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) {
19-
// TODO: Remove once static initializers are folded into the
20-
// static constructors
21-
isStaticAssignable(ControlFlowGraphImpl::getNodeCfgScope(call.getControlFlowNode()))
22-
}
23-
249
predicate uniqueNodeLocationExclude(Node n) {
2510
// Methods with multiple implementations
2611
n instanceof ParameterNode
@@ -70,16 +55,6 @@ private module Input implements InputSig<Location, CsharpDataFlow> {
7055
init.getInitializer().getNumberOfChildren() > 1
7156
)
7257
or
73-
exists(ControlFlowNodes::ElementNode cfn, ControlFlowNodes::Split split |
74-
exists(arg.asExprAtNode(cfn))
75-
|
76-
split = cfn.getASplit() and
77-
not split = call.getControlFlowNode().getASplit()
78-
or
79-
split = call.getControlFlowNode().getASplit() and
80-
not split = cfn.getASplit()
81-
)
82-
or
8358
call.(NonDelegateDataFlowCall).getDispatchCall().isReflection()
8459
)
8560
}

csharp/ql/consistency-queries/VariableCaptureConsistency.ql

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import csharp
22
import semmle.code.csharp.dataflow.internal.DataFlowPrivate::VariableCapture::Flow::ConsistencyChecks
33
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate::VariableCapture::Flow::ConsistencyChecks as ConsistencyChecks
4-
private import semmle.code.csharp.controlflow.BasicBlocks
5-
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl
6-
7-
query predicate uniqueEnclosingCallable(BasicBlock bb, string msg) {
8-
ConsistencyChecks::uniqueEnclosingCallable(bb, msg) and
9-
getNodeCfgScope(bb.getFirstNode()) instanceof Callable
10-
}
114

125
query predicate consistencyOverview(string msg, int n) { none() }
136

csharp/ql/lib/printCfg.ql

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
* @tags ide-contextual-queries/print-cfg
88
*/
99

10-
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl
11-
private import semmle.code.csharp.controlflow.ControlFlowGraph2 as C2
10+
import csharp
1211

1312
external string selectedSourceFile();
1413

@@ -22,17 +21,15 @@ external int selectedSourceColumn();
2221

2322
private predicate selectedSourceColumnAlias = selectedSourceColumn/0;
2423

25-
module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
26-
// module ViewCfgQueryInput implements C2::ControlFlow::ViewCfgQueryInputSig<File> {
24+
module ViewCfgQueryInput implements ControlFlow::ViewCfgQueryInputSig<File> {
2725
predicate selectedSourceFile = selectedSourceFileAlias/0;
2826

2927
predicate selectedSourceLine = selectedSourceLineAlias/0;
3028

3129
predicate selectedSourceColumn = selectedSourceColumnAlias/0;
3230

3331
predicate cfgScopeSpan(
34-
CfgScope scope, File file, int startLine, int startColumn, int endLine, int endColumn
35-
// Callable scope, File file, int startLine, int startColumn, int endLine, int endColumn
32+
Callable scope, File file, int startLine, int startColumn, int endLine, int endColumn
3633
) {
3734
file = scope.getFile() and
3835
scope.getLocation().getStartLine() = startLine and
@@ -42,13 +39,21 @@ module ViewCfgQueryInput implements ViewCfgQueryInputSig<File> {
4239
loc.getEndColumn() = endColumn
4340
|
4441
loc = scope.(Callable).getBody().getLocation()
45-
// or
46-
// loc = scope.(Field).getInitializer().getLocation()
47-
// or
48-
// loc = scope.(Property).getInitializer().getLocation()
42+
or
43+
loc = any(AssignExpr init | scope.(ObjectInitMethod).initializes(init)).getLocation()
44+
or
45+
exists(AssignableMember a, Constructor ctor |
46+
scope = ctor and
47+
ctor.isStatic() and
48+
a.isStatic() and
49+
a.getDeclaringType() = ctor.getDeclaringType()
50+
|
51+
loc = a.(Field).getInitializer().getLocation()
52+
or
53+
loc = a.(Property).getInitializer().getLocation()
54+
)
4955
)
5056
}
5157
}
5258

53-
import ViewCfgQuery<File, ViewCfgQueryInput>
54-
// import C2::ControlFlow::ViewCfgQuery<File, ViewCfgQueryInput>
59+
import ControlFlow::ViewCfgQuery<File, ViewCfgQueryInput>

csharp/ql/lib/semmle/code/csharp/Caching.qll

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,6 @@ private import csharp
77
* in the same stage across different files.
88
*/
99
module Stages {
10-
cached
11-
module ControlFlowStage {
12-
private import semmle.code.csharp.controlflow.internal.Splitting
13-
14-
cached
15-
predicate forceCachingInSameStage() { any() }
16-
17-
cached
18-
private predicate forceCachingInSameStageRev() {
19-
exists(Split s)
20-
or
21-
exists(ControlFlowNode n)
22-
or
23-
forceCachingInSameStageRev()
24-
}
25-
}
26-
2710
cached
2811
module GuardsStage {
2912
private import semmle.code.csharp.controlflow.Guards

0 commit comments

Comments
 (0)