MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / parse_possiblevalueset

Method parse_possiblevalueset

python/binaryview.py:7765–7812  ·  view source on GitHub ↗

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:func:`parse_expression` API. This implies that a ``ConstantValue [0x4000].d`` can be provided given that 4 bytes ca

(
	    self, value: str, state: RegisterValueType, here: int = 0
	)

Source from the content-addressed store, hash-verified

7763 core.BNFreeTypeParserResult(parse)
7764
7765 def parse_possiblevalueset(
7766 self, value: str, state: RegisterValueType, here: int = 0
7767 ) -> 'variable.PossibleValueSet':
7768 """
7769 Evaluates a string representation of a PossibleValueSet into an instance of the ``PossibleValueSet`` value.
7770
7771 .. note:: Values are evaluated based on the rules as specified for :py:func:`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.
7772
7773 The parser uses the following rules:
7774 - ConstantValue - ``<value>``
7775 - ConstantPointerValue - ``<value>``
7776 - StackFrameOffset - ``<value>``
7777 - SignedRangeValue - ``<value>:<value>:<value>{,<value>:<value>:<value>}*`` (Multiple ValueRanges can be provided by separating them by commas)
7778 - UnsignedRangeValue - ``<value>:<value>:<value>{,<value>:<value>:<value>}*`` (Multiple ValueRanges can be provided by separating them by commas)
7779 - InSetOfValues - ``<value>{,<value>}*``
7780 - NotInSetOfValues - ``<value>{,<value>}*``
7781
7782 :param str value: PossibleValueSet value to be parsed
7783 :param RegisterValueType state: State for which the value is to be parsed
7784 :param int here: (optional) Base address for relative expressions, defaults to zero
7785 :rtype: PossibleValueSet
7786 :Example:
7787
7788 >>> psv_c = bv.parse_possiblevalueset("400", RegisterValueType.ConstantValue)
7789 >>> psv_c
7790 <const 0x400>
7791 >>> psv_ur = bv.parse_possiblevalueset("1:10:1", RegisterValueType.UnsignedRangeValue)
7792 >>> psv_ur
7793 <unsigned ranges: [<range: 0x1 to 0x10>]>
7794 >>> psv_is = bv.parse_possiblevalueset("1,2,3", RegisterValueType.InSetOfValues)
7795 >>> psv_is
7796 <in set([0x1, 0x2, 0x3])>
7797 >>>
7798 """
7799 result = core.BNPossibleValueSet()
7800 errors = ctypes.c_char_p()
7801 if value == None:
7802 value = ''
7803 if not core.BNParsePossibleValueSet(self.handle, value, state, result, here, errors):
7804 if errors:
7805 assert errors.value is not None, "core.BNParsePossibleValueSet returned errors set to None"
7806 error_str = errors.value.decode("utf-8")
7807 else:
7808 error_str = "Error parsing specified PossibleValueSet"
7809 core.BNFreePossibleValueSet(result)
7810 core.free_string(errors)
7811 raise ValueError(error_str)
7812 return variable.PossibleValueSet(self.arch, result)
7813
7814 @property
7815 def type_container(self) -> 'typecontainer.TypeContainer':

Callers

nothing calls this directly

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected