コード例 #1
0
 def testSeedNotTheSame(self):
     min_length = 10
     max_length = 100
     field1 = RandomBytes(value=self.default_value, seed=11111, min_length=min_length, max_length=max_length)
     field2 = RandomBytes(value=self.default_value, seed=22222, min_length=min_length, max_length=max_length)
     res1 = self._get_all_mutations(field1)
     res2 = self._get_all_mutations(field2)
     self.assertNotEqual(res1, res2)
コード例 #2
0
 def testNoStepSizes(self):
     min_length = 10
     max_length = 100
     field = RandomBytes(value=self.default_value, min_length=min_length, max_length=max_length)
     while field.mutate():
         rendered = field.render().bytes
         self.assertGreaterEqual(len(rendered), min_length)
         self.assertLessEqual(len(rendered), max_length)
コード例 #3
0
 def testNoStepSizes(self):
     min_length = 10
     max_length = 100
     field = RandomBytes(value=self.default_value, min_length=min_length, max_length=max_length)
     while field.mutate():
         rendered = field.render().bytes
         self.assertGreaterEqual(len(rendered), min_length)
         self.assertLessEqual(len(rendered), max_length)
コード例 #4
0
 def testStepNumMutations(self):
     min_length = 10
     max_length = 100
     step = 3
     excepted_num_mutations = (max_length - min_length) / step
     field = RandomBytes(value=self.default_value, min_length=min_length, max_length=max_length, step=step)
     self._check_mutation_count(field, excepted_num_mutations)
     field.reset()
     self._check_mutation_count(field, excepted_num_mutations)
コード例 #5
0
 def testStepNumMutations(self):
     min_length = 10
     max_length = 100
     step = 3
     excepted_num_mutations = (max_length - min_length) / step
     field = RandomBytes(value=self.default_value, min_length=min_length, max_length=max_length, step=step)
     self._check_mutation_count(field, excepted_num_mutations)
     field.reset()
     self._check_mutation_count(field, excepted_num_mutations)
コード例 #6
0
 def testNoStepNumMutations(self):
     param_num_mutations = 100
     field = RandomBytes(value=self.default_value,
                         min_length=10,
                         max_length=20,
                         num_mutations=param_num_mutations)
     self._check_mutation_count(field, param_num_mutations)
     field.reset()
     self._check_mutation_count(field, param_num_mutations)
コード例 #7
0
 def testStepSizes(self):
     min_length = 10
     max_length = 100
     step = 3
     field = RandomBytes(value=self.default_value, min_length=min_length, max_length=max_length, step=step)
     expected_length = min_length
     while field.mutate():
         rendered = field.render().bytes
         self.assertEqual(len(rendered), expected_length)
         expected_length += step
コード例 #8
0
 def testStepSizes(self):
     min_length = 10
     max_length = 100
     step = 3
     field = RandomBytes(value=self.default_value, min_length=min_length, max_length=max_length, step=step)
     expected_length = min_length
     while field.mutate():
         rendered = field.render().bytes
         self.assertEqual(len(rendered), expected_length)
         expected_length += step
コード例 #9
0
 def testStepRandomness(self):
     min_length = 10
     max_length = 100
     step = 5
     field = RandomBytes(value=self.default_value, min_length=min_length, max_length=max_length, step=step)
     mutations = self._get_all_mutations(field)
     self.assertNotEqual(len(set(mutations)), 1)
コード例 #10
0
ファイル: enum.py プロジェクト: webstorage119/umap2
string_descriptor = Descriptor(name='string_descriptor',
                               descriptor_type=DescriptorType.string,
                               fields=[
                                   String(
                                       name='bString',
                                       value='hello_kitty',
                                       encoder=StrEncodeEncoder('utf_16_le'),
                                       max_size=254 / 2)
                               ])

