summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2019-08-03 22:40:47 -0400
committerRusty Wagner <rusty@vector35.com>2019-12-19 17:20:53 -0500
commitc69b76dd1a7e1985f58f71c07dfc8b7b0657f57a (patch)
tree25bbbdc261c3b550dd65d66580b016dfb03dade7 /python
parent741fb0538e0ac6ab14928f78697196803dbd2ed5 (diff)
Add data flow query options
Diffstat (limited to 'python')
-rw-r--r--python/lowlevelil.py73
-rw-r--r--python/mediumlevelil.py85
2 files changed, 129 insertions, 29 deletions
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 5f71b80c..da5d5bb5 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -909,7 +909,7 @@ class LowLevelILInstruction(object):
@property
def possible_values(self):
"""Possible values of expression using path-sensitive static data flow analysis (read-only)"""
- value = core.BNGetLowLevelILPossibleExprValues(self._function.handle, self.expr_index)
+ value = core.BNGetLowLevelILPossibleExprValues(self._function.handle, self.expr_index, None, 0)
result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -937,6 +937,17 @@ class LowLevelILInstruction(object):
result.append(LowLevelILOperationAndSize(self._operation, self._size))
return result
+ def get_possible_values(self, options = []):
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetLowLevelILPossibleExprValues(self._function.handle, self.expr_index, option_array, len(options))
+ result = binaryninja.function.PossibleValueSet(self._function.arch, value)
+ core.BNFreePossibleValueSet(value)
+ return result
+
def get_reg_value(self, reg):
reg = self._function.arch.get_reg_index(reg)
value = core.BNGetLowLevelILRegisterValueAtInstruction(self._function.handle, reg, self._instr_index)
@@ -949,16 +960,28 @@ class LowLevelILInstruction(object):
result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
- def get_possible_reg_values(self, reg):
+ def get_possible_reg_values(self, reg, options = []):
reg = self._function.arch.get_reg_index(reg)
- value = core.BNGetLowLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetLowLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index,
+ option_array, len(options))
result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
- def get_possible_reg_values_after(self, reg):
+ def get_possible_reg_values_after(self, reg, options = []):
reg = self._function.arch.get_reg_index(reg)
- value = core.BNGetLowLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetLowLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index,
+ option_array, len(options))
result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -975,16 +998,28 @@ class LowLevelILInstruction(object):
result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
- def get_possible_flag_values(self, flag):
+ def get_possible_flag_values(self, flag, options = []):
flag = self._function.arch.get_flag_index(flag)
- value = core.BNGetLowLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetLowLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index,
+ option_array, len(options))
result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
- def get_possible_flag_values_after(self, flag):
+ def get_possible_flag_values_after(self, flag, options = []):
flag = self._function.arch.get_flag_index(flag)
- value = core.BNGetLowLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetLowLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index,
+ option_array, len(options))
result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -999,14 +1034,26 @@ class LowLevelILInstruction(object):
result = binaryninja.function.RegisterValue(self._function.arch, value)
return result
- def get_possible_stack_contents(self, offset, size):
- value = core.BNGetLowLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index)
+ def get_possible_stack_contents(self, offset, size, options = []):
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetLowLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index,
+ option_array, len(options))
result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
- def get_possible_stack_contents_after(self, offset, size):
- value = core.BNGetLowLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index)
+ def get_possible_stack_contents_after(self, offset, size, options = []):
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetLowLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index,
+ option_array, len(options))
result = binaryninja.function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 24b87ac7..812914cb 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -24,7 +24,7 @@ import struct
# Binary Ninja components
import binaryninja
from binaryninja import _binaryninjacore as core
-from binaryninja.enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDependence
+from binaryninja.enums import MediumLevelILOperation, InstructionTextTokenType, ILBranchDependence, DataFlowQueryOption
from binaryninja import basicblock #required for MediumLevelILBasicBlock argument
from binaryninja import function
from binaryninja import types
@@ -434,7 +434,7 @@ class MediumLevelILInstruction(object):
@property
def possible_values(self):
"""Possible values of expression using path-sensitive static data flow analysis (read-only)"""
- value = core.BNGetMediumLevelILPossibleExprValues(self._function.handle, self._expr_index)
+ value = core.BNGetMediumLevelILPossibleExprValues(self._function.handle, self._expr_index, None, 0)
result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -555,12 +555,29 @@ class MediumLevelILInstruction(object):
return types.Type(result.type, platform = platform, confidence = result.confidence)
return None
- def get_ssa_var_possible_values(self, ssa_var):
+ def get_possible_values(self, options = []):
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetMediumLevelILPossibleExprValues(self._function.handle, self._expr_index, option_array, len(options))
+ result = function.PossibleValueSet(self._function.arch, value)
+ core.BNFreePossibleValueSet(value)
+ return result
+
+ def get_ssa_var_possible_values(self, ssa_var, options = []):
var_data = core.BNVariable()
var_data.type = ssa_var.var.source_type
var_data.index = ssa_var.var.index
var_data.storage = ssa_var.var.storage
- value = core.BNGetMediumLevelILPossibleSSAVarValues(self._function.handle, var_data, ssa_var.version, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetMediumLevelILPossibleSSAVarValues(self._function.handle, var_data, ssa_var.version,
+ self._instr_index, option_array, len(options))
result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -598,16 +615,28 @@ class MediumLevelILInstruction(object):
result = function.RegisterValue(self._function.arch, value)
return result
- def get_possible_reg_values(self, reg):
+ def get_possible_reg_values(self, reg, options = []):
reg = self._function.arch.get_reg_index(reg)
- value = core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self._function.handle, reg, self._instr_index,
+ option_array, len(options))
result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
- def get_possible_reg_values_after(self, reg):
+ def get_possible_reg_values_after(self, reg, options = []):
reg = self._function.arch.get_reg_index(reg)
- value = core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self._function.handle, reg, self._instr_index,
+ option_array, len(options))
result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -624,16 +653,28 @@ class MediumLevelILInstruction(object):
result = function.RegisterValue(self._function.arch, value)
return result
- def get_possible_flag_values(self, flag):
+ def get_possible_flag_values(self, flag, options = []):
flag = self._function.arch.get_flag_index(flag)
- value = core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self._function.handle, flag, self._instr_index,
+ option_array, len(options))
result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
- def get_possible_flag_values_after(self, flag):
+ def get_possible_flag_values_after(self, flag, options = []):
flag = self._function.arch.get_flag_index(flag)
- value = core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index)
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self._function.handle, flag, self._instr_index,
+ option_array, len(options))
result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -648,14 +689,26 @@ class MediumLevelILInstruction(object):
result = function.RegisterValue(self._function.arch, value)
return result
- def get_possible_stack_contents(self, offset, size):
- value = core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index)
+ def get_possible_stack_contents(self, offset, size, options = []):
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self._function.handle, offset, size, self._instr_index,
+ option_array, len(options))
result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result
- def get_possible_stack_contents_after(self, offset, size):
- value = core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index)
+ def get_possible_stack_contents_after(self, offset, size, options = []):
+ option_array = (ctypes.c_int * len(options))()
+ idx = 0
+ for option in options:
+ option_array[idx] = option
+ idx += 1
+ value = core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self._function.handle, offset, size, self._instr_index,
+ option_array, len(options))
result = function.PossibleValueSet(self._function.arch, value)
core.BNFreePossibleValueSet(value)
return result