summaryrefslogtreecommitdiff
path: root/python/lowlevelil.py
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2018-01-16 16:25:30 -0500
committerPeter LaFosse <peter@vector35.com>2018-03-23 17:10:06 -0400
commit95a3c711722901c347ddbfa922734ed15f04d62f (patch)
treede0d68ef6f1784a68e03ffed6fe499e06e8f789e /python/lowlevelil.py
parentd788badbbd0744a623da4fd97aaa539d2726a00b (diff)
Add classes and groups for semantic flags resolution
Diffstat (limited to 'python/lowlevelil.py')
-rw-r--r--python/lowlevelil.py58
1 files changed, 55 insertions, 3 deletions
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 42c34ee0..a2d77c9f 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -99,6 +99,38 @@ class ILFlag(object):
return self.name
+class ILSemanticFlagClass(object):
+ def __init__(self, arch, sem_class):
+ self.arch = arch
+ self.index = sem_class
+ self.name = self.arch.get_semantic_flag_class_name(self.index)
+
+ def __str__(self):
+ return self.name
+
+ def __repr__(self):
+ return self.name
+
+ def __eq__(self, other):
+ return self.index == other.index
+
+
+class ILSemanticFlagGroup(object):
+ def __init__(self, arch, sem_group):
+ self.arch = arch
+ self.index = sem_group
+ self.name = self.arch.get_semantic_flag_group_name(self.index)
+
+ def __str__(self):
+ return self.name
+
+ def __repr__(self):
+ return self.name
+
+ def __eq__(self, other):
+ return self.index == other.index
+
+
class SSARegister(object):
def __init__(self, reg, version):
self.reg = reg
@@ -202,7 +234,8 @@ class LowLevelILInstruction(object):
LowLevelILOperation.LLIL_NORET: [],
LowLevelILOperation.LLIL_IF: [("condition", "expr"), ("true", "int"), ("false", "int")],
LowLevelILOperation.LLIL_GOTO: [("dest", "int")],
- LowLevelILOperation.LLIL_FLAG_COND: [("condition", "cond")],
+ LowLevelILOperation.LLIL_FLAG_COND: [("condition", "cond", "semantic_class", "sem_class")],
+ LowLevelILOperation.LLIL_FLAG_GROUP: [("semantic_group", "sem_group")],
LowLevelILOperation.LLIL_CMP_E: [("left", "expr"), ("right", "expr")],
LowLevelILOperation.LLIL_CMP_NE: [("left", "expr"), ("right", "expr")],
LowLevelILOperation.LLIL_CMP_SLT: [("left", "expr"), ("right", "expr")],
@@ -238,6 +271,7 @@ class LowLevelILInstruction(object):
LowLevelILOperation.LLIL_FCMP_LE: [("left", "expr"), ("right", "expr")],
LowLevelILOperation.LLIL_FCMP_GE: [("left", "expr"), ("right", "expr")],
LowLevelILOperation.LLIL_FCMP_GT: [("left", "expr"), ("right", "expr")],
+ LowLevelILOperation.LLIL_FCMP_O: [("left", "expr"), ("right", "expr")],
LowLevelILOperation.LLIL_FCMP_UO: [("left", "expr"), ("right", "expr")],
LowLevelILOperation.LLIL_SET_REG_SSA: [("dest", "reg_ssa"), ("src", "expr")],
LowLevelILOperation.LLIL_SET_REG_SSA_PARTIAL: [("full_reg", "reg_ssa"), ("dest", "reg"), ("src", "expr")],
@@ -324,6 +358,10 @@ class LowLevelILInstruction(object):
flag = ILFlag(func.arch, instr.operands[i])
i += 1
value = SSAFlag(flag, instr.operands[i])
+ elif operand_type == "sem_class":
+ value = ILSemanticFlagClass(func.arch, instr.operands[i])
+ elif operand_type == "sem_group":
+ value = ILSemanticFlagGroup(func.arch, instr.operands[i])
elif operand_type == "cond":
value = LowLevelILFlagCondition(instr.operands[i])
elif operand_type == "int_list":
@@ -1507,11 +1545,12 @@ class LowLevelILFunction(object):
"""
return self.expr(LowLevelILOperation.LLIL_NORET)
- def flag_condition(self, cond):
+ def flag_condition(self, cond, sem_class = None):
"""
``flag_condition`` returns a flag_condition expression for the given LowLevelILFlagCondition
:param LowLevelILFlagCondition cond: Flag condition expression to retrieve
+ :param str sem_class: Optional semantic flag class
:return: A flag_condition expression
:rtype: LowLevelILExpr
"""
@@ -1519,7 +1558,19 @@ class LowLevelILFunction(object):
cond = LowLevelILFlagCondition[cond]
elif isinstance(cond, LowLevelILFlagCondition):
cond = cond.value
- return self.expr(LowLevelILOperation.LLIL_FLAG_COND, cond)
+ class_index = self.arch.get_semantic_flag_class_index(sem_class)
+ return self.expr(LowLevelILOperation.LLIL_FLAG_COND, cond, class_index)
+
+ def flag_group(self, sem_group):
+ """
+ ``flag_group`` returns a flag_group expression for the given semantic flag group
+
+ :param str sem_group: Semantic flag group to access
+ :return: A flag_group expression
+ :rtype: LowLevelILExpr
+ """
+ group = self.arch.get_semantic_flag_group_index(sem_group)
+ return self.expr(LowLevelILOperation.LLIL_FLAG_GROUP, group)
def compare_equal(self, size, a, b):
"""
@@ -2174,6 +2225,7 @@ class LowLevelILBasicBlock(basicblock.BasicBlock):
def __hash__(self):
return hash((self.start, self.end, self.il_function))
+
def LLIL_TEMP(n):
return n | 0x80000000