Skip to content

Commit 33753b6

Browse files
committed
Binary: Load instructions's operand now have a LoadOperand type.
1 parent b666074 commit 33753b6

6 files changed

Lines changed: 31 additions & 14 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class CopyInstruction extends Instruction {
144144
class LoadInstruction extends Instruction {
145145
override Opcode::Load opcode;
146146

147-
UnaryOperand getOperand() { result = this.getAnOperand() }
147+
LoadAddressOperand getOperand() { result = this.getAnOperand() }
148148
}
149149

150150
class StoreInstruction extends Instruction {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class UnaryOperand extends Operand {
5757
override UnaryTag operandTag;
5858
}
5959

60+
class LoadAddressOperand extends Operand {
61+
override LoadAddressTag operandTag;
62+
}
63+
6064
class ConditionOperand extends Operand {
6165
override CondTag operandTag;
6266
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
440440
// Load from [x]
441441
this.isLoaded() and
442442
tag = MemoryOperandLoadTag() and
443-
operandTag = UnaryTag() and
443+
operandTag = LoadAddressTag() and
444444
result = this.getInstruction(MemoryOperandAdd2Tag()).getResultVariable()
445445
}
446446

@@ -469,7 +469,7 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
469469
// Load from [x]
470470
this.isLoaded() and
471471
tag = MemoryOperandLoadTag() and
472-
operandTag = UnaryTag() and
472+
operandTag = LoadAddressTag() and
473473
result = this.getInstruction(MemoryOperandAdd1Tag()).getResultVariable()
474474
}
475475

@@ -498,7 +498,7 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
498498
// Load from [x]
499499
this.isLoaded() and
500500
tag = MemoryOperandLoadTag() and
501-
operandTag = UnaryTag() and
501+
operandTag = LoadAddressTag() and
502502
result = this.getInstruction(MemoryOperandAdd2Tag()).getResultVariable()
503503
}
504504

@@ -517,7 +517,7 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
517517
// Load from [x]
518518
this.isLoaded() and
519519
tag = MemoryOperandLoadTag() and
520-
operandTag = UnaryTag() and
520+
operandTag = LoadAddressTag() and
521521
result = this.getInstruction(MemoryOperandAdd1Tag()).getResultVariable()
522522
}
523523

@@ -536,15 +536,15 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
536536
// Load from [x]
537537
this.isLoaded() and
538538
tag = MemoryOperandLoadTag() and
539-
operandTag = UnaryTag() and
539+
operandTag = LoadAddressTag() and
540540
result = this.getInstruction(MemoryOperandAdd1Tag()).getResultVariable()
541541
}
542542

543543
// Compute base
544544
Variable case6(InstructionTag tag, OperandTag operandTag) {
545545
this.isLoaded() and
546546
tag = MemoryOperandLoadTag() and
547-
operandTag = UnaryTag() and
547+
operandTag = LoadAddressTag() and
548548
result = this.getX86RegisterVariable(op.getBaseRegister().getTarget())
549549
// If we are in case6 and we do not need to load the result will be the base register
550550
}
@@ -574,7 +574,7 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
574574
// Load from [x]
575575
this.isLoaded() and
576576
tag = MemoryOperandLoadTag() and
577-
operandTag = UnaryTag() and
577+
operandTag = LoadAddressTag() and
578578
result = this.getInstruction(MemoryOperandAdd1Tag()).getResultVariable()
579579
}
580580

@@ -593,7 +593,7 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
593593
// Load from [x]
594594
this.isLoaded() and
595595
tag = MemoryOperandLoadTag() and
596-
operandTag = UnaryTag() and
596+
operandTag = LoadAddressTag() and
597597
result = this.getInstruction(MemoryOperandMulTag()).getResultVariable()
598598
}
599599

