Skip to content

Commit 4608684

Browse files
committed
Allow LLILFunction.set_flag to use flag index
For things like temporary flags which the lifters can produce
1 parent 8908746 commit 4608684

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

python/lowlevelil.py

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,7 +3945,7 @@ def copy_expr_to(
39453945
return dest.reg_stack_push(expr.size, expr.stack, sub_expr_handler(expr.src), expr.flags, loc)
39463946
if expr.operation == LowLevelILOperation.LLIL_SET_FLAG:
39473947
expr: LowLevelILSetFlag
3948-
return dest.set_flag(expr.dest.name, sub_expr_handler(expr.src), loc)
3948+
return dest.set_flag(expr.dest, sub_expr_handler(expr.src), loc)
39493949
if expr.operation == LowLevelILOperation.LLIL_LOAD:
39503950
expr: LowLevelILLoad
39513951
return dest.load(expr.size, sub_expr_handler(expr.src), expr.flags, loc)
@@ -3966,10 +3966,10 @@ def copy_expr_to(
39663966
return dest.reg_stack_pop(expr.size, expr.stack, loc)
39673967
if expr.operation == LowLevelILOperation.LLIL_FLAG:
39683968
expr: LowLevelILFlag
3969-
return dest.flag(expr.src.name, loc)
3969+
return dest.flag(expr.src, loc)
39703970
if expr.operation == LowLevelILOperation.LLIL_FLAG_BIT:
39713971
expr: LowLevelILFlagBit
3972-
return dest.flag_bit(expr.size, expr.src.name, expr.bit, loc)
3972+
return dest.flag_bit(expr.size, expr.src, expr.bit, loc)
39733973
if expr.operation == LowLevelILOperation.LLIL_JUMP:
39743974
expr: LowLevelILJump
39753975
return dest.jump(sub_expr_handler(expr.dest), loc)
@@ -4284,7 +4284,7 @@ def reg_stack_push(
42844284
return self.expr(LowLevelILOperation.LLIL_REG_STACK_PUSH, _reg_stack, value, size=size, flags=flags, source_location=loc)
42854285

42864286
def set_flag(
4287-
self, flag: 'architecture.FlagName', value: ExpressionIndex,
4287+
self, flag: 'architecture.FlagType', value: ExpressionIndex,
42884288
loc: Optional['ILSourceLocation'] = None
42894289
) -> ExpressionIndex:
42904290
"""
@@ -4296,26 +4296,34 @@ def set_flag(
42964296
:return: The expression FLAG.flag = value
42974297
:rtype: ExpressionIndex
42984298
"""
4299-
return self.expr(LowLevelILOperation.LLIL_SET_FLAG, ExpressionIndex(self.arch.get_flag_by_name(flag)), value, source_location=loc)
4299+
if isinstance(flag, str):
4300+
flag_index = self.arch.get_flag_by_name(flag)
4301+
elif isinstance(flag, int):
4302+
flag_index = flag
4303+
elif isinstance(flag, ILFlag):
4304+
flag_index = flag.index
4305+
else:
4306+
assert False, "Unknown flag type"
4307+
return self.expr(LowLevelILOperation.LLIL_SET_FLAG, ExpressionIndex(flag_index), value, source_location=loc)
43004308

43014309
def load(
4302-
self, size: int, addr: ExpressionIndex, flags: Optional['architecture.FlagName'] = None,
4310+
self, size: int, addr: ExpressionIndex, flags: Optional['architecture.FlagType'] = None,
43034311
loc: Optional['ILSourceLocation'] = None
43044312
) -> ExpressionIndex:
43054313
"""
43064314
``load`` Reads ``size`` bytes from the expression ``addr``
43074315
43084316
:param int size: number of bytes to read
43094317
:param ExpressionIndex addr: the expression to read memory from
4310-
:param FlagName flags: which flags are set by this operation
4318+
:param FlagType flags: which flags are set by this operation
43114319
:param ILSourceLocation loc: location of returned expression
43124320
:return: The expression ``[addr].size``
43134321
:rtype: ExpressionIndex
43144322
"""
43154323
return self.expr(LowLevelILOperation.LLIL_LOAD, addr, size=size, flags=flags, source_location=loc)
43164324

43174325
def store(
4318-
self, size: int, addr: ExpressionIndex, value: ExpressionIndex, flags: Optional['architecture.FlagName'] = None,
4326+
self, size: int, addr: ExpressionIndex, value: ExpressionIndex, flags: Optional['architecture.FlagType'] = None,
43194327
loc: Optional['ILSourceLocation'] = None
43204328
) -> ExpressionIndex:
43214329
"""
@@ -4324,7 +4332,7 @@ def store(
43244332
:param int size: number of bytes to write
43254333
:param ExpressionIndex addr: the expression to write to
43264334
:param ExpressionIndex value: the expression to be written
4327-
:param FlagName flags: which flags are set by this operation
4335+
:param FlagType flags: which flags are set by this operation
43284336
:param ILSourceLocation loc: location of returned expression
43294337
:return: The expression ``[addr].size = value``
43304338
:rtype: ExpressionIndex
@@ -4492,19 +4500,27 @@ def float_const_double(self, value: float, loc: Optional['ILSourceLocation'] = N
44924500
"""
44934501
return self.expr(LowLevelILOperation.LLIL_FLOAT_CONST, struct.unpack("Q", struct.pack("d", value))[0], size=8, source_location=loc)
44944502

4495-
def flag(self, flag: 'architecture.FlagName', loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex:
4503+
def flag(self, flag: 'architecture.FlagType', loc: Optional['ILSourceLocation'] = None) -> ExpressionIndex:
44964504
"""
44974505
``flag`` returns a flag expression for the given flag name.
44984506
4499-
:param architecture.FlagName flag: name of the flag expression to retrieve
4507+
:param architecture.FlagType flag: flag expression to retrieve
45004508
:param ILSourceLocation loc: location of returned expression
45014509
:return: A flag expression of given flag name
45024510
:rtype: ExpressionIndex
45034511
"""
4504-
return self.expr(LowLevelILOperation.LLIL_FLAG, self.arch.get_flag_by_name(flag), source_location=loc)
4512+
if isinstance(flag, str):
4513+
flag_index = self.arch.get_flag_by_name(flag)
4514+
elif isinstance(flag, int):
4515+
flag_index = flag
4516+
elif isinstance(flag, ILFlag):
4517+
flag_index = flag.index
4518+
else:
4519+
assert False, "Unknown flag type"
4520+
return self.expr(LowLevelILOperation.LLIL_FLAG, ExpressionIndex(flag_index), source_location=loc)
45054521

45064522
def flag_bit(
4507-
self, size: int, flag: 'architecture.FlagName', bit: int, loc: Optional['ILSourceLocation'] = None
4523+
self, size: int, flag: 'architecture.FlagType', bit: int, loc: Optional['ILSourceLocation'] = None
45084524
) -> ExpressionIndex:
45094525
"""
45104526
``flag_bit`` sets the flag named ``flag`` and size ``size`` to the constant integer value ``bit``
@@ -4516,7 +4532,15 @@ def flag_bit(
45164532
:return: A constant expression of given value and size ``FLAG.flag = bit``
45174533
:rtype: ExpressionIndex
45184534
"""
4519-
return self.expr(LowLevelILOperation.LLIL_FLAG_BIT, self.arch.get_flag_by_name(flag), bit, size=size, source_location=loc)
4535+
if isinstance(flag, str):
4536+
flag_index = self.arch.get_flag_by_name(flag)
4537+
elif isinstance(flag, int):
4538+
flag_index = flag
4539+
elif isinstance(flag, ILFlag):
4540+
flag_index = flag.index
4541+
else:
4542+
assert False, "Unknown flag type"
4543+
return self.expr(LowLevelILOperation.LLIL_FLAG_BIT, ExpressionIndex(flag_index), bit, size=size, source_location=loc)
45204544

45214545
def add(
45224546
self, size: int, a: ExpressionIndex, b: ExpressionIndex, flags: Optional['architecture.FlagType'] = None,

0 commit comments

Comments
 (0)