Skip to content

Commit ecf00f9

Browse files
committed
Binary: Add a FieldAddress instruction to the IR.
1 parent 79817dc commit ecf00f9

5 files changed

Lines changed: 42 additions & 1 deletion

File tree

binary/ql/lib/semmle/code/binary/ast/ir/IR.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ private module FinalInstruction {
321321
}
322322
}
323323

324+
class FieldAddressInstruction extends Instruction instanceof Instruction::FieldAddressInstruction {
325+
UnaryOperand getBaseOperand() { result = super.getBaseOperand() }
326+
327+
string getFieldName() { result = super.getFieldName() }
328+
}
329+
324330
class SubInstruction extends BinaryInstruction instanceof Instruction::SubInstruction { }
325331

326332
class AddInstruction extends BinaryInstruction instanceof Instruction::AddInstruction { }

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ class ExternalRefInstruction extends Instruction {
179179
final override string getImmediateValue() { result = this.getExternalName() }
180180
}
181181

182+
class FieldAddressInstruction extends Instruction {
183+
override Opcode::FieldAddress opcode;
184+
185+
UnaryOperand getBaseOperand() { result = this.getAnOperand() }
186+
187+
string getFieldName() { result = te.getFieldName(tag) }
188+
189+
final override string getImmediateValue() { result = this.getFieldName() }
190+
}
191+
182192
class FunEntryInstruction extends Instruction {
183193
override Opcode::FunEntry opcode;
184194
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ private import codeql.controlflow.SuccessorType
44
private import semmle.code.binary.ast.Location
55

66
signature module InstructionSig {
7-
87
class Type {
98
Function getAFunction();
109

@@ -267,6 +266,12 @@ signature module InstructionSig {
267266
string getStringValue();
268267
}
269268

269+
class FieldAddressInstruction extends Instruction {
270+
UnaryOperand getBaseOperand();
271+
272+
string getFieldName();
273+
}
274+
270275
class ControlFlowNode {
271276
Instruction asInstruction();
272277

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private newtype TOpcode =
2424
TNop() or
2525
TNot() or
2626
TInit() or
27+
TFieldAddress() or
2728
// TODO: Ideally, this should either be removed when we handle unresolved CIL calls better.
2829
TExternalRef() or
2930
TFunEntry()
@@ -144,6 +145,10 @@ class Init extends Opcode, TInit {
144145
override string toString() { result = "Init" }
145146
}
146147

148+
class FieldAddress extends Opcode, TFieldAddress {
149+
override string toString() { result = "FieldAddress" }
150+
}
151+
147152
newtype ConditionKind =
148153
EQ() or
149154
NE() or

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,21 @@ module Transform<InstructionSig Input> {
732732
}
733733
}
734734

735+
class FieldAddressInstruction extends Instruction {
736+
FieldAddressInstruction() { this.getOpcode() instanceof Opcode::FieldAddress }
737+
738+
UnaryOperand getBaseOperand() { result = this.getAnOperand() }
739+
740+
string getFieldName() {
741+
exists(Input::FieldAddressInstruction fieldAddr |
742+
this = TOldInstruction(fieldAddr) and
743+
result = fieldAddr.getFieldName()
744+
)
745+
}
746+
747+
final override string getImmediateValue() { result = this.getFieldName() }
748+
}
749+
735750
private class NewInstruction extends MkInstruction, Instruction {
736751
Opcode opcode;
737752
TranslatedElement te;

0 commit comments

Comments
 (0)