string_descriptor_zero = Descriptor(name='string_descriptor_zero',
                                    descriptor_type=DescriptorType.string,
                                    fields=[
                                        RandomBytes(name='lang_id',
                                                    min_length=0,
                                                    max_length=253,
                                                    step=3,
                                                    value='\x04\x09')
                                    ])

hub_descriptor = Descriptor(name='hub_descriptor',
                            descriptor_type=DescriptorType.hub,
                            fields=[
                                UInt8(name='bNbrPorts', value=4),
                                BitField(name='wHubCharacteristics',
                                         value=0xe000,
                                         length=16),
                                UInt8(name='bPwrOn2PwrGood', value=0x32),
                                UInt8(name='bHubContrCurrent', value=0x64),
                                UInt8(name='DeviceRemovable', value=0),
                                UInt8(name='PortPwrCtrlMask', value=0xff)
コード例 #11
0
ファイル: cdc.py プロジェクト: xairy/nu-map
                 LE16(name='wMaxSegmentSize', value=1514),
                 LE16(name='wNumberMCFilters', value=0),
                 UInt8(name='bNumberPowerFilters', value=0)
             ]),
         # .. todo: 4.3.2.6
         OneOf(fields=[
             Static(''),
             SubDescriptor(name='junk',
                           descriptor_type=DescriptorType.cs_interface,
                           fields=[
                               UInt8(name='bDesciptorSubType',
                                     value=0x15),
                               ForEach('bDesciptorSubType',
                                       fields=[
                                           RandomBytes(name='junk',
                                                       value=b'\x01',
                                                       min_length=0,
                                                       max_length=250),
                                       ])
                           ]),
         ])
     ]),
 Container(name='endpoints',
           fields=[
               SubDescriptor(name='endpoint_descriptor',
                             descriptor_type=DescriptorType.endpoint,
                             fields=[
                                 UInt8(name='bEndpointAddress',
                                       value=0x83),
                                 BitField(name='bmAttributes',
                                          value=3,
                                          length=8),
コード例 #12
0
                    UInt8(name='CmdQue', value=0x00),
                    Pad(8 * 8, fields=String(name='VendorID', value='Paul', max_size=8)),
                    Pad(16 * 8, fields=String(name='ProductID', value='Atreides', max_size=16)),
                    Pad(4 * 8, fields=String(name='productRev', value='1718', max_size=4)),
                ])
    ])


# Mode Sense - FuzzableUSBMassStorageInterface
scsi_mode_sense_6_response = Template(
    name='scsi_mode_sense_6_response',
    fields=[
        SizeInBytes(name='bLength', sized_field='scsi_mode_sense_6_response', length=8, fuzzable=True),
        UInt8(name='MediumType', value=0x00),
        UInt8(name='Device_Specific_Param', value=0x00),
        SizedPt(name='Mode_Parameter_Container', fields=RandomBytes(name='Mode_Parameter', min_length=0, max_length=4, value=b'\x1c'))
    ])


# Mode Sense - FuzzableUSBMassStorageInterface
scsi_mode_sense_10_response = Template(
    name='scsi_mode_sense_10_response',
    fields=[
        SizeInBytes(name='bLength', sized_field='scsi_mode_sense_10_response', length=8, fuzzable=True),
        UInt8(name='MediumType', value=0x00),
        UInt8(name='Device_Specific_Param', value=0x00),
        SizedPt(name='Mode_Parameter_Container', fields=RandomBytes(name='Mode_Parameter', min_length=0, max_length=4, value=b'\x1c'))
    ])


# Read Format Capacity - FuzzableUSBMassStorageInterface
コード例 #13
0
 def testNoStepNumMutations(self):
     param_num_mutations = 100
     field = RandomBytes(value=self.default_value, min_length=10, max_length=20, num_mutations=param_num_mutations)
     self._check_mutation_count(field, param_num_mutations)
     field.reset()
     self._check_mutation_count(field, param_num_mutations)
