Skip to content

Commit 7de93f0

Browse files
committed
X86: Prefix X86 specific entities with 'x86'.
1 parent 5c3bb6a commit 7de93f0

9 files changed

Lines changed: 2298 additions & 2298 deletions

File tree

binary/ql/lib/binary.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ import semmle.code.binary.ast.instructions
22
import semmle.code.binary.ast.Location
33
import semmle.code.binary.ast.Sections
44
import semmle.code.binary.ast.Headers
5-
import semmle.code.binary.ast.Functions

binary/ql/lib/semmle/code/binary/ast/Functions.qll

Lines changed: 0 additions & 25 deletions
This file was deleted.

binary/ql/lib/semmle/code/binary/ast/instructions.qll

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ private import internal.instructions as Internal
22
private import binary
33
private import Headers
44
private import Sections
5-
private import Functions
65
private import codeql.util.Unit
76

87
private class TElement = @x86_instruction or @operand;
98

109
class Element extends TElement {
10+
final string toString() { none() }
11+
}
12+
13+
private class X86InstructionElement extends Element {
1114
final string toString() {
1215
exists(string sInstr |
1316
instruction_string(this, sInstr) and
@@ -19,25 +22,23 @@ class Element extends TElement {
1922
sOp, ", " order by i
2023
)
2124
)
22-
or
23-
operand_string(this, result)
2425
}
26+
}
2527

26-
Element getNext() {
27-
exists(int a, int b, int length |
28-
instruction(this, a, b, _) and
29-
instruction_length(this, length) and
30-
instruction(result, a, b + length, _)
31-
)
32-
}
28+
private class X86OperandElement extends Element {
29+
final string toString() { operand_string(this, result) }
30+
}
31+
32+
private class IlInstructionElement extends Element {
33+
final string toString() { instruction_string(this, result) }
3334
}
3435

