summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/architecture.py4
-rw-r--r--python/basicblock.py3
-rw-r--r--python/binaryview.py23
-rw-r--r--python/callingconvention.py9
-rw-r--r--python/function.py48
-rw-r--r--python/lowlevelil.py3
-rw-r--r--python/mediumlevelil.py3
-rw-r--r--python/types.py165
8 files changed, 199 insertions, 59 deletions
diff --git a/python/architecture.py b/python/architecture.py
index 2eb3c717..b9c6fcc9 100644
--- a/python/architecture.py
+++ b/python/architecture.py
@@ -478,6 +478,7 @@ class Architecture(object):
token_buf[i].size = tokens[i].size
token_buf[i].operand = tokens[i].operand
token_buf[i].context = tokens[i].context
+ token_buf[i].confidence = tokens[i].confidence
token_buf[i].address = tokens[i].address
result[0] = token_buf
ptr = ctypes.cast(token_buf, ctypes.c_void_p)
@@ -1163,8 +1164,9 @@ class Architecture(object):
size = tokens[i].size
operand = tokens[i].operand
context = tokens[i].context
+ confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
+ result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeInstructionText(tokens, count.value)
return result, length.value
diff --git a/python/basicblock.py b/python/basicblock.py
index 7858cc60..c92336c5 100644
--- a/python/basicblock.py
+++ b/python/basicblock.py
@@ -298,8 +298,9 @@ class BasicBlock(object):
size = lines[i].tokens[j].size
operand = lines[i].tokens[j].operand
context = lines[i].tokens[j].context
+ confidence = lines[i].tokens[j].confidence
address = lines[i].tokens[j].address
- tokens.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
+ tokens.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
result.append(function.DisassemblyTextLine(addr, tokens))
core.BNFreeDisassemblyTextLines(lines, count.value)
return result
diff --git a/python/binaryview.py b/python/binaryview.py
index c0ac0abc..15e5d5da 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -211,7 +211,7 @@ class BinaryDataNotificationCallbacks(object):
def _data_var_added(self, ctxt, view, var):
try:
address = var[0].address
- var_type = types.Type(core.BNNewTypeReference(var[0].type))
+ var_type = types.Type(core.BNNewTypeReference(var[0].type), confidence = var[0].typeConfidence)
auto_discovered = var[0].autoDiscovered
self.notify.data_var_added(self.view, DataVariable(address, var_type, auto_discovered))
except:
@@ -220,7 +220,7 @@ class BinaryDataNotificationCallbacks(object):
def _data_var_removed(self, ctxt, view, var):
try:
address = var[0].address
- var_type = types.Type(core.BNNewTypeReference(var[0].type))
+ var_type = types.Type(core.BNNewTypeReference(var[0].type), confidence = var[0].typeConfidence)
auto_discovered = var[0].autoDiscovered
self.notify.data_var_removed(self.view, DataVariable(address, var_type, auto_discovered))
except:
@@ -229,7 +229,7 @@ class BinaryDataNotificationCallbacks(object):
def _data_var_updated(self, ctxt, view, var):
try:
address = var[0].address
- var_type = types.Type(core.BNNewTypeReference(var[0].type))
+ var_type = types.Type(core.BNNewTypeReference(var[0].type), confidence = var[0].typeConfidence)
auto_discovered = var[0].autoDiscovered
self.notify.data_var_updated(self.view, DataVariable(address, var_type, auto_discovered))
except:
@@ -854,7 +854,7 @@ class BinaryView(object):
result = {}
for i in xrange(0, count.value):
addr = var_list[i].address
- var_type = types.Type(core.BNNewTypeReference(var_list[i].type))
+ var_type = types.Type(core.BNNewTypeReference(var_list[i].type), confidence = var_list[i].typeConfidence)
auto_discovered = var_list[i].autoDiscovered
result[addr] = DataVariable(addr, var_type, auto_discovered)
core.BNFreeDataVariables(var_list, count.value)
@@ -1847,7 +1847,10 @@ class BinaryView(object):
>>> bv.define_data_var(bv.entry_point, t[0])
>>>
"""
- core.BNDefineDataVariable(self.handle, addr, var_type.handle)
+ tc = core.BNTypeWithConfidence()
+ tc.type = var_type.handle
+ tc.confidence = var_type.confidence
+ core.BNDefineDataVariable(self.handle, addr, tc)
def define_user_data_var(self, addr, var_type):
"""
@@ -1864,7 +1867,10 @@ class BinaryView(object):
>>> bv.define_user_data_var(bv.entry_point, t[0])
>>>
"""
- core.BNDefineUserDataVariable(self.handle, addr, var_type.handle)
+ tc = core.BNTypeWithConfidence()
+ tc.type = var_type.handle
+ tc.confidence = var_type.confidence
+ core.BNDefineUserDataVariable(self.handle, addr, tc)
def undefine_data_var(self, addr):
"""
@@ -1910,7 +1916,7 @@ class BinaryView(object):
var = core.BNDataVariable()
if not core.BNGetDataVariableAtAddress(self.handle, addr, var):
return None
- return DataVariable(var.address, types.Type(var.type), var.autoDiscovered)
+ return DataVariable(var.address, types.Type(var.type, confidence = var.typeConfidence), var.autoDiscovered)
def get_function_at(self, addr, plat=None):
"""
@@ -2781,8 +2787,9 @@ class BinaryView(object):
size = lines[i].contents.tokens[j].size
operand = lines[i].contents.tokens[j].operand
context = lines[i].contents.tokens[j].context
+ confidence = lines[i].contents.tokens[j].confidence
address = lines[i].contents.tokens[j].address
- tokens.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
+ tokens.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
contents = function.DisassemblyTextLine(addr, tokens)
result.append(lineardisassembly.LinearDisassemblyLine(lines[i].type, func, block, lines[i].lineOffset, contents))
diff --git a/python/callingconvention.py b/python/callingconvention.py
index 4c87eef6..e6aa323c 100644
--- a/python/callingconvention.py
+++ b/python/callingconvention.py
@@ -25,6 +25,7 @@ import ctypes
import _binaryninjacore as core
import architecture
import log
+import types
class CallingConvention(object):
@@ -40,7 +41,7 @@ class CallingConvention(object):
_registered_calling_conventions = []
- def __init__(self, arch, handle = None):
+ def __init__(self, arch, handle = None, confidence = types.Type.max_confidence):
if handle is None:
self.arch = arch
self._pending_reg_lists = {}
@@ -109,6 +110,8 @@ class CallingConvention(object):
else:
self.__dict__["float_return_reg"] = self.arch.get_reg_name(reg)
+ self.confidence = confidence
+
def __del__(self):
core.BNFreeCallingConvention(self.handle)
@@ -220,3 +223,7 @@ class CallingConvention(object):
def __str__(self):
return self.name
+
+ def with_confidence(self, confidence):
+ return CallingConvention(self.arch, handle = core.BNNewCallingConventionReference(self.handle),
+ confidence = confidence)
diff --git a/python/function.py b/python/function.py
index 8beebe66..3cd5396f 100644
--- a/python/function.py
+++ b/python/function.py
@@ -183,9 +183,11 @@ class Variable(object):
if name is None:
name = core.BNGetVariableName(func.handle, var)
if var_type is None:
- var_type = core.BNGetVariableType(func.handle, var)
- if var_type:
- var_type = types.Type(var_type)
+ var_type_conf = core.BNGetVariableType(func.handle, var)
+ if var_type_conf.type:
+ var_type = types.Type(var_type, confidence = var_type_conf.confidence)
+ else:
+ var_type = None
self.name = name
self.type = var_type
@@ -390,7 +392,7 @@ class Function(object):
result = []
for i in xrange(0, count.value):
result.append(Variable(self, v[i].var.type, v[i].var.index, v[i].var.storage, v[i].name,
- types.Type(handle = core.BNNewTypeReference(v[i].type))))
+ types.Type(handle = core.BNNewTypeReference(v[i].type), confidence = v[i].typeConfidence)))
result.sort(key = lambda x: x.identifier)
core.BNFreeVariableList(v, count.value)
return result
@@ -403,7 +405,7 @@ class Function(object):
result = []
for i in xrange(0, count.value):
result.append(Variable(self, v[i].var.type, v[i].var.index, v[i].var.storage, v[i].name,
- types.Type(handle = core.BNNewTypeReference(v[i].type))))
+ types.Type(handle = core.BNNewTypeReference(v[i].type), confidence = v[i].typeConfidence)))
result.sort(key = lambda x: x.identifier)
core.BNFreeVariableList(v, count.value)
return result
@@ -616,7 +618,7 @@ class Function(object):
refs = core.BNGetStackVariablesReferencedByInstruction(self.handle, arch.handle, addr, count)
result = []
for i in xrange(0, count.value):
- var_type = types.Type(core.BNNewTypeReference(refs[i].type))
+ var_type = types.Type(core.BNNewTypeReference(refs[i].type), confidence = refs[i].typeConfidence)
result.append(StackVariableReference(refs[i].sourceOperand, var_type,
refs[i].name, Variable.from_identifier(self, refs[i].varIdentifier, refs[i].name, var_type),
refs[i].referencedOffset))
@@ -730,8 +732,9 @@ class Function(object):
size = lines[i].tokens[j].size
operand = lines[i].tokens[j].operand
context = lines[i].tokens[j].context
+ confidence = lines[i].tokens[j].confidence
address = lines[i].tokens[j].address
- tokens.append(InstructionTextToken(token_type, text, value, size, operand, context, address))
+ tokens.append(InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
result.append(tokens)
core.BNFreeInstructionTextLines(lines, count.value)
return result
@@ -853,10 +856,16 @@ class Function(object):
core.BNSetUserInstructionHighlight(self.handle, arch.handle, addr, color._get_core_struct())
def create_auto_stack_var(self, offset, var_type, name):
- core.BNCreateAutoStackVariable(self.handle, offset, var_type.handle, name)
+ tc = core.BNTypeWithConfidence()
+ tc.type = var_type.handle
+ tc.confidence = var_type.confidence
+ core.BNCreateAutoStackVariable(self.handle, offset, tc, name)
def create_user_stack_var(self, offset, var_type, name):
- core.BNCreateUserStackVariable(self.handle, offset, var_type.handle, name)
+ tc = core.BNTypeWithConfidence()
+ tc.type = var_type.handle
+ tc.confidence = var_type.confidence
+ core.BNCreateUserStackVariable(self.handle, offset, tc, name)
def delete_auto_stack_var(self, offset):
core.BNDeleteAutoStackVariable(self.handle, offset)
@@ -869,14 +878,20 @@ class Function(object):
var_data.type = var.source_type
var_data.index = var.index
var_data.storage = var.storage
- core.BNCreateAutoVariable(self.handle, var_data, var_type.handle, name, ignore_disjoint_uses)
+ tc = core.BNTypeWithConfidence()
+ tc.type = var_type.handle
+ tc.confidence = var_type.confidence
+ core.BNCreateAutoVariable(self.handle, var_data, tc, name, ignore_disjoint_uses)
def create_user_var(self, var, var_type, name, ignore_disjoint_uses = False):
var_data = core.BNVariable()
var_data.type = var.source_type
var_data.index = var.index
var_data.storage = var.storage
- core.BNCreateUserVariable(self.handle, var_data, var_type.handle, name, ignore_disjoint_uses)
+ tc = core.BNTypeWithConfidence()
+ tc.type = var_type.handle
+ tc.confidence = var_type.confidence
+ core.BNCreateUserVariable(self.handle, var_data, tc, name, ignore_disjoint_uses)
def delete_auto_var(self, var):
var_data = core.BNVariable()
@@ -899,7 +914,7 @@ class Function(object):
if not core.BNGetStackVariableAtFrameOffset(self.handle, arch.handle, addr, offset, found_var):
return None
result = Variable(self, found_var.var.type, found_var.var.index, found_var.var.storage,
- found_var.name, types.Type(handle = core.BNNewTypeReference(found_var.type)))
+ found_var.name, types.Type(handle = core.BNNewTypeReference(found_var.type), confidence = found_var.typeConfidence))
core.BNFreeVariableNameAndType(found_var)
return result
@@ -1043,8 +1058,9 @@ class FunctionGraphBlock(object):
size = lines[i].tokens[j].size
operand = lines[i].tokens[j].operand
context = lines[i].tokens[j].context
+ confidence = lines[i].tokens[j].confidence
address = lines[i].tokens[j].address
- tokens.append(InstructionTextToken(token_type, text, value, size, operand, context, address))
+ tokens.append(InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
result.append(DisassemblyTextLine(addr, tokens))
core.BNFreeDisassemblyTextLines(lines, count.value)
return result
@@ -1101,8 +1117,9 @@ class FunctionGraphBlock(object):
size = lines[i].tokens[j].size
operand = lines[i].tokens[j].operand
context = lines[i].tokens[j].context
+ confidence = lines[i].tokens[j].confidence
address = lines[i].tokens[j].address
- tokens.append(InstructionTextToken(token_type, text, value, size, operand, context, address))
+ tokens.append(InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
yield DisassemblyTextLine(addr, tokens)
finally:
core.BNFreeDisassemblyTextLines(lines, count.value)
@@ -1384,13 +1401,14 @@ class InstructionTextToken(object):
"""
def __init__(self, token_type, text, value = 0, size = 0, operand = 0xffffffff,
- context = InstructionTextTokenContext.NoTokenContext, address = 0):
+ context = InstructionTextTokenContext.NoTokenContext, address = 0, confidence = types.Type.max_confidence):
self.type = InstructionTextTokenType(token_type)
self.text = text
self.value = value
self.size = size
self.operand = operand
self.context = InstructionTextTokenContext(context)
+ self.confidence = confidence
self.address = address
def __str__(self):
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index c359a79c..62e33a75 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -309,8 +309,9 @@ class LowLevelILInstruction(object):
size = tokens[i].size
operand = tokens[i].operand
context = tokens[i].context
+ confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
+ result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeInstructionText(tokens, count.value)
return result
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 1274bd9b..275746cc 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -265,8 +265,9 @@ class MediumLevelILInstruction(object):
size = tokens[i].size
operand = tokens[i].operand
context = tokens[i].context
+ confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
+ result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeInstructionText(tokens, count.value)
return result
diff --git a/python/types.py b/python/types.py
index f8e416f4..c3d7156e 100644
--- a/python/types.py
+++ b/python/types.py
@@ -22,7 +22,7 @@ import ctypes
# Binary Ninja components
import _binaryninjacore as core
-from enums import SymbolType, TypeClass, NamedTypeReferenceClass, InstructionTextTokenType, StructureType
+from enums import SymbolType, TypeClass, NamedTypeReferenceClass, InstructionTextTokenType, StructureType, ReferenceType
import callingconvention
import function
@@ -198,8 +198,11 @@ class Symbol(object):
class Type(object):
- def __init__(self, handle):
+ max_confidence = 255
+
+ def __init__(self, handle, confidence = max_confidence):
self.handle = handle
+ self.confidence = confidence
def __del__(self):
core.BNFreeType(self.handle)
@@ -232,12 +235,14 @@ class Type(object):
@property
def signed(self):
"""Wether type is signed (read-only)"""
- return core.BNIsTypeSigned(self.handle)
+ result = core.BNIsTypeSigned(self.handle)
+ return BoolWithConfidence(result.value, confidence = result.confidence)
@property
def const(self):
"""Whether type is const (read-only)"""
- return core.BNIsTypeConst(self.handle)
+ result = core.BNIsTypeConst(self.handle)
+ return BoolWithConfidence(result.value, confidence = result.confidence)
@property
def modified(self):
@@ -248,33 +253,33 @@ class Type(object):
def target(self):
"""Target (read-only)"""
result = core.BNGetChildType(self.handle)
- if result is None:
+ if not result.type:
return None
- return Type(result)
+ return Type(result.type, confidence = result.confidence)
@property
def element_type(self):
"""Target (read-only)"""
result = core.BNGetChildType(self.handle)
- if result is None:
+ if not result.type:
return None
- return Type(result)
+ return Type(result.type, confidence = result.confidence)
@property
def return_value(self):
"""Return value (read-only)"""
result = core.BNGetChildType(self.handle)
- if result is None:
+ if not result.type:
return None
- return Type(result)
+ return Type(result.type, confidence = result.confidence)
@property
def calling_convention(self):
"""Calling convention (read-only)"""
result = core.BNGetTypeCallingConvention(self.handle)
- if result is None:
+ if not result.convention:
return None
- return callingconvention.CallingConvention(None, result)
+ return callingconvention.CallingConvention(None, result, confidence = result.confidence)
@property
def parameters(self):
@@ -283,7 +288,7 @@ class Type(object):
params = core.BNGetTypeParameters(self.handle, count)
result = []
for i in xrange(0, count.value):
- result.append((Type(core.BNNewTypeReference(params[i].type)), params[i].name))
+ result.append((Type(core.BNNewTypeReference(params[i].type), confidence = params[i].typeConfidence), params[i].name))
core.BNFreeTypeParameterList(params, count.value)
return result
@@ -295,7 +300,8 @@ class Type(object):
@property
def can_return(self):
"""Whether type can return (read-only)"""
- return core.BNFunctionTypeCanReturn(self.handle)
+ result = core.BNFunctionTypeCanReturn(self.handle)
+ return BoolWithConfidence(result.value, confidence = result.confidence)
@property
def structure(self):
@@ -330,6 +336,8 @@ class Type(object):
return core.BNGetTypeString(self.handle)
def __repr__(self):
+ if self.confidence < Type.max_confidence:
+ return "<type: %s, %d%% confidence>" % (str(self), (self.confidence * 100) / Type.max_confidence)
return "<type: %s>" % str(self)
def get_string_before_name(self):
@@ -351,8 +359,9 @@ class Type(object):
size = tokens[i].size
operand = tokens[i].operand
context = tokens[i].context
+ confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
+ result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeTokenList(tokens, count.value)
return result
@@ -367,8 +376,9 @@ class Type(object):
size = tokens[i].size
operand = tokens[i].operand
context = tokens[i].context
+ confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
+ result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeTokenList(tokens, count.value)
return result
@@ -383,8 +393,9 @@ class Type(object):
size = tokens[i].size
operand = tokens[i].operand
context = tokens[i].context
+ confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address))
+ result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeTokenList(tokens, count.value)
return result
@@ -397,14 +408,23 @@ class Type(object):
return Type(core.BNCreateBoolType())
@classmethod
- def int(self, width, sign = True, altname=""):
+ def int(self, width, sign = None, altname=""):
"""
``int`` class method for creating an int Type.
:param int width: width of the integer in bytes
:param bool sign: optional variable representing signedness
"""
- return Type(core.BNCreateIntegerType(width, sign, altname))
+ if sign is None:
+ sign = BoolWithConfidence(True, confidence = 0)
+ elif not isinstance(sign, BoolWithConfidence):
+ sign = BoolWithConfidence(sign)
+
+ sign_conf = core.BNBoolWithConfidence()
+ sign_conf.value = sign.value
+ sign_conf.confidence = sign.confidence
+
+ return Type(core.BNCreateIntegerType(width, sign_conf, altname))
@classmethod
def float(self, width):
@@ -444,12 +464,40 @@ class Type(object):
return Type(core.BNCreateEnumerationType(e.handle, width))
@classmethod
- def pointer(self, arch, t, const=False):
- return Type(core.BNCreatePointerType(arch.handle, t.handle, const))
+ def pointer(self, arch, t, const=None, volatile=None, ref_type=None):
+ if const is None:
+ const = BoolWithConfidence(False, confidence = 0)
+ elif not isinstance(const, BoolWithConfidence):
+ const = BoolWithConfidence(const)
+
+ if volatile is None:
+ volatile = BoolWithConfidence(False, confidence = 0)
+ elif not isinstance(volatile, BoolWithConfidence):
+ volatile = BoolWithConfidence(volatile)
+
+ if ref_type is None:
+ ref_type = ReferenceType.PointerReferenceType
+
+ type_conf = core.BNTypeWithConfidence()
+ type_conf.type = t.handle
+ type_conf.confidence = t.confidence
+
+ const_conf = core.BNBoolWithConfidence()
+ const_conf.value = const.value
+ const_conf.confidence = const.confidence
+
+ volatile_conf = core.BNBoolWithConfidence()
+ volatile_conf.value = volatile.value
+ volatile_conf.confidence = volatile.confidence
+
+ return Type(core.BNCreatePointerType(arch.handle, type_conf, const_conf, volatile_conf, ref_type))
@classmethod
def array(self, t, count):
- return Type(core.BNCreateArrayType(t.handle, count))
+ type_conf = core.BNTypeWithConfidence()
+ type_conf.type = t.handle
+ type_conf.confidence = t.confidence
+ return Type(core.BNCreateArrayType(type_conf, count))
@classmethod
def function(self, ret, params, calling_convention=None, variable_arguments=False):
@@ -466,13 +514,26 @@ class Type(object):
if isinstance(params[i], Type):
param_buf[i].name = ""
param_buf[i].type = params[i].handle
+ param_buf[i].typeConfidence = params[i].confidence
else:
param_buf[i].name = params[i][1]
- param_buf[i].type = params[i][0]
- if calling_convention is not None:
- calling_convention = calling_convention.handle
- return Type(core.BNCreateFunctionType(ret.handle, calling_convention, param_buf, len(params),
- variable_arguments))
+ param_buf[i].type = params[i][0].handle
+ param_buf[i].typeConfidence = params[i][0].confidence
+
+ ret_conf = core.BNTypeWithConfidence()
+ ret_conf.type = ret.handle
+ ret_conf.confidence = ret.confidence
+
+ conv_conf = core.BNCallingConventionWithConfidence()
+ if calling_convention is None:
+ conv_conf.convention = None
+ conv_conf.confidence = 0
+ else:
+ conv_conf.convention = calling_convention.handle
+ conv_conf.confidence = calling_convention.confidence
+
+ return Type(core.BNCreateFunctionType(ret_conf, conv_conf, param_buf, len(params),
+ variable_arguments))
@classmethod
def generate_auto_type_id(self, source, name):
@@ -488,6 +549,9 @@ class Type(object):
def get_auto_demanged_type_id_source(self):
return core.BNGetAutoDemangledTypeIdSource()
+ def with_confidence(self, confidence):
+ return Type(handle = core.BNNewTypeReference(self.handle), confidence = confidence)
+
def __setattr__(self, name, value):
try:
object.__setattr__(self, name, value)
@@ -495,6 +559,36 @@ class Type(object):
raise AttributeError("attribute '%s' is read only" % name)
+class BoolWithConfidence(object):
+ def __init__(self, value, confidence = Type.max_confidence):
+ self.value = value
+ self.confidence = confidence
+
+ def __str__(self):
+ return str(self.value)
+
+ def __repr__(self):
+ return repr(self.value)
+
+ def __bool__(self):
+ return self.value
+
+ def __nonzero__(self):
+ return self.value
+
+
+class ReferenceTypeWithConfidence(object):
+ def __init__(self, value, confidence = Type.max_confidence):
+ self.value = value
+ self.confidence = confidence
+
+ def __str__(self):
+ return str(self.value)
+
+ def __repr__(self):
+ return repr(self.value)
+
+
class NamedTypeReference(object):
def __init__(self, type_class = NamedTypeReferenceClass.UnknownNamedTypeClass, type_id = None, name = None, handle = None):
if handle is None:
@@ -611,7 +705,7 @@ class Structure(object):
members = core.BNGetStructureMembers(self.handle, count)
result = []
for i in xrange(0, count.value):
- result.append(StructureMember(Type(core.BNNewTypeReference(members[i].type)),
+ result.append(StructureMember(Type(core.BNNewTypeReference(members[i].type), confidence = members[i].typeConfidence),
members[i].name, members[i].offset))
core.BNFreeStructureMemberList(members, count.value)
return result
@@ -664,16 +758,25 @@ class Structure(object):
return "<struct: size %#x>" % self.width
def append(self, t, name = ""):
- core.BNAddStructureMember(self.handle, t.handle, name)
+ tc = core.BNTypeWithConfidence()
+ tc.type = t.handle
+ tc.confidence = t.confidence
+ core.BNAddStructureMember(self.handle, tc, name)
def insert(self, offset, t, name = ""):
- core.BNAddStructureMemberAtOffset(self.handle, t.handle, name, offset)
+ tc = core.BNTypeWithConfidence()
+ tc.type = t.handle
+ tc.confidence = t.confidence
+ core.BNAddStructureMemberAtOffset(self.handle, tc, name, offset)
def remove(self, i):
core.BNRemoveStructureMember(self.handle, i)
def replace(self, i, t, name = ""):
- core.BNReplaceStructureMember(self.handle, i, t.handle, name)
+ tc = core.BNTypeWithConfidence()
+ tc.type = t.handle
+ tc.confidence = t.confidence
+ core.BNReplaceStructureMember(self.handle, i, tc, name)
class EnumerationMember(object):