From 73b649e79d5cd219cb56866abf2ee5e6a64d976a Mon Sep 17 00:00:00 2001 From: Chinmay Date: Mon, 17 Aug 2020 22:53:09 -0700 Subject: UI changes for user-informed dataflow --- python/binaryview.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'python/binaryview.py') diff --git a/python/binaryview.py b/python/binaryview.py index 1cd57bf9..39af851c 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -4677,6 +4677,50 @@ class BinaryView(object): core.BNFreeTypeParserResult(parse) return types.TypeParserResult(type_dict, variables, functions) + def parse_possiblevalueset_string(self, value, state, here=0): + r""" + Evaluates a string representation of a PossibleValueSet into an instance of the ``PossibleValueSet`` value. + + .. note:: Values are evaluated based on the rules as specified for :py:meth:`parse_expression` API. This implies that a ``ConstantValue [0x4000].d`` can be provided given that 4 bytes can be read at ``0x4000``. All constants are considered to be in hexadecimal form by default. + + The parser uses the following rules: + - ConstantValue - ```` + - ConstantPointerValue - ```` + - StackFrameOffset - ```` + - SignedRangeValue - ``::{,::}*`` (Multiple ValueRanges can be provided by separating them by commas) + - UnsignedRangeValue - ``::{,::}*`` (Multiple ValueRanges can be provided by separating them by commas) + - InSetOfValues - ``{,}*`` + - NotInSetOfValues - ``{,}*`` + + :param str value: PossibleValueSet value to be parsed + :param RegisterValueType state: State for which the value is to be parsed + :param int here: (optional) Base address for relative expressions, defaults to zero + :rtype: PossibleValueSet + :Example: + + >>> psv_c = bv.parse_possiblevalueset_string("400", RegisterValueType.ConstantValue) + >>> psv_c + + >>> psv_ur = bv.parse_possiblevalueset_string("1:10:1", RegisterValueType.UnsignedRangeValue) + >>> psv_ur + ]> + >>> psv_is = bv.parse_possiblevalueset_string("1,2,3", RegisterValueType.InSetOfValues) + >>> psv_is + + >>> + """ + result = core.BNPossibleValueSet(); + errors = ctypes.c_char_p(); + if not core.BNParsePossibleValueSetString(self.handle, value, state, result, here, errors): + if errors: + error_str = errors.value.decode("utf-8") + else: + error_str = "Error parsing specified PossibleValueSet" + core.BNFreePossibleValueSet(result) + core.BNFreeString(ctypes.cast(errors, ctypes.POINTER(ctypes.c_byte))) + raise ValueError(error_str) + return function.PossibleValueSet(self.arch, result) + def get_type_by_name(self, name): """ ``get_type_by_name`` returns the defined type whose name corresponds with the provided ``name`` -- cgit v1.3.1