How to use the boofuzz.primitives.BitField function in boofuzz

To help you get started, we’ve selected a few boofuzz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jtpereyda / boofuzz / boofuzz / blocks / size.py View on Github external
def _length_to_bytes(self, length):
        return primitives.BitField.render_int(
            value=self.math(length),
            output_format=self.format,
            bit_width=self.length * 8,
            endian=self.endian,
            signed=self.signed,
        )
github jtpereyda / boofuzz / boofuzz / __init__.py View on Github external
:param width:          Width of bit fields
    :type  endian:         Character
    :param endian:         (Optional, def=LITTLE_ENDIAN) Endianess of the bit field (LITTLE_ENDIAN: <, BIG_ENDIAN: >)
    :type  output_format:  str
    :param output_format:  (Optional, def=binary) Output format, "binary" or "ascii"
    :type  signed:         bool
    :param signed:         (Optional, def=False) Make size signed vs. unsigned (applicable only with format="ascii")
    :type  full_range:     bool
    :param full_range:     (Optional, def=False) If enabled the field mutates through *all* possible values.
    :type  fuzzable:       bool
    :param fuzzable:       (Optional, def=True) Enable/disable fuzzing of this primitive
    :type  name:           str
    :param name:           (Optional, def=None) Specifying a name gives you direct access to a primitive
    """

    bit_field = primitives.BitField(value, width, None, endian, output_format, signed, full_range, fuzzable, name)
    blocks.CURRENT.push(bit_field)
github jtpereyda / boofuzz / boofuzz / __init__.py View on Github external
:param width:          Width of bit fields
    :type  endian:         Character
    :param endian:         (Optional, def=LITTLE_ENDIAN) Endianess of the bit field (LITTLE_ENDIAN: <, BIG_ENDIAN: >)
    :type  output_format:  str
    :param output_format:  (Optional, def=binary) Output format, "binary" or "ascii"
    :type  signed:         bool
    :param signed:         (Optional, def=False) Make size signed vs. unsigned (applicable only with format="ascii")
    :type  full_range:     bool
    :param full_range:     (Optional, def=False) If enabled the field mutates through *all* possible values.
    :type  fuzzable:       bool
    :param fuzzable:       (Optional, def=True) Enable/disable fuzzing of this primitive
    :type  name:           str
    :param name:           (Optional, def=None) Specifying a name gives you direct access to a primitive
    """

    bit_field = primitives.BitField(value, width, None, endian, output_format, signed, full_range, fuzzable, name)
    blocks.CURRENT.push(bit_field)
github jtpereyda / boofuzz / boofuzz / primitives.py View on Github external
class Byte(BitField):
    def __init__(self, value, *args, **kwargs):
        # Inject the one parameter we care to pass in (width)
        width = 8
        max_num = None

        super(Byte, self).__init__(value, width, max_num, *args, **kwargs)

        self.s_type = "byte"

        if type(self._value) not in [int, long, list, tuple]:
            self._value = struct.unpack(self.endian + "B", self._value)[0]


class Word(BitField):
    def __init__(self, value, *args, **kwargs):
        # Inject our width argument
        width = 16
        max_num = None

        super(Word, self).__init__(value, width, max_num, *args, **kwargs)

        self.s_type = "word"

        if type(self._value) not in [int, long, list, tuple]:
            self._value = struct.unpack(self.endian + "H", self._value)[0]


class DWord(BitField):
    def __init__(self, value, *args, **kwargs):
        # Inject our width argument
github jtpereyda / boofuzz / boofuzz / primitives.py View on Github external
class Word(BitField):
    def __init__(self, value, *args, **kwargs):
        # Inject our width argument
        width = 16
        max_num = None

        super(Word, self).__init__(value, width, max_num, *args, **kwargs)

        self.s_type = "word"

        if type(self._value) not in [int, long, list, tuple]:
            self._value = struct.unpack(self.endian + "H", self._value)[0]


class DWord(BitField):
    def __init__(self, value, *args, **kwargs):
        # Inject our width argument
        width = 32
        max_num = None

        super(DWord, self).__init__(value, width, max_num, *args, **kwargs)

        self.s_type = "dword"

        if type(self._value) not in [int, long, list, tuple]:
            self._value = struct.unpack(self.endian + "L", self._value)[0]


class QWord(BitField):
    def __init__(self, value, *args, **kwargs):
        width = 64
github jtpereyda / boofuzz / boofuzz / primitives.py View on Github external
return int(binary, 2)

    def __len__(self):
        return self.width / 8

    def __nonzero__(self):
        """
        Make sure instances evaluate to True even if __len__ is zero.

        :return: True
        """
        return True


class Byte(BitField):
    def __init__(self, value, *args, **kwargs):
        # Inject the one parameter we care to pass in (width)
        width = 8
        max_num = None

        super(Byte, self).__init__(value, width, max_num, *args, **kwargs)

        self.s_type = "byte"

        if type(self._value) not in [int, long, list, tuple]:
            self._value = struct.unpack(self.endian + "B", self._value)[0]


class Word(BitField):
    def __init__(self, value, *args, **kwargs):
        # Inject our width argument
github jtpereyda / boofuzz / boofuzz / blocks / size.py View on Github external
:param name:          Name of this sizer field
        """

        self.block_name = block_name
        self.request = request
        self.offset = offset
        self.length = length
        self.endian = endian
        self.format = output_format
        self.inclusive = inclusive
        self.signed = signed
        self.math = math
        self._fuzzable = fuzzable
        self._name = name

        self.bit_field = primitives.BitField(
            0, self.length * 8, endian=self.endian, output_format=self.format, signed=self.signed
        )
        self._rendered = b""
        self._fuzz_complete = False
        self._mutant_index = self.bit_field.mutant_index

        if not self.math:
            self.math = lambda x: x

        # Set the recursion flag before calling a method that may cause a recursive loop.
        self._recursion_flag = False