Skip to content

Commit a238c01

Browse files
committed
Binary: Consistency queries for all stages.
1 parent 33753b6 commit a238c01

4 files changed

Lines changed: 51 additions & 15 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
private import semmle.code.binary.ast.ir.internal.Tags
2+
private import codeql.controlflow.SuccessorType
3+
private import semmle.code.binary.ast.ir.internal.InstructionSig
4+
5+
module StagedConsistencyInput<InstructionSig Input> {
6+
query predicate nonUniqueSuccessor(Input::Function f, Input::Instruction i, SuccessorType t, int k) {
7+
i.getEnclosingFunction() = f and
8+
k = strictcount(i.getSuccessor(t)) and
9+
k > 1
10+
}
11+
12+
query predicate nonUniqueResultVariable(Input::Function f, Input::Instruction i, int k) {
13+
i.getEnclosingFunction() = f and
14+
strictcount(i.getResultVariable()) = k and
15+
k > 1
16+
}
17+
18+
query predicate missingSuccessor(Input::Function f, Input::Instruction i) {
19+
i.getEnclosingFunction() = f and
20+
not i instanceof Input::RetInstruction and
21+
not i instanceof Input::RetValueInstruction and
22+
exists(i.getAPredecessor()) and
23+
not exists(i.getASuccessor())
24+
}
25+
}
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
private import TranslatedElement
1+
private import Instruction0
2+
import semmle.code.binary.ast.ir.internal.Consistency
3+
import StagedConsistencyInput<Instruction0>
24
private import TranslatedInstruction
3-
private import semmle.code.binary.ast.ir.internal.InstructionTag
4-
private import Instruction0::Instruction0
5-
private import codeql.controlflow.SuccessorType
6-
7-
query predicate nonUniqueSuccessor(Instruction i, SuccessorType t, int k) {
8-
k = strictcount(i.getSuccessor(t)) and
9-
k > 1
10-
}
11-
12-
query predicate nonUniqueResultVariable(Instruction i, int k) {
13-
strictcount(i.getResultVariable()) = k and
14-
k > 1
15-
}
5+
private import TranslatedFunction
6+
private import semmle.code.binary.ast.ir.internal.Opcode
7+
private import semmle.code.binary.ast.ir.internal.Tags
8+
private import InstructionTag
169

1710
query predicate nonUniqueOpcode(TranslatedInstruction ti, InstructionTag tag, int k) {
1811
strictcount(Opcode opcode | ti.hasInstruction(opcode, tag, _)) = k and
1912
k > 1
2013
}
2114

2215
query predicate nonUniqueVariableOperand(
23-
TranslatedInstruction ti, InstructionTag tag, OperandTag operandTag, int k
16+
TranslatedFunction tf, TranslatedInstruction ti, string s, InstructionTag tag,
17+
OperandTag operandTag, int k
2418
) {
19+
tf = ti.getEnclosingFunction() and
20+
s = concat(ti.getAQlClass().toString(), ", ") and
2521
strictcount(ti.getVariableOperand(tag, operandTag)) = k and
2622
k > 1
2723
}
24+
25+
query predicate nonUniqueResultVariable0(
26+
TranslatedFunction tf, TranslatedInstruction ti, string s, int k
27+
) {
28+
tf = ti.getEnclosingFunction() and
29+
s = concat(ti.getAQlClass().toString(), ", ") and
30+
strictcount(ti.getResultVariable()) = k and
31+
k > 1
32+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
private import Instruction1
2+
import semmle.code.binary.ast.ir.internal.Consistency
3+
import StagedConsistencyInput<Instruction1>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
private import Instruction2
2+
import semmle.code.binary.ast.ir.internal.Consistency
3+
import StagedConsistencyInput<Instruction2>

0 commit comments

Comments
 (0)