summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChinmay <chinmay1dd@gmail.com>2020-09-09 22:17:15 -0700
committerChinmay Deshpande <chinmay1dd@gmail.com>2020-09-10 08:45:04 -0700
commit167ced17956bbb79aee3a6e6ef88079d822427cb (patch)
tree0a991c4954d9e8f427d34057716795a508fe2b1c
parent78ae59ac4998ac66ff104f1ac6ef365b301feb43 (diff)
Update API name for ParsePossibleValueSet
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h2
-rw-r--r--binaryview.cpp4
-rw-r--r--python/binaryview.py10
-rw-r--r--python/function.py10
-rw-r--r--suite/testcommon.py98
6 files changed, 61 insertions, 65 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index d399a71c..5be335bf 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -1660,7 +1660,7 @@ __attribute__ ((format (printf, 1, 2)))
uint64_t GetPreviousDataBeforeAddress(uint64_t addr);
uint64_t GetPreviousDataVariableStartBeforeAddress(uint64_t addr);
- bool ParsePossibleValueSetString(const std::string& value, BNRegisterValueType state, PossibleValueSet& result, uint64_t here, std::string& errors);
+ bool ParsePossibleValueSet(const std::string& value, BNRegisterValueType state, PossibleValueSet& result, uint64_t here, std::string& errors);
bool ParseTypeString(const std::string& text, QualifiedNameAndType& result, std::string& errors,
const std::set<QualifiedName>& typesAllowRedefinition = {});
diff --git a/binaryninjacore.h b/binaryninjacore.h
index bf691026..6ed1f548 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -3390,7 +3390,7 @@ __attribute__ ((format (printf, 1, 2)))
BINARYNINJACOREAPI void BNClearUserVariableValue(BNFunction* func, const BNVariable* var, const BNArchitectureAndAddress* defSite);
BINARYNINJACOREAPI BNUserVariableValue* BNGetAllUserVariableValues(BNFunction *func, size_t* count);
BINARYNINJACOREAPI void BNFreeUserVariableValues(BNUserVariableValue* result);
- BINARYNINJACOREAPI bool BNParsePossibleValueSetString(BNBinaryView* view, const char* valueText, BNRegisterValueType state,
+ BINARYNINJACOREAPI bool BNParsePossibleValueSet(BNBinaryView* view, const char* valueText, BNRegisterValueType state,
BNPossibleValueSet* result, uint64_t here, char** errors);
BINARYNINJACOREAPI void BNRequestFunctionDebugReport(BNFunction* func, const char* name);
diff --git a/binaryview.cpp b/binaryview.cpp
index 3953cee6..11a6c032 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -2446,12 +2446,12 @@ uint64_t BinaryView::GetPreviousDataVariableStartBeforeAddress(uint64_t addr)
}
-bool BinaryView::ParsePossibleValueSetString(const string& value, BNRegisterValueType state, PossibleValueSet& result, uint64_t here, string& errors)
+bool BinaryView::ParsePossibleValueSet(const string& value, BNRegisterValueType state, PossibleValueSet& result, uint64_t here, string& errors)
{
BNPossibleValueSet res;
char* errorStr;
- if (!BNParsePossibleValueSetString(m_object, value.c_str(), state, &res, here, &errorStr))
+ if (!BNParsePossibleValueSet(m_object, value.c_str(), state, &res, here, &errorStr))
{
if (!errorStr)
errors = "";
diff --git a/python/binaryview.py b/python/binaryview.py
index 39af851c..49a80a4a 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -4677,7 +4677,7 @@ class BinaryView(object):
core.BNFreeTypeParserResult(parse)
return types.TypeParserResult(type_dict, variables, functions)
- def parse_possiblevalueset_string(self, value, state, here=0):
+ def parse_possiblevalueset(self, value, state, here=0):
r"""
Evaluates a string representation of a PossibleValueSet into an instance of the ``PossibleValueSet`` value.
@@ -4698,20 +4698,20 @@ class BinaryView(object):
:rtype: PossibleValueSet
:Example:
- >>> psv_c = bv.parse_possiblevalueset_string("400", RegisterValueType.ConstantValue)
+ >>> psv_c = bv.parse_possiblevalueset("400", RegisterValueType.ConstantValue)
>>> psv_c
<const 0x400>
- >>> psv_ur = bv.parse_possiblevalueset_string("1:10:1", RegisterValueType.UnsignedRangeValue)
+ >>> psv_ur = bv.parse_possiblevalueset("1:10:1", RegisterValueType.UnsignedRangeValue)
>>> psv_ur
<unsigned ranges: [<range: 0x1 to 0x10>]>
- >>> psv_is = bv.parse_possiblevalueset_string("1,2,3", RegisterValueType.InSetOfValues)
+ >>> psv_is = bv.parse_possiblevalueset("1,2,3", RegisterValueType.InSetOfValues)
>>> psv_is
<in set([0x1, 0x2, 0x3])>
>>>
"""
result = core.BNPossibleValueSet();
errors = ctypes.c_char_p();
- if not core.BNParsePossibleValueSetString(self.handle, value, state, result, here, errors):
+ if not core.BNParsePossibleValueSet(self.handle, value, state, result, here, errors):
if errors:
error_str = errors.value.decode("utf-8")
else:
diff --git a/python/function.py b/python/function.py
index 44c2f383..bf5afb87 100644
--- a/python/function.py
+++ b/python/function.py
@@ -382,13 +382,15 @@ class PossibleValueSet(object):
def __eq__(self, other):
if self.type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue] and isinstance(other, numbers.Integral):
return self.value == other
- if self.type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue] and hasattr(other, 'type') and other.type == self.type:
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ if self.type in [RegisterValueType.ConstantValue, RegisterValueType.ConstantPointerValue]:
return self.value == other.value
- elif self.type == RegisterValueType.StackFrameOffset and hasattr(other, 'type') and other.type == self.type:
+ elif self.type == RegisterValueType.StackFrameOffset:
return self.offset == other.offset
- elif self.type in [RegisterValueType.SignedRangeValue, RegisterValueType.UnsignedRangeValue] and hasattr(other, 'type') and other.type == self.type:
+ elif self.type in [RegisterValueType.SignedRangeValue, RegisterValueType.UnsignedRangeValue]:
return self.ranges == other.ranges
- elif self.type in [RegisterValueType.InSetOfValues, RegisterValueType.NotInSetOfValues] and hasattr(other, 'type') and other.type == self.type:
+ elif self.type in [RegisterValueType.InSetOfValues, RegisterValueType.NotInSetOfValues]:
return self.values == other.values
elif self.type == RegisterValueType.UndeterminedValue and hasattr(other, 'type'):
return self.type == other.type
diff --git a/suite/testcommon.py b/suite/testcommon.py
index a523fe3a..14a991a5 100644
--- a/suite/testcommon.py
+++ b/suite/testcommon.py
@@ -887,48 +887,48 @@ class VerifyBuilder(Builder):
""" Failed to parse PossibleValueSet from string"""
file_name = self.unpackage_file("helloworld")
try:
- bv = binja.BinaryViewType.get_view_of_file(file_name)
- # ConstantValue
- lhs = bv.parse_possiblevalueset_string("0", binja.RegisterValueType.ConstantValue)
- rhs = binja.PossibleValueSet.constant(0)
- assert lhs == rhs
- lhs = bv.parse_possiblevalueset_string("$here + 2", binja.RegisterValueType.ConstantValue, 0x2000)
- rhs = binja.PossibleValueSet.constant(0x2000 + 2)
- assert lhs == rhs
- # ConstantPointerValue
- lhs = bv.parse_possiblevalueset_string("0x8000", binja.RegisterValueType.ConstantPointerValue)
- rhs = binja.PossibleValueSet.constant_ptr(0x8000)
- assert lhs == rhs
- # StackFrameOffset
- lhs = bv.parse_possiblevalueset_string("16", binja.RegisterValueType.StackFrameOffset)
- rhs = binja.PossibleValueSet.stack_frame_offset(0x16)
- assert lhs == rhs
- # SignedRangeValue
- lhs = bv.parse_possiblevalueset_string("-10:0:2", binja.RegisterValueType.SignedRangeValue)
- rhs = binja.PossibleValueSet.signed_range_value([binja.ValueRange(-0x10, 0, 2)])
- assert lhs == rhs
- lhs = bv.parse_possiblevalueset_string("-10:0:2,2:5:1", binja.RegisterValueType.SignedRangeValue)
- rhs = binja.PossibleValueSet.signed_range_value([binja.ValueRange(-0x10, 0, 2), binja.ValueRange(2, 5, 1)])
- assert lhs == rhs
- # UnsignedRangeValue
- lhs = bv.parse_possiblevalueset_string("1:10:1", binja.RegisterValueType.UnsignedRangeValue)
- rhs = binja.PossibleValueSet.unsigned_range_value([binja.ValueRange(1, 0x10, 1)])
- assert lhs == rhs
- lhs = bv.parse_possiblevalueset_string("1:10:1, 2:20:2", binja.RegisterValueType.UnsignedRangeValue)
- rhs = binja.PossibleValueSet.unsigned_range_value([binja.ValueRange(1, 0x10, 1), binja.ValueRange(2, 0x20, 2)])
- assert lhs == rhs
- # InSetOfValues
- lhs = bv.parse_possiblevalueset_string("1,2,3,3,4", binja.RegisterValueType.InSetOfValues)
- rhs = binja.PossibleValueSet.in_set_of_values([1,2,3,4])
- assert lhs == rhs
- # NotInSetOfValues
- lhs = bv.parse_possiblevalueset_string("1,2,3,4,4", binja.RegisterValueType.NotInSetOfValues)
- rhs = binja.PossibleValueSet.not_in_set_of_values([1,2,3,4])
- assert lhs == rhs
- # UndeterminedValue
- lhs = bv.parse_possiblevalueset_string("", binja.RegisterValueType.UndeterminedValue)
- rhs = binja.PossibleValueSet.undetermined()
- assert lhs == rhs
+ with binja.open_view(file_name) as bv:
+ # ConstantValue
+ lhs = bv.parse_possiblevalueset("0", binja.RegisterValueType.ConstantValue)
+ rhs = binja.PossibleValueSet.constant(0)
+ assert lhs == rhs
+ lhs = bv.parse_possiblevalueset("$here + 2", binja.RegisterValueType.ConstantValue, 0x2000)
+ rhs = binja.PossibleValueSet.constant(0x2000 + 2)
+ assert lhs == rhs
+ # ConstantPointerValue
+ lhs = bv.parse_possiblevalueset("0x8000", binja.RegisterValueType.ConstantPointerValue)
+ rhs = binja.PossibleValueSet.constant_ptr(0x8000)
+ assert lhs == rhs
+ # StackFrameOffset
+ lhs = bv.parse_possiblevalueset("16", binja.RegisterValueType.StackFrameOffset)
+ rhs = binja.PossibleValueSet.stack_frame_offset(0x16)
+ assert lhs == rhs
+ # SignedRangeValue
+ lhs = bv.parse_possiblevalueset("-10:0:2", binja.RegisterValueType.SignedRangeValue)
+ rhs = binja.PossibleValueSet.signed_range_value([binja.ValueRange(-0x10, 0, 2)])
+ assert lhs == rhs
+ lhs = bv.parse_possiblevalueset("-10:0:2,2:5:1", binja.RegisterValueType.SignedRangeValue)
+ rhs = binja.PossibleValueSet.signed_range_value([binja.ValueRange(-0x10, 0, 2), binja.ValueRange(2, 5, 1)])
+ assert lhs == rhs
+ # UnsignedRangeValue
+ lhs = bv.parse_possiblevalueset("1:10:1", binja.RegisterValueType.UnsignedRangeValue)
+ rhs = binja.PossibleValueSet.unsigned_range_value([binja.ValueRange(1, 0x10, 1)])
+ assert lhs == rhs
+ lhs = bv.parse_possiblevalueset("1:10:1, 2:20:2", binja.RegisterValueType.UnsignedRangeValue)
+ rhs = binja.PossibleValueSet.unsigned_range_value([binja.ValueRange(1, 0x10, 1), binja.ValueRange(2, 0x20, 2)])
+ assert lhs == rhs
+ # InSetOfValues
+ lhs = bv.parse_possiblevalueset("1,2,3,3,4", binja.RegisterValueType.InSetOfValues)
+ rhs = binja.PossibleValueSet.in_set_of_values([1,2,3,4])
+ assert lhs == rhs
+ # NotInSetOfValues
+ lhs = bv.parse_possiblevalueset("1,2,3,4,4", binja.RegisterValueType.NotInSetOfValues)
+ rhs = binja.PossibleValueSet.not_in_set_of_values([1,2,3,4])
+ assert lhs == rhs
+ # UndeterminedValue
+ lhs = bv.parse_possiblevalueset("", binja.RegisterValueType.UndeterminedValue)
+ rhs = binja.PossibleValueSet.undetermined()
+ assert lhs == rhs
return True
finally:
self.delete_package("helloworld")
@@ -1260,8 +1260,7 @@ class VerifyBuilder(Builder):
"""User-informed dataflow tests"""
file_name = self.unpackage_file("helloworld")
try:
- with binja.BinaryViewType['ELF'].open(file_name) as bv:
- bv.update_analysis_and_wait()
+ with binja.open_view(file_name) as bv:
func = bv.get_function_at(0x00008440)
ins_idx = func.mlil.get_instruction_start(0x845c)
@@ -1326,8 +1325,7 @@ class VerifyBuilder(Builder):
bv.create_database(temp_name)
bv.file.close()
- with binja.FileMetadata(temp_name).open_existing_database(temp_name).get_view_of_type('ELF') as bv:
- bv.update_analysis_and_wait()
+ with binja.open_view(temp_name) as bv:
func = bv.get_function_at(0x00008440)
ins_idx = func.mlil.get_instruction_start(0x845c)
@@ -1371,8 +1369,7 @@ class VerifyBuilder(Builder):
def test_helper(value):
file_name = self.unpackage_file("helloworld")
try:
- with binja.BinaryViewType['ELF'].open(file_name) as bv:
- bv.update_analysis_and_wait()
+ with binja.open_view(file_name) as bv:
func = bv.get_function_at(0x00008440)
ins_idx = func.mlil.get_instruction_start(0x845c)
@@ -1392,10 +1389,8 @@ class VerifyBuilder(Builder):
temp_name = next(tempfile._get_candidate_names()) + ".bndb"
bv.create_database(temp_name)
- bv.file.close()
- with binja.FileMetadata(temp_name).open_existing_database(temp_name).get_view_of_type('ELF') as bv:
- bv.update_analysis_and_wait()
+ with binja.open_view(temp_name) as bv:
func = bv.get_function_at(0x00008440)
ins_idx = func.mlil.get_instruction_start(0x845c)
@@ -1405,7 +1400,6 @@ class VerifyBuilder(Builder):
def_ins = func.mlil[def_ins_idx]
assert(def_ins.get_possible_reg_values_after('r3') == value)
- bv.file.close()
os.unlink(temp_name)
return True