Skip to content

Commit 5730756

Browse files
committed
Python API: Properly extract LLIL flags in get_flag_write_low_level_il
1 parent 1897812 commit 5730756

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

python/architecture.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,13 @@ def _get_flag_write_low_level_il(self, ctxt, op, size, write_type, flag, operand
14951495
flag_name = self._flags_by_index[flag]
14961496
operand_list = []
14971497
for i in range(operand_count):
1498-
if operands[i].constant:
1498+
if operand_count == 3 and i == 2 and not operands[i].constant and (
1499+
op == LowLevelILOperation.LLIL_ADC
1500+
or op == LowLevelILOperation.LLIL_SBB
1501+
or op == LowLevelILOperation.LLIL_RLC
1502+
or op == LowLevelILOperation.LLIL_RRC):
1503+
operand_list.append(lowlevelil.ILFlag(self, operands[i].reg))
1504+
elif operands[i].constant:
14991505
operand_list.append(operands[i].value)
15001506
elif lowlevelil.LLIL_REG_IS_TEMP(operands[i].reg):
15011507
operand_list.append(lowlevelil.ILRegister(self, operands[i].reg))
@@ -2241,14 +2247,14 @@ def get_flag_role(self, flag: FlagIndex, sem_class: Optional[SemanticClassIndex]
22412247

22422248
def get_flag_write_low_level_il(
22432249
self, op: LowLevelILOperation, size: int, write_type: Optional[FlagWriteTypeName], flag: FlagType,
2244-
operands: List['lowlevelil.ILRegisterType'], il: 'lowlevelil.LowLevelILFunction'
2250+
operands: List['lowlevelil.ILOperandType'], il: 'lowlevelil.LowLevelILFunction'
22452251
) -> 'lowlevelil.ExpressionIndex':
22462252
"""
22472253
:param LowLevelILOperation op:
22482254
:param int size:
22492255
:param str write_type:
22502256
:param FlagType flag:
2251-
:param operands: a list of either items that are either string register names or constant integer values
2257+
:param operands: a list of either items that are either string registers, flags, or constant integer values
22522258
:type operands: list(str) or list(int)
22532259
:param LowLevelILFunction il:
22542260
:rtype: lowlevelil.ExpressionIndex
@@ -2260,7 +2266,7 @@ def get_flag_write_low_level_il(
22602266

22612267
def get_default_flag_write_low_level_il(
22622268
self, op: 'lowlevelil.LowLevelILOperation', size: int, role: FlagRole,
2263-
operands: List['lowlevelil.ILRegisterType'], il: 'lowlevelil.LowLevelILFunction'
2269+
operands: List['lowlevelil.ILOperandType'], il: 'lowlevelil.LowLevelILFunction'
22642270
) -> 'lowlevelil.ExpressionIndex':
22652271
"""
22662272
:param LowLevelILOperation op:
@@ -2277,6 +2283,15 @@ def get_default_flag_write_low_level_il(
22772283
if isinstance(operand, str):
22782284
operand_list[i].constant = False
22792285
operand_list[i].reg = self.regs[RegisterName(operand)].index
2286+
elif isinstance(operand, lowlevelil.ILFlag):
2287+
assert len(operands) == 3 and i == 2 and (
2288+
op == LowLevelILOperation.LLIL_ADC
2289+
or op == LowLevelILOperation.LLIL_SBB
2290+
or op == LowLevelILOperation.LLIL_RLC
2291+
or op == LowLevelILOperation.LLIL_RRC
2292+
), "Flag operands only allowed for adc/sbb/rlc/rrc"
2293+
operand_list[i].constant = False
2294+
operand_list[i].reg = operand.index
22802295
elif isinstance(operand, lowlevelil.ILRegister):
22812296
operand_list[i].constant = False
22822297
operand_list[i].reg = operand.index

python/lowlevelil.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
TokenList = List['function.InstructionTextToken']
5151
InstructionOrExpression = Union['LowLevelILInstruction', Index]
5252
ILRegisterType = Union[str, 'ILRegister', int]
53+
ILOperandType = Union[ILRegisterType, 'architecture.ILFlag', int]
5354
LLILInstructionsType = Generator['LowLevelILInstruction', None, None]
5455
OperandsType = Tuple[ExpressionIndex, ExpressionIndex, ExpressionIndex, ExpressionIndex]
5556
LowLevelILOperandType = Union['LowLevelILOperationAndSize', 'ILRegister', 'ILFlag', 'ILIntrinsic', 'ILRegisterStack',

0 commit comments

Comments
 (0)