コード例 #14
0
 BE8(name="flags", value=0x00, fuzzable=False),
 SizeInBytes(name="size",
             sized_field="frames",
             length=28,
             encoder=id3v23_size_encoder()),
 # TODO: Extended header
 OneOf(
     name="frames",
     fields=[
         id3v23_frame("UFID",
                      fields=[
                          String(name="Owner Identifier",
                                 value="owner identifier",
                                 encoder=STR_ENC_NULLTERM),
                          RandomBytes(name="Identifier",
                                      value="A" * 64,
                                      min_length=1,
                                      max_length=100)
                      ]),
         id3v23_text_frame("TALB", value="Album/Movie/Show title"),
         id3v23_text_frame("TBPM",
                           value="100"),  # TODO: numeric strings only
         id3v23_text_frame("TCOM", value="Composer"),
         id3v23_text_frame(
             "TCON", value="(0)Hard rock"),  # TODO: implement encoding
         id3v23_text_frame("TCOP", value="Copyright message"),
         id3v23_text_frame("TDAT", value="2609"),
         id3v23_text_frame("TDLY",
                           value="100"),  # TODO: numeric strings only?
         id3v23_text_frame("TENC", value="Encoded by"),
         id3v23_text_frame("TEXT", value="Lyricist/Text writer"),
         id3v23_text_frame(
コード例 #15
0
    ])

# Table 4-7
# TODO: remove?
audio_feature_unit_descriptor = Descriptor(
    name='audio_feature_unit_descriptor',
    descriptor_type=_DescriptorTypes.CS_INTERFACE,
    fields=[
        UInt8(name='bDesciptorSubType',
              value=_AC_DescriptorSubTypes.FEATURE_UNIT),
        UInt8(name='bUnitID', value=0x00),
        UInt8(name='bSourceID', value=0x00),
        SizedPt(name='bmaControls',
                fields=RandomBytes(name='bmaControlsX',
                                   value='\x00',
                                   min_length=0,
                                   step=17,
                                   max_length=249)),
        UInt8(name='iFeature', value=0x00)
    ])

# Table 4-19
# TODO: remove?
audio_as_interface_descriptor = Descriptor(
    name='audio_as_interface_descriptor',
    descriptor_type=_DescriptorTypes.CS_INTERFACE,
    fields=[
        UInt8(name='bDesciptorSubType',
              value=_AS_DescriptorSubTypes.AS_GENERAL),
        UInt8(name='bTerminalLink', value=0x00),
        UInt8(name='bDelay', value=0x00),
コード例 #16
0
            DescriptorType.hub,
            self.num_ports,
            self.hub_chars,
            self.pwr_on_2_pwr_good,
            self.hub_contr_current,
        )
        num_bytes = self.num_ports // 7
        if self.num_ports % 7 != 0:
            num_bytes += 1
        d += b'\x00' * num_bytes
        d += b'\xff' * num_bytes
        d = struct.pack('B', len(d) + 1) + d
        return d
'''

hub_descriptor = Descriptor(name='hub_descriptor',
                            descriptor_type=DescriptorType.hub,
                            fields=[
                                Size(name='bNbrPorts',
                                     sized_field='DeviceRemovable',
                                     length=8,
                                     calc_func=lambda x: len(x) * 7),
                                LE16(name='wHubCharacteristics', value=0x0000),
                                UInt8(name='bPwrOn2PwrGood', value=0x00),
                                UInt8(name='bHubContrCurrent', value=0x02),
                                RandomBytes(name='DeviceRemovable',
                                            value=b'\x00',
                                            min_length=0,
                                            max_length=250),
                            ])
コード例 #17
0
 def testStepNegative(self):
     with self.assertRaises(KittyException):
         RandomBytes(value=self.default_value,
                     min_length=1,
                     max_length=5,
                     step=-1)
コード例 #18
0
 def testStepMinBiggerThanMax(self):
     with self.assertRaises(KittyException):
         RandomBytes(value=self.default_value,
                     min_length=5,
                     max_length=4,
                     step=1)
コード例 #19
0
 def testStepMaxIs0(self):
     with self.assertRaises(KittyException):
         RandomBytes(value=self.default_value,
                     min_length=0,
                     max_length=0,
                     step=1)
コード例 #20
0
 def testNoStepMaxNegative(self):
     with self.assertRaises(KittyException):
         RandomBytes(value=self.default_value, min_length=-2, max_length=-1)
コード例 #21
0
ファイル: mass_storage.py プロジェクト: sprout42/nu-map
                ])
    ])

# Mode Sense - FuzzableUSBMassStorageInterface
scsi_mode_sense_6_response = Template(
    name='scsi_mode_sense_6_response',
    fields=[
        SizeInBytes(name='bLength',
                    sized_field='scsi_mode_sense_6_response',
                    length=8,
                    fuzzable=True),
        UInt8(name='MediumType', value=0x00),
        UInt8(name='Device_Specific_Param', value=0x00),
        SizedPt(name='Mode_Parameter_Container',
                fields=RandomBytes(name='Mode_Parameter',
                                   min_length=0,
                                   max_length=4,
                                   value='\x1c'))
    ])

# Mode Sense - FuzzableUSBMassStorageInterface
scsi_mode_sense_10_response = Template(
    name='scsi_mode_sense_10_response',
    fields=[
        SizeInBytes(name='bLength',
                    sized_field='scsi_mode_sense_10_response',
                    length=8,
                    fuzzable=True),
        UInt8(name='MediumType', value=0x00),
        UInt8(name='Device_Specific_Param', value=0x00),
        SizedPt(name='Mode_Parameter_Container',
                fields=RandomBytes(name='Mode_Parameter',
コード例 #22
0
ファイル: apetagv2.py プロジェクト: xiaoyanguoke/katnip
apev2container = Container(
    name="apev2container",
    fields=[
        Static("APETAGEX"),
        LE32(name="version", value=struct.unpack("<I", "2000")[0]),
        SizeInBytes(name="size",
                    sized_field="items and footer",
                    length=32,
                    encoder=ENC_INT_LE),
        ElementCount(depends_on="items",
                     length=32,
                     name="item count",
                     encoder=ENC_INT_LE),
        LE32(name="flags", value=0xa0000000),
        RandomBytes(name="reserved",
                    value="\x00" * 8,
                    min_length=8,
                    max_length=8),
        Container(
            name="items and footer",
            fields=[
                OneOf(
                    name="items",
                    fields=[
                        apev2textitem("Title", "Music Piece Title"),
                        apev2textitem(
                            "Subtitle",
                            "Title when TITLE contains the work or additional sub title"
                        ),
                        apev2textitem("Artist", "Performing artist"),
                        apev2textitem("Album", "Album name"),
                        apev2textitem("Debut album", "Debut album name"),
コード例 #23
0
ファイル: smart_card.py プロジェクト: xairy/nu-map
            UInt8(name='bError', value=error),
            UInt8(name='bProtocolNum', value=proto),
            Container(name='abData', fields=ab_data),
        ]
        super(R2PParameters, self).__init__(name=name,
                                            fields=fields,
                                            fuzzable=fuzzable)


smartcard_GetParameters_response = R2PParameters(
    name='smartcard_GetParameters_response',
    status=0x00,
    error=0x80,
    proto=0,
    ab_data=RandomBytes(name='data',
                        value=b'\x11\x00\x00\x0a\x00',
                        min_length=0,
                        max_length=150),
)

smartcard_ResetParameters_response = R2PParameters(
    name='smartcard_ResetParameters_response',
    status=0x00,
    error=0x80,
    proto=0,
    ab_data=RandomBytes(name='data',
                        value=b'\x11\x00\x00\x0a\x00',
                        min_length=0,
                        max_length=150),
)

smartcard_SetParameters_response = R2PParameters(