summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2017-08-29 20:13:57 -0400
committerRusty Wagner <rusty@vector35.com>2017-08-29 20:15:48 -0400
commit47333ef2460edfa9b5ba5be26fd19f80c0d8d8b6 (patch)
tree65eb1e071548ca49b6dff6866fba922fed004cbe /python
parent09af54fba214ee5e0baf6a9bacce0ceebbd34deb (diff)
Updating APIs to deal with stack adjustment
Diffstat (limited to 'python')
-rw-r--r--python/lowlevelil.py13
-rw-r--r--python/types.py19
2 files changed, 30 insertions, 2 deletions
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index e50f80c6..75a3f1ad 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -161,6 +161,7 @@ class LowLevelILInstruction(object):
LowLevelILOperation.LLIL_JUMP: [("dest", "expr")],
LowLevelILOperation.LLIL_JUMP_TO: [("dest", "expr"), ("targets", "int_list")],
LowLevelILOperation.LLIL_CALL: [("dest", "expr")],
+ LowLevelILOperation.LLIL_CALL_STACK_ADJUST: [("dest", "expr"), ("stack_adjustment", "int")],
LowLevelILOperation.LLIL_RET: [("dest", "expr")],
LowLevelILOperation.LLIL_NORET: [],
LowLevelILOperation.LLIL_IF: [("condition", "expr"), ("true", "int"), ("false", "int")],
@@ -1262,6 +1263,18 @@ class LowLevelILFunction(object):
"""
return self.expr(LowLevelILOperation.LLIL_CALL, dest.index)
+ def call_stack_adjust(self, dest, stack_adjust):
+ """
+ ``call_stack_adjust`` returns an expression which first pushes the address of the next instruction onto the stack
+ then jumps (branches) to the expression ``dest``. After the function exits, ``stack_adjust`` is added to the
+ stack pointer register.
+
+ :param LowLevelILExpr dest: the expression to call
+ :return: The expression ``call(dest), stack += stack_adjust``
+ :rtype: LowLevelILExpr
+ """
+ return self.expr(LowLevelILOperation.LLIL_CALL_STACK_ADJUST, dest.index, stack_adjust)
+
def ret(self, dest):
"""
``ret`` returns an expression which jumps (branches) to the expression ``dest``. ``ret`` is a special alias for
diff --git a/python/types.py b/python/types.py
index bf4a7b74..2557db2c 100644
--- a/python/types.py
+++ b/python/types.py
@@ -362,6 +362,12 @@ class Type(object):
"""Offset into structure (read-only)"""
return core.BNGetTypeOffset(self.handle)
+ @property
+ def stack_adjustment(self):
+ """Stack adjustment for function (read-only)"""
+ result = core.BNGetTypeStackAdjustment(self.handle)
+ return SizeWithConfidence(result.value, confidence = result.confidence)
+
def __str__(self):
platform = None
if self.platform is not None:
@@ -551,7 +557,7 @@ class Type(object):
return Type(core.BNCreateArrayType(type_conf, count))
@classmethod
- def function(self, ret, params, calling_convention=None, variable_arguments=None):
+ def function(self, ret, params, calling_convention=None, variable_arguments=None, stack_adjust=None):
"""
``function`` class method for creating an function Type.
@@ -605,8 +611,17 @@ class Type(object):
vararg_conf.value = variable_arguments.value
vararg_conf.confidence = variable_arguments.confidence
+ if stack_adjust is None:
+ stack_adjust = SizeWithConfidence(0, confidence = 0)
+ elif not isinstance(stack_adjust, SizeWithConfidence):
+ stack_adjust = SizeWithConfidence(stack_adjust)
+
+ stack_adjust_conf = core.BNSizeWithConfidence()
+ stack_adjust_conf.value = stack_adjust.value
+ stack_adjust_conf.confidence = stack_adjust.confidence
+
return Type(core.BNCreateFunctionType(ret_conf, conv_conf, param_buf, len(params),
- vararg_conf))
+ vararg_conf, stack_adjust_conf))
@classmethod
def generate_auto_type_id(self, source, name):