def testResolveFieldByAbsoluteName(self): self.target_field = '/B/C/to' uut = self.get_default_field() container = Container( name='A', fields=[ uut, Container(name='B', fields=[ Container(name='C', fields=[ self.to, Container(name='D', fields=[ UInt32(name='E', value=1) ]), ]), ]), ]) container.render() uut_rendered = uut.render() uut_val = unpack('>I', uut_rendered.tobytes())[0] self.assertEqual(len(uut_rendered), uut_val) self.assertEqual(32, uut_val)
def setUp(self): self.logger = get_test_logger() self.logger.debug('TESTING METHOD: %s', self._testMethodName) self.t_str = Template(name='simple_str_template', fields=[String(name='str1', value='kitty')]) self.t_int = Template(name='simple_int_template', fields=[UInt32(name='int1', value=0x1234)]) self.fuzzer = None self.prepare()
def setUp(self): super(AbsoluteOffsetTests, self).setUp(AbsoluteOffset) self.to = UInt32(name='to', value=1) self.target_field = self.to self.uut_len = 32 self.correction = 0 self.encoder = ENC_INT_BE self.fuzzable = False self.uut_name = 'uut'
def setUp(self): super(WebInterfaceTest, self).setUp(None) self.t_str = Template(name='simple_str_template', fields=[String(name='str1', value='kitty')]) self.t_int = Template(name='simple_int_template', fields=[UInt32(name='int1', value=0x1234)]) self.fuzzer = None self.host = '127.0.0.1' self.port = 11223 self.url = 'http://%(host)s:%(port)s' % {'host': self.host, 'port': self.port} self.prepare()
def add_stage(g, stage, template, count): ''' Add a stage to the session graph :param g: the GraphModel object :param stage: stage name :param template: the actual template :param count: the stage count :example: for the call add_stage(g, 'X', x, 4) we will create the following graph: :: x p1 -> x p1 -> p2 -> x p1 -> p2 -> p3 -> x ''' g.connect(template) pseudos = [ # workaround for a PseudoTemplate bug in kitty 0.6.9 # TODO: move to PseudoTemplate in next kitty version Template( name=stage, fields=Meta(fields=[ String(value=stage), UInt32(value=i) ]), fuzzable=False ) for i in range(count - 1) ] if pseudos: g.connect(pseudos[0]) for i in range(len(pseudos) - 1): g.connect(pseudos[i], pseudos[i + 1]) g.connect(pseudos[i], template) g.connect(pseudos[-1], template)
def get_templates(self): res = [] res.append(Template(name='t1', fields=[String('data1')])) res.append(Template(name='t2', fields=[String('data2'), UInt32(300)])) res.append(Template(name='t3', fields=[UInt32(400)])) return res
def dict_to_JsonObject(the_dict, name=None, ctx=None): ''' Create a JsonObject from a dictionary. The context parameter is used for recursive calls, no need to pass it from outside. :param the_dict: dictionary to base the `JsonObject` on :param ctx: context for the parser (default: None) :rtype: :class:`~katnip.legos.json.JsonObject` :return: JSON object that represents the dictionary ''' val = None if not isinstance(the_dict, dict): raise ValueError('expecting dictionary as first argument') if ctx is None: ctx = _JsonStringContext() members = {} for (k, v) in the_dict.items(): if v is None: val = JsonNull(name=ctx.uname(k), fuzzable=False) elif isinstance(v, bool): val = JsonBoolean(name=ctx.uname(k), value=v, fuzzable=True) elif isinstance(v, str): if '+enum' in v: if isinstance(v.split('+')[0], int): val = Dword(v.split('+')[0], name=ctx.uname(k), fuzzable=False) elif isinstance(v.split('+')[0], str): val = JsonString(name=ctx.uname(k), value=v.split('+')[0], fuzzable=False) elif isinstance(v.split('+')[0], bool): val = JsonBoolean(name=ctx.uname(k), value=v.split('+')[0], fuzzable=False) else: val = JsonString(name=ctx.uname(k), value=v, fuzzable=True) elif isinstance(v, list): val = list_to_JsonArray(v, k, ctx) elif isinstance(v, dict): val = dict_to_JsonObject(v, k, ctx) elif isinstance(v, int): if v in range(-214783648, 214783648): val = SInt32(v, encoder=ENC_INT_DEC, name=ctx.uname(k), min_value=-214783648, max_value=214783648) if v in range(0, 18446744073709551615): val = UInt64(v, encoder=ENC_INT_DEC, name=ctx.uname(k), min_value=0, max_value=18446744073709551615) if v in range(0, 4294967295): val = UInt32(v, encoder=ENC_INT_DEC, name=ctx.uname(k), min_value=0, max_value=4294967295) else: raise ValueError('type not supported: %s' % type(v)) members[k] = val if name is None: name = 'obj' return JsonObject(name=ctx.uname(name, False), member_dict=members, fuzz_keys=False)