3536
private module Pre {
3637
module PreInput implements Internal::InstructionInputSig {
37-
class BaseInstruction extends Internal::Instruction {
38+
class BaseX86Instruction extends Internal::X86Instruction {
3839
private string toString0() { instruction_string(this, result) }
3940

40-
string toString() {
41+
override string toString() {
4142
if exists(this.getAnOperand())
4243
then
4344
result =
@@ -47,66 +48,66 @@ private module Pre {
4748
}
4849
}
4950

50-
class BaseRegister extends Internal::Register { }
51+
class BaseX86Register extends Internal::X86Register { }
5152

52-
class BaseRipRegister extends BaseRegister, Internal::RipRegister { }
53+
class BaseRipRegister extends BaseX86Register, Internal::RipRegister { }
5354

54-
class BaseRspRegister extends BaseRegister, Internal::RspRegister { }
55+
class BaseRspRegister extends BaseX86Register, Internal::RspRegister { }
5556

56-
class BaseRbpRegister extends BaseRegister, Internal::RbpRegister { }
57+
class BaseRbpRegister extends BaseX86Register, Internal::RbpRegister { }
5758

58-
class BaseOperand extends Internal::Operand { }
59+
class BaseX86Operand extends Internal::X86Operand { }
5960

60-
class BaseRegisterAccess extends Internal::RegisterAccess {
61-
BaseRegister getTarget() { result = super.getTarget() }
61+
class BaseX86RegisterAccess extends Internal::X86RegisterAccess {
62+
BaseX86Register getTarget() { result = super.getTarget() }
6263
}
6364

64-
class BaseUnusedOperand extends BaseOperand, Internal::UnusedOperand { }
65+
class BaseX86UnusedOperand extends BaseX86Operand, Internal::X86UnusedOperand { }
6566

66-
class BaseRegisterOperand extends BaseOperand, Internal::RegisterOperand {
67-
BaseRegisterAccess getAccess() { result = super.getAccess() }
67+
class BaseX86RegisterOperand extends BaseX86Operand, Internal::X86RegisterOperand {
68+
BaseX86RegisterAccess getAccess() { result = super.getAccess() }
6869
}
6970

70-
class BasePointerOperand extends BaseOperand, Internal::PointerOperand { }
71+
class BaseX86PointerOperand extends BaseX86Operand, Internal::X86PointerOperand { }
7172

72-
class BaseImmediateOperand extends BaseOperand, Internal::ImmediateOperand { }
73+
class BaseX86ImmediateOperand extends BaseX86Operand, Internal::X86ImmediateOperand { }
7374

74-
abstract private class MyCall extends BaseInstruction instanceof Internal::Call {
75-
Internal::Operand op;
75+
abstract private class MyCall extends BaseX86Instruction instanceof Internal::X86Call {
76+
Internal::X86Operand op;
7677

7778
MyCall() { op = this.getOperand(0) }
7879

79-
abstract Internal::Instruction getTarget();
80+
abstract Internal::X86Instruction getTarget();
8081
}
8182

8283
private class CallImmediate extends MyCall {
83-
override Internal::ImmediateOperand op;
84-
BaseInstruction target;
84+
override Internal::X86ImmediateOperand op;
85+
BaseX86Instruction target;
8586

8687
CallImmediate() {
8788
op.isRelative() and
8889
op.getValue().toBigInt() + this.getIndex() + this.getLength().toBigInt() = target.getIndex()
8990
}
9091

91-
override Internal::Instruction getTarget() { result = target }
92+
override Internal::X86Instruction getTarget() { result = target }
9293
}
9394

94-
class BaseMemoryOperand extends Operand instanceof Internal::MemoryOperand {
95+
class BaseX86MemoryOperand extends X86Operand instanceof Internal::X86MemoryOperand {
9596
predicate hasDisplacement() { super.hasDisplacement() }
9697

97-
BaseRegisterAccess getSegmentRegister() { result = super.getSegmentRegister() }
98+
BaseX86RegisterAccess getSegmentRegister() { result = super.getSegmentRegister() }
9899

99-
BaseRegisterAccess getBaseRegister() { result = super.getBaseRegister() }
100+
BaseX86RegisterAccess getBaseRegister() { result = super.getBaseRegister() }
100101

101-
BaseRegisterAccess getIndexRegister() { result = super.getIndexRegister() }
102+
BaseX86RegisterAccess getIndexRegister() { result = super.getIndexRegister() }
102103

103104
int getScaleFactor() { result = super.getScaleFactor() }
104105

105106
int getDisplacementValue() { result = super.getDisplacementValue() }
106107
}
107108

108109
private class CallConstantMemoryOperand extends MyCall {
109-
override Internal::MemoryOperand op;
110+
override Internal::X86MemoryOperand op;
110111
int displacement;
111112

112113
CallConstantMemoryOperand() {
@@ -115,7 +116,7 @@ private module Pre {
115116
displacement = op.getDisplacementValue()
116117
}
117118

118-
final override BaseInstruction getTarget() {
119+
final override BaseX86Instruction getTarget() {
119120
exists(
120121
QlBuiltins::BigInt rip, QlBuiltins::BigInt effectiveVA,
121122
QlBuiltins::BigInt offsetWithinSection, RDataSection rdata, QlBuiltins::BigInt address
@@ -129,24 +130,24 @@ private module Pre {
129130
}
130131
}
131132

132-
BaseInstruction getCallTarget(BaseInstruction b) { result = b.(MyCall).getTarget() }
133+
BaseX86Instruction getCallTarget(BaseX86Instruction b) { result = b.(MyCall).getTarget() }
133134

134-
abstract private class MyJumping extends BaseInstruction instanceof Internal::JumpingInstruction
135+
abstract private class MyJumping extends BaseX86Instruction instanceof Internal::X86JumpingInstruction
135136
{
136-
abstract BaseInstruction getTarget();
137+
abstract BaseX86Instruction getTarget();
137138
}
138139

139140
private class ImmediateRelativeJumping extends MyJumping {
140-
ImmediateOperand op;
141+
X86ImmediateOperand op;
141142

142143
ImmediateRelativeJumping() { op = this.getOperand(0) and op.isRelative() }
143144

144-
final override BaseInstruction getTarget() {
145+
final override BaseX86Instruction getTarget() {
145146
op.getValue().toBigInt() + this.getIndex() + this.getLength().toBigInt() = result.getIndex()
146147
}
147148
}
148149

149-
BaseInstruction getJumpTarget(BaseInstruction b) { result = b.(MyJumping).getTarget() }
150+
BaseX86Instruction getJumpTarget(BaseX86Instruction b) { result = b.(MyJumping).getTarget() }
150151
}
151152

152153
import Internal::MakeInstructions<PreInput> as Instructions
@@ -161,77 +162,81 @@ private int getOffsetOfAnExportedFunction() {
161162
}
162163

163164
private module Input implements Internal::InstructionInputSig {
164-
private class ProgramEntryInstruction0 extends Pre::Instructions::Instruction {
165+
private class ProgramEntryInstruction0 extends Pre::Instructions::X86Instruction {
165166
ProgramEntryInstruction0() { this.getIndex() = getOffsetOfEntryPoint().toBigInt() }
166167
}
167168

168-
private class ExportedInstruction0 extends Pre::Instructions::Instruction {
169+
private class ExportedInstruction0 extends Pre::Instructions::X86Instruction {
169170
ExportedInstruction0() { this.getIndex() = getOffsetOfAnExportedFunction().toBigInt() }
170171
}
171172

172-
private predicate fwd(Pre::Instructions::Instruction i) {
173+
private predicate fwd(Pre::Instructions::X86Instruction i) {
173174
i instanceof ProgramEntryInstruction0
174175
or
175176
i instanceof ExportedInstruction0
176177
or
177-
exists(Pre::Instructions::Instruction i0 | fwd(i0) |
178+
exists(Pre::Instructions::X86Instruction i0 | fwd(i0) |
178179
i0.getASuccessor() = i
179180
or
180181
Pre::PreInput::getCallTarget(i0) = i
181182
)
182183
}
183184

184-
class BaseInstruction extends Pre::Instructions::Instruction {
185-
BaseInstruction() { fwd(this) }
185+
class BaseX86Instruction extends Pre::Instructions::X86Instruction {
186+
BaseX86Instruction() { fwd(this) }
186187
}
187188

188-
BaseInstruction getCallTarget(BaseInstruction b) { result = Pre::PreInput::getCallTarget(b) }
189+
BaseX86Instruction getCallTarget(BaseX86Instruction b) {
190+
result = Pre::PreInput::getCallTarget(b)
191+
}
189192

190-
BaseInstruction getJumpTarget(BaseInstruction b) { result = Pre::PreInput::getJumpTarget(b) }
193+
BaseX86Instruction getJumpTarget(BaseX86Instruction b) {
194+
result = Pre::PreInput::getJumpTarget(b)
195+
}
191196

192-
class BaseRegister extends Pre::Instructions::Register { }
197+
class BaseX86Register extends Pre::Instructions::X86Register { }
193198

194-
class BaseRipRegister extends BaseRegister, Pre::Instructions::RipRegister { }
199+
class BaseRipRegister extends BaseX86Register, Pre::Instructions::RipRegister { }
195200

196-
class BaseRspRegister extends BaseRegister, Pre::Instructions::RspRegister { }
201+
class BaseRspRegister extends BaseX86Register, Pre::Instructions::RspRegister { }
197202

198-
class BaseRbpRegister extends BaseRegister, Pre::Instructions::RbpRegister { }
203+
class BaseRbpRegister extends BaseX86Register, Pre::Instructions::RbpRegister { }
199204

200-
class BaseOperand extends Pre::Instructions::Operand {
201-
BaseOperand() { this.getUse() instanceof BaseInstruction }
205+
class BaseX86Operand extends Pre::Instructions::X86Operand {
206+
BaseX86Operand() { this.getUse() instanceof BaseX86Instruction }
202207
}
203208

204-
class BaseRegisterAccess extends Pre::Instructions::RegisterAccess {
205-
BaseRegister getTarget() { result = super.getTarget() }
209+
class BaseX86RegisterAccess extends Pre::Instructions::X86RegisterAccess {
210+
BaseX86Register getTarget() { result = super.getTarget() }
206211
}
207212

208-
class BaseUnusedOperand extends BaseOperand, Pre::Instructions::UnusedOperand { }
213+
class BaseX86UnusedOperand extends BaseX86Operand, Pre::Instructions::X86UnusedOperand { }
209214

210-
class BaseRegisterOperand extends BaseOperand, Pre::Instructions::RegisterOperand {
211-
BaseRegisterAccess getAccess() { result = super.getAccess() }
215+
class BaseX86RegisterOperand extends BaseX86Operand, Pre::Instructions::X86RegisterOperand {
216+
BaseX86RegisterAccess getAccess() { result = super.getAccess() }
212217
}
213218

214-
final private class FinalBaseOperand = BaseOperand;
219+
final private class FinalBaseX86Operand = BaseX86Operand;
215220

216-
class BaseMemoryOperand extends FinalBaseOperand, Pre::Instructions::MemoryOperand {
217-
BaseRegisterAccess getSegmentRegister() { result = super.getSegmentRegister() }
221+
class BaseX86MemoryOperand extends FinalBaseX86Operand, Pre::Instructions::X86MemoryOperand {
222+
BaseX86RegisterAccess getSegmentRegister() { result = super.getSegmentRegister() }
218223

219-
BaseRegisterAccess getBaseRegister() { result = super.getBaseRegister() }
224+
BaseX86RegisterAccess getBaseRegister() { result = super.getBaseRegister() }
220225

221-
BaseRegisterAccess getIndexRegister() { result = super.getIndexRegister() }
226+
BaseX86RegisterAccess getIndexRegister() { result = super.getIndexRegister() }
222227
}
223228

224-
class BasePointerOperand extends BaseOperand, Pre::Instructions::PointerOperand { }
229+
class BaseX86PointerOperand extends BaseX86Operand, Pre::Instructions::X86PointerOperand { }
225230

226-
class BaseImmediateOperand extends BaseOperand, Pre::Instructions::ImmediateOperand { }
231+
class BaseX86ImmediateOperand extends BaseX86Operand, Pre::Instructions::X86ImmediateOperand { }
227232
}
228233

229234
import Internal::MakeInstructions<Input>
230235

231-
class ProgramEntryInstruction extends Instruction {
236+
class ProgramEntryInstruction extends X86Instruction {
232237
ProgramEntryInstruction() { this.getIndex() = getOffsetOfEntryPoint().toBigInt() }
233238
}
234239

235-
class ExportedEntryInstruction extends Instruction {
240+
class ExportedEntryInstruction extends X86Instruction {
236241
ExportedEntryInstruction() { this.getIndex() = getOffsetOfAnExportedFunction().toBigInt() }
237242
}

0 commit comments

Comments
 (0)