Skip to content

Commit d6d1622

Browse files
committed
Binary: Make the instruction and varible tags parameters of transformations.
1 parent 3945cf5 commit d6d1622

16 files changed

Lines changed: 631 additions & 553 deletions

File tree

binary/ql/lib/semmle/code/binary/ast/ir/internal/Instruction0/Instruction.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
private import semmle.code.binary.ast.Location
22
private import codeql.util.Option
33
private import TranslatedElement
4-
private import semmle.code.binary.ast.ir.internal.InstructionTag
4+
private import semmle.code.binary.ast.ir.internal.Tags
5+
private import InstructionTag
56
private import semmle.code.binary.ast.ir.internal.Opcode as Opcode
67
private import Function
78
private import TranslatedInstruction
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import semmle.code.binary.ast.ir.internal.InstructionSig
22

33
module Instruction0 implements InstructionSig {
4-
import semmle.code.binary.ast.ir.internal.Instruction0.Instruction
5-
import semmle.code.binary.ast.ir.internal.Instruction0.Function
6-
import semmle.code.binary.ast.ir.internal.Instruction0.Operand
7-
import semmle.code.binary.ast.ir.internal.Instruction0.Variable
8-
import semmle.code.binary.ast.ir.internal.Instruction0.BasicBlock
4+
import Instruction
5+
import Function
6+
import Operand
7+
import Variable
8+
import BasicBlock
9+
import InstructionTag
10+
import VariableTag
911
}
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
private import codeql.util.Boolean
2+
private import semmle.code.binary.ast.ir.internal.Opcode
3+
4+
newtype TInstructionTag =
5+
SingleTag() or
6+
X86JumpInstrRefTag() or
7+
X86JumpTag() or
8+
X86CJumpInstrRefTag() or
9+
X86CJumpTag() or
10+
WriteTag() or
11+
InitFramePtrTag() or
12+
InitStackPtrTag() or
13+
TestAndTag() or
14+
TestZeroTag() or
15+
TestCmpTag() or
16+
ImmediateOperandConstTag() or
17+
MemoryOperandConstFactorTag() or
18+
MemoryOperandConstDisplacementTag() or
19+
MemoryOperandMulTag() or
20+
MemoryOperandAdd1Tag() or
21+
MemoryOperandAdd2Tag() or
22+
MemoryOperandLoadTag() or
23+
PushSubTag() or
24+
PushStoreTag() or
25+
PushSubConstTag() or
26+
PopAddTag() or
27+
PopAddConstTag() or
28+
PopLoadTag() or
29+
DecOrIncConstTag() or
30+
DecOrIncOpTag() or
31+
BtShiftTag() or
32+
BtAndTag() or
33+
BtCmpTag() or
34+
BtOneTag() or
35+
BtZeroTag() or
36+
BtrOneTag() or
37+
BtrShiftTag() or
38+
BtrNotTag() or
39+
BtrAndTag() or
40+
NegConstZeroTag() or
41+
NegSubTag() or
42+
CilLdcSizeTag() or
43+
CilLdcConstTag() or
44+
CilLdcSubTag() or
45+
CilLdcWriteTag() or
46+
CilStlocLoadTag() or
47+
CilStlocAddTag() or
48+
CilStlocConstTag() or
49+
CilRelSubTag() or
50+
CilRelCJumpTag() or
51+
CilRelConstTag(Boolean b) or
52+
CilRelRefTag() or
53+
CilBoolBranchRefTag() or
54+
CilBoolBranchSubTag() or
55+
CilBoolBranchConstTag() or
56+
CilBoolBranchCJumpTag() or
57+
CilUnconditionalBranchTag() or
58+
CilUnconditionalBranchRefTag()
59+
60+
class InstructionTag extends TInstructionTag {
61+
final string toString() {
62+
this = SingleTag() and
63+
result = "Single"
64+
or
65+
this = X86JumpInstrRefTag() and
66+
result = "X86JumpInstrRef"
67+
or
68+
this = X86JumpTag() and
69+
result = "X86Jump"
70+
or
71+
this = X86CJumpInstrRefTag() and
72+
result = "X86CJumpInstrRef"
73+
or
74+
this = X86CJumpTag() and
75+
result = "X86CJump"
76+
or
77+
this = WriteTag() and
78+
result = "Write"
79+
or
80+
this = InitFramePtrTag() and
81+
result = "InitFramePtr"
82+
or
83+
this = InitStackPtrTag() and
84+
result = "InitStackPtr"
85+
or
86+
this = TestAndTag() and
87+
result = "TestAnd"
88+
or
89+
this = TestZeroTag() and
90+
result = "TestZero"
91+
or
92+
this = TestCmpTag() and
93+
result = "TestCmp"
94+
or
95+
this = ImmediateOperandConstTag() and
96+
result = "ImmediateOperandConst"
97+
or
98+
this = MemoryOperandConstFactorTag() and
99+
result = "MemoryOperandConstFactor"
100+
or
101+
this = MemoryOperandConstDisplacementTag() and
102+
result = "MemoryOperandConstDisplacement"
103+
or
104+
this = MemoryOperandMulTag() and
105+
result = "MemoryOperandMul"
106+
or
107+
this = MemoryOperandAdd1Tag() and
108+
result = "MemoryOperandAdd1"
109+
or
110+
this = MemoryOperandAdd2Tag() and
111+
result = "MemoryOperandAdd2"
112+
or
113+
this = MemoryOperandLoadTag() and
114+
result = "MemoryOperandLoad"
115+
or
116+
this = PushSubTag() and
117+
result = "PushSub"
118+
or
119+
this = PushStoreTag() and
120+
result = "PushStore"
121+
or
122+
this = PushSubConstTag() and
123+
result = "PushSubConst"
124+
or
125+
this = PopAddTag() and
126+
result = "PopAdd"
127+
or
128+
this = PopAddConstTag() and
129+
result = "PopAddConst"
130+
or
131+
this = PopLoadTag() and
132+
result = "PopLoad"
133+
or
134+
this = DecOrIncConstTag() and
135+
result = "DecOrIncConst"
136+
or
137+
this = DecOrIncOpTag() and
138+
result = "DecOrIncOp"
139+
or
140+
this = BtrOneTag() and
141+
result = "BtrOne"
142+
or
143+
this = BtrShiftTag() and
144+
result = "BtrShift"
145+
or
146+
this = BtrNotTag() and
147+
result = "BtrNot"
148+
or
149+
this = BtrAndTag() and
150+
result = "BtrAnd"
151+
or
152+
this = NegConstZeroTag() and
153+
result = "NegConstZero"
154+
or
155+
this = NegSubTag() and
156+
result = "NegSub"
157+
or
158+
this = CilLdcConstTag() and
159+
result = "CilLdcConst"
160+
or
161+
this = CilLdcSizeTag() and
162+
result = "CilLdcSize"
163+
or
164+
this = CilLdcSubTag() and
165+
result = "CilLdcSub"
166+
or
167+
this = CilLdcWriteTag() and
168+
result = "CilLdcWrite"
169+
or
170+
this = CilStlocLoadTag() and
171+
result = "CilStlocLoad"
172+
or
173+
this = CilStlocAddTag() and
174+
result = "CilStlocAdd"
175+
or
176+
this = CilStlocConstTag() and
177+
result = "CilStlocConst"
178+
or
179+
this = CilRelSubTag() and
180+
result = "CilRelSub"
181+
or
182+
this = CilRelCJumpTag() and
183+
result = "CilRelCJump"
184+
or
185+
exists(boolean b |
186+
this = CilRelConstTag(b) and
187+
result = "CilRelConst(" + b.toString() + ")"
188+
)
189+
or
190+
this = CilRelRefTag() and
191+
result = "CilRelRef"
192+
or
193+
this = CilBoolBranchRefTag() and
194+
result = "CilBoolBranchRef"
195+
or
196+
this = CilBoolBranchSubTag() and
197+
result = "CilBoolBranchSub"
198+
or
199+
this = CilBoolBranchConstTag() and
200+
result = "CilBoolBranchConst"
201+
or
202+
this = CilBoolBranchCJumpTag() and
203+
result = "CilBoolBranchCJump"
204+
or
205+
this = CilUnconditionalBranchTag() and
206+
result = "CilUnconditionalBranch"
207+
or
208+
this = CilUnconditionalBranchRefTag() and
209+
result = "CilUnconditionalBranchRef"
210+
}
211+
}