@@ -612,15 +612,15 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
612612
// Load from [x]
613613
this.isLoaded() and
614614
tag = MemoryOperandLoadTag() and
615-
operandTag = UnaryTag() and
615+
operandTag = LoadAddressTag() and
616616
result = this.getInstruction(MemoryOperandAdd1Tag()).getResultVariable()
617617
}
618618

619619
// Compute index
620620
Variable case10(InstructionTag tag, OperandTag operandTag) {
621621
this.isLoaded() and
622622
tag = MemoryOperandLoadTag() and
623-
operandTag = UnaryTag() and
623+
operandTag = LoadAddressTag() and
624624
result = this.getX86RegisterVariable(op.getIndexRegister().getTarget())
625625
// If we are in case10 and we do not need to load the result will be the index register
626626
}
@@ -629,7 +629,7 @@ class TranslatedX86MemoryOperand extends TranslatedX86Operand, TTranslatedX86Mem
629629
Variable case11(InstructionTag tag, OperandTag operandTag) {
630630
this.isLoaded() and
631631
tag = MemoryOperandLoadTag() and
632-
operandTag = UnaryTag() and
632+
operandTag = LoadAddressTag() and
633633
result = this.getInstruction(MemoryOperandConstDisplacementTag()).getResultVariable()
634634
// If we are in case11 and we do not need to load the result will be the displacement constant
635635
}

binary/ql/lib/semmle/code/binary/ast/ir/internal/InstructionSig.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ signature module InstructionSig {
3636

3737
class UnaryOperand extends Operand;
3838

39+
class LoadAddressOperand extends Operand;
40+
3941
class ConditionOperand extends Operand;
4042

4143
class ConditionJumpTargetOperand extends Operand;
@@ -183,7 +185,7 @@ signature module InstructionSig {
183185
}
184186

185187
class LoadInstruction extends Instruction {
186-
UnaryOperand getOperand();
188+
LoadAddressOperand getOperand();
187189
}
188190

189191
class StoreInstruction extends Instruction {

binary/ql/lib/semmle/code/binary/ast/ir/internal/Tags.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ newtype TOperandTag =
2828
RightTag() or
2929
UnaryTag() or
3030
StoreValueTag() or
31+
LoadAddressTag() or
3132
StoreAddressTag() or
3233
CallTargetTag() or
3334
CondTag() or
@@ -45,6 +46,9 @@ class OperandTag extends TOperandTag {
4546
this = UnaryTag() and
4647
result = 0
4748
or
49+
this = LoadAddressTag() and
50+
result = 0
51+
or
4852
this = StoreValueTag() and
4953
result = 1
5054
or
@@ -87,6 +91,9 @@ class OperandTag extends TOperandTag {
8791
this = UnaryTag() and
8892
result = "Unary"
8993
or
94+
this = LoadAddressTag() and
95+
result = "LoadAddr"
96+
or
9097
this = StoreValueTag() and
9198
result = "StoreValue"
9299
or

binary/ql/lib/semmle/code/binary/ast/ir/internal/TransformInstruction/TransformInstruction.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ module Transform<InstructionSig Input> {
596596
class LoadInstruction extends Instruction {
597597
LoadInstruction() { this.getOpcode() instanceof Opcode::Load }
598598

599-
UnaryOperand getOperand() { result = this.getAnOperand() }
599+
LoadAddressOperand getOperand() { result = this.getAnOperand() }
600600
}
601601

602602
class StoreInstruction extends Instruction {
@@ -843,6 +843,10 @@ module Transform<InstructionSig Input> {
843843
StoreAddressOperand() { this.getOperandTag() instanceof StoreAddressTag }
844844
}
845845

846+
class LoadAddressOperand extends Operand {
847+
LoadAddressOperand() { this.getOperandTag() instanceof LoadAddressTag }
848+
}
849+
846850
class UnaryOperand extends Operand {
847851
UnaryOperand() { this.getOperandTag() instanceof UnaryTag }
848852
}

0 commit comments

Comments
 (0)