Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def request_multiple_blocks(context):
r = Request("unit-test-request")
r.push(primitives.Byte(value=1, name="string block"))
r.push(primitives.String(value="The perfection of art is to conceal art.", name="unit-test-byte"))
context.uut = r
:param value: Default string value
:type size: int
:param size: (Optional, def=-1) Static size of this field, leave -1 for dynamic.
:type padding: Character
:param padding: (Optional, def="\\x00") Value to use as padding to fill static field size.
:type encoding: str
:param encoding: (Optonal, def="ascii") String encoding, ex: utf_16_le for Microsoft Unicode.
:type fuzzable: bool
:param fuzzable: (Optional, def=True) Enable/disable fuzzing of this primitive
:type max_len: int
:param max_len: (Optional, def=0) Maximum string length
:type name: str
:param name: (Optional, def=None) Specifying a name gives you direct access to a primitive
"""
s = primitives.String(value, size, padding, encoding, fuzzable, max_len, name)
blocks.CURRENT.push(s)
def __init__(self, name, request, value, options=None):
if not options:
options = {}
super(String, self).__init__(name, request)
self.value = value
self.options = options
self.prefix = options.get("prefix", b"\x04")
if not self.value:
raise exception.SullyRuntimeError("MISSING LEGO.ber_string DEFAULT VALUE")
str_block = blocks.Block(name + "_STR", request)
str_block.push(primitives.String(self.value))
self.push(blocks.Size(name + "_STR", request, endian=BIG_ENDIAN, fuzzable=True))
self.push(str_block)
@param value: Default string value
@type size: int
@param size: (Optional, def=-1) Static size of this field, leave -1 for dynamic.
@type padding: chr
@param padding: (Optional, def="\\x00") Value to use as padding to fill static field size.
@type encoding: str
@param encoding: (Optional, def="ascii") String encoding, ex: utf_16_le for Microsoft Unicode.
@type fuzzable: bool
@param fuzzable: (Optional, def=True) Enable/disable fuzzing of this primitive
@type max_len: int
@param max_len: (Optional, def=0) Maximum string length
@type name: str
@param name: (Optional, def=None) Specifying a name gives you direct access to a primitive
"""
super(String, self).__init__()
self._value = self.original_value = value
self.size = size
self.padding = padding
self.encoding = encoding
self.fuzzable = fuzzable
self.name = name
self.s_type = "string" # for ease of object identification
self.this_library = \
[
self._value * 2,
self._value * 10,
self._value * 100,
# UTF-8
# TODO: This can't actually convert these to unicode strings...
def __init__(self, name, request, value, options=None):
if not options:
options = {}
super(NdrWString).__init__(name, request)
self.value = value
self.options = options
if not self.value:
raise exception.SullyRuntimeError("MISSING LEGO.tag DEFAULT VALUE")
self.push(primitives.String(self.value))
:param value: Default string value
:type size: int
:param size: (Optional, def=-1) Static size of this field, leave -1 for dynamic.
:type padding: Character
:param padding: (Optional, def="\\x00") Value to use as padding to fill static field size.
:type encoding: str
:param encoding: (Optonal, def="ascii") String encoding, ex: utf_16_le for Microsoft Unicode.
:type fuzzable: bool
:param fuzzable: (Optional, def=True) Enable/disable fuzzing of this primitive
:type max_len: int
:param max_len: (Optional, def=0) Maximum string length
:type name: str
:param name: (Optional, def=None) Specifying a name gives you direct access to a primitive
"""
s = primitives.String(value, size, padding, encoding, fuzzable, max_len, name)
blocks.CURRENT.push(s)