binary/ql/lib/semmle/code/binary/ast/ir/internal/Instruction0/Operand.qll

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
private import semmle.code.binary.ast.Location
22
private import TranslatedElement
3-
private import semmle.code.binary.ast.ir.internal.InstructionTag as Tags
3+
private import semmle.code.binary.ast.ir.internal.Tags
4+
private import InstructionTag
45
private import Instruction
56
private import semmle.code.binary.ast.ir.internal.Opcode as Opcode
67
private import Function
@@ -10,14 +11,14 @@ private import codeql.controlflow.SuccessorType
1011
private import BasicBlock
1112

1213
newtype TOperand =
13-
MkOperand(TranslatedElement te, Tags::InstructionTag tag, Tags::OperandTag operandTag) {
14+
MkOperand(TranslatedElement te, InstructionTag tag, OperandTag operandTag) {
1415
exists(te.getVariableOperand(tag, operandTag))
1516
}
1617

1718
class Operand extends TOperand {
1819
TranslatedElement te;
19-
Tags::InstructionTag tag;
20-
Tags::TOperandTag operandTag;
20+
InstructionTag tag;
21+
TOperandTag operandTag;
2122

2223
Operand() { this = MkOperand(te, tag, operandTag) }
2324

@@ -37,35 +38,37 @@ class Operand extends TOperand {
3738
}
3839

3940
class StoreValueOperand extends Operand {
40-
override Tags::StoreValueTag operandTag;
41+
override StoreValueTag operandTag;
4142
}
4243

4344
class LeftOperand extends Operand {
44-
override Tags::LeftTag operandTag;
45+
override LeftTag operandTag;
4546
}
4647

4748
class RightOperand extends Operand {
48-
override Tags::RightTag operandTag;
49+
override RightTag operandTag;
4950
}
5051

5152
class StoreAddressOperand extends Operand {
52-
override Tags::StoreAddressTag operandTag;
53+
override StoreAddressTag operandTag;
5354
}
5455

5556
class UnaryOperand extends Operand {
56-
override Tags::UnaryTag operandTag;
57+
override UnaryTag operandTag;
5758
}
5859

5960
class ConditionOperand extends Operand {
60-
override Tags::CondTag operandTag;
61+
override CondTag operandTag;
6162
}
6263

6364
class ConditionJumpTargetOperand extends Operand {
64-
override Tags::CondJumpTargetTag operandTag;
65+
override CondJumpTargetTag operandTag;
6566
}
6667

6768
class JumpTargetOperand extends Operand {
68-
override Tags::JumpTargetTag operandTag;
69+
override JumpTargetTag operandTag;
6970
}
7071

72+
private import semmle.code.binary.ast.ir.internal.Tags as Tags
73+
7174
class OperandTag = Tags::OperandTag;

binary/ql/lib/semmle/code/binary/ast/ir/internal/Instruction0/TranslatedElement.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
private import semmle.code.binary.ast.instructions as Raw
22
private import codeql.controlflow.SuccessorType
3-
private import semmle.code.binary.ast.ir.internal.InstructionTag
3+
private import semmle.code.binary.ast.ir.internal.Tags
4+
private import InstructionTag
5+
private import VariableTag
46
private import Instruction
57
private import semmle.code.binary.ast.ir.internal.Opcode as Opcode
68
private import codeql.util.Either

binary/ql/lib/semmle/code/binary/ast/ir/internal/Instruction0/TranslatedFunction.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ private import semmle.code.binary.ast.ir.internal.Opcode as Opcode
55
private import Variable
66
private import Instruction
77
private import TranslatedInstruction
8-
private import semmle.code.binary.ast.ir.internal.InstructionTag
8+
private import semmle.code.binary.ast.ir.internal.Tags
9+
private import InstructionTag
910
private import codeql.controlflow.SuccessorType
1011

1112
abstract class TranslatedFunction extends TranslatedElement {

binary/ql/lib/semmle/code/binary/ast/ir/internal/Instruction0/TranslatedInstruction.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
private import semmle.code.binary.ast.instructions as Raw
22
private import TranslatedElement
33
private import semmle.code.binary.ast.ir.internal.Opcode as Opcode
4-
private import semmle.code.binary.ast.ir.internal.InstructionTag
4+
private import semmle.code.binary.ast.ir.internal.Tags
5+
private import InstructionTag
56
private import Instruction
67
private import Variable
78
private import TranslatedFunction
89
private import codeql.util.Option
910
private import TranslatedOperand
11+
private import VariableTag
1012
private import codeql.controlflow.SuccessorType
1113
private import codeql.util.Either
1214

binary/ql/lib/semmle/code/binary/ast/ir/internal/Instruction0/TranslatedOperand.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ private import semmle.code.binary.ast.instructions as Raw
22
private import TranslatedElement
33
private import codeql.util.Option
44
private import semmle.code.binary.ast.ir.internal.Opcode as Opcode
5-
private import semmle.code.binary.ast.ir.internal.InstructionTag
5+
private import semmle.code.binary.ast.ir.internal.Tags
6+
private import InstructionTag
67
private import TranslatedInstruction
78
private import Instruction
89
private import Operand
910
private import codeql.controlflow.SuccessorType
1011
private import Variable
12+
private import VariableTag
1113

1214
abstract class TranslatedOperand extends TranslatedElement {
1315
abstract TranslatedInstruction getUse();

0 commit comments

Comments
 (0)