Example #1
0
 def __init__(self, name, status, error, freq, rate, fuzzable=True):
     fields = [
         U8(name='bMessageType', value=0x84),
         SizeInBytes(name='dwLength',
                     sized_field=ab_data,
                     length=32,
                     fuzzable=True,
                     encoder=ENC_INT_LE),
         DynamicInt(name='bSlot',
                    key='bSlot',
                    bitfield=U8(name='bSlotInt', value=0)),
         DynamicInt(name='bSeq',
                    key='bSeq',
                    bitfield=U8(name='bSeqInt', value=0)),
         U8(name='bStatus', value=status),
         U8(name='bError', value=error),
         U8(name='bRFU', value=0),
         Container(name='abData',
                   fields=[
                       LE32(name='dwClockFrequency', value=freq),
                       LE32(name='dwDataRate', value=rate),
                   ]),
     ]
     super(R2PDataRateAndClockFrequency, self).__init__(name=name,
                                                        fields=fields,
                                                        fuzzable=fuzzable)
Example #2
0
 def __init__(self,
              name,
              status,
              error,
              chain_param,
              ab_data,
              fuzzable=True):
     fields = [
         U8(name='bMessageType', value=0x80),
         SizeInBytes(name='dwLength',
                     sized_field=ab_data,
                     length=32,
                     fuzzable=True,
                     encoder=ENC_INT_LE),
         DynamicInt(name='bSlot',
                    key='bSlot',
                    bitfield=U8(name='bSlotInt', value=0)),
         DynamicInt(name='bSeq',
                    key='bSeq',
                    bitfield=U8(name='bSeqInt', value=0)),
         U8(name='bStatus', value=status),
         U8(name='bError', value=error),
         U8(name='bChainParameter', value=chain_param),
         Container(name='abData', fields=ab_data),
     ]
     super(R2PDataBlock, self).__init__(name=name,
                                        fields=fields,
                                        fuzzable=fuzzable)
Example #3
0
 def test_set_session_data(self):
     new_value = 'new_value'
     uut = DynamicInt(self.the_key, self.bf)
     res = uut.render().bytes
     self.assertEqual(res, self.def_value)
     uut.set_session_data({self.the_key: new_value})
     res = uut.render().bytes
     self.assertEqual(res, new_value)
Example #4
0
 def __init__(self, name, status, error, clock_status, fuzzable=True):
     fields = [
         U8(name='bMessageType', value=0x80),
         LE32(name='dwLength', value=0x00),
         DynamicInt(name='bSlot', key='bSlot', bitfield=U8(name='bSlotInt', value=0)),
         DynamicInt(name='bSeq', key='bSeq', bitfield=U8(name='bSeqInt', value=0)),
         U8(name='bStatus', value=status),
         U8(name='bError', value=error),
         U8(name='bClockStatus', value=clock_status),
     ]
     super(R2PSlotStatus, self).__init__(name=name, fields=fields, fuzzable=fuzzable)
Example #5
0
 def test_vanilla(self):
     uut = DynamicInt(self.the_key, self.bf)
     bf_mutations = get_mutation_set(self.bf)
     uut_mutations = get_mutation_set(uut)
     if not any(x in bf_mutations for x in bf_mutations):
         raise AssertionError(
             'Not all similar_mutations are in uut_mutations')
     self.assertGreater(len(uut_mutations), len(bf_mutations))
Example #6
0
 def test_set_session_data(self):
     new_value = 'new_value'
     uut = DynamicInt(self.the_key, self.bf)
     res = uut.render().bytes
     self.assertEqual(res, self.def_value)
     uut.set_session_data({self.the_key: new_value})
     res = uut.render().bytes
     self.assertEqual(res, new_value)
Example #7
0
        ),  # USB 2.0 is reported as 0x0200, USB 1.1 as 0x0110 and USB 1.0 as 0x0100
        UInt8(name='bDeviceClass', value=0),
        UInt8(name='bDeviceSubClass', value=0),
        UInt8(name='bDeviceProtocol', value=0),
        UInt8(name='bMaxPacketSize', value=0),  # valid sizes: 8,16,32,64
        UInt8(name='bNumConfigurations', value=0),
        UInt8(name='bReserved', value=0)
    ])

# Configuration descriptor
# Section 9.6.3, page 265
configuration_descriptor = Descriptor(
    name='configuration_descriptor',
    descriptor_type=_DescriptorTypes.CONFIGURATION,
    fields=[
        DynamicInt('wTotalLength', LE16(value=9)),
        DynamicInt('bNumInterfaces', UInt8(value=1)),
        DynamicInt('bConfigurationValue', UInt8(value=1)),
        DynamicInt('iConfiguration', UInt8(value=0)),
        DynamicInt('bmAttributes', BitField(value=0, length=8)),
        DynamicInt('bMaxPower', UInt8(value=1)),
    ])

# Other_Speed_Configuration descriptor
# Section 9.6.4, page 267
other_speed_configuration_descriptor = Descriptor(
    name='other_speed_configuration_descriptor',
    descriptor_type=_DescriptorTypes.OTHER_SPEED_CONFIGURATION,
    fields=[
        LE16(name='wTotalLength', value=0xffff),  # TODO: real default size
        UInt8(name='bNumInterfaces', value=0xff),  # TODO: real default size
Example #8
0
    fields=[
        UInt8(name='bDesciptorSubType',
              value=_AS_DescriptorSubTypes.FORMAT_TYPE),
        UInt8(name='bFormatType', value=0x01),
        UInt8(name='bNrChannels', value=0x01),
        UInt8(name='bSubFrameSize', value=0x02),
        UInt8(name='bBitResolution', value=0x10),
        UInt8(name='bSamFreqType', value=0x01),
        BitField(name='tSamFreq', length=24, value=0x01F40)
    ])

audio_hid_descriptor = Descriptor(
    name='audio_hid_descriptor',
    descriptor_type=_DescriptorTypes.HID,
    fields=[
        DynamicInt('bcdHID', LE16(value=0x1001)),
        DynamicInt('bCountryCode', UInt8(value=0x00)),
        DynamicInt('bNumDescriptors', UInt8(value=0x01)),
        DynamicInt('bDescriptorType2',
                   UInt8(value=_DescriptorTypes.HID_REPORT)),
        DynamicInt('wDescriptorLength', LE16(value=0x2b)),
    ])

# this descriptor is based on umap
# https://github.com/nccgroup/umap
# commit 3ad812135f8c34dcde0e055d1fefe30500196c0f
audio_report_descriptor = Template(
    name='audio_report_descriptor',
    fields=GenerateHidReport(
        '050C0901A1011500250109E909EA75019502810209E209008106050B092095018142050C09009503810226FF000900750895038102090095049102C0'
        .decode('hex')))
Example #9
0
 def test_not_fuzzable(self):
     uut = DynamicInt(self.the_key, self.bf, fuzzable=False)
     res = uut.render().bytes
     self.assertEqual(res, self.def_value)
     self.assertEqual(uut.num_mutations(), 0)
Example #10
0
 def test_default_value(self):
     uut = DynamicInt(self.the_key, self.bf)
     res = uut.render().bytes
     self.assertEqual(res, self.def_value)
Example #11
0
 def test_not_fuzzable(self):
     uut = DynamicInt(self.the_key, self.bf, fuzzable=False)
     res = uut.render().bytes
     self.assertEqual(res, self.def_value)
     self.assertEqual(uut.num_mutations(), 0)
Example #12
0
 def test_default_value(self):
     uut = DynamicInt(self.the_key, self.bf)
     res = uut.render().bytes
     self.assertEqual(res, self.def_value)