コード例 #1
0
def test_read_block_data_big_endian():
    # No need for padding; size = 4 bytes (size 0x10)
    data = io.BytesIO(b'\x00\x00\x00\x10' b'1234' b'\x00\x00\x00\x10')
    assert read_block_data(data, '>') == b'1234'

    # Base size: 0x0c (12); payload size: 0x05; total: 0x11 (17)
    data = io.BytesIO(b'\x00\x00\x00\x11' b'12345XXX' b'\x00\x00\x00\x11')
    assert read_block_data(data, '>') == b'12345'
コード例 #2
0
ファイル: test_structs.py プロジェクト: sim0nx/python-pcapng
def test_read_block_data_little_endian():
    # No need for padding; size = 4 bytes (size 0x10)
    data = io.BytesIO('\x10\x00\x00\x00' '1234' '\x10\x00\x00\x00\x10')
    assert read_block_data(data, '<') == '1234'

    # Base size: 0x0c (12); payload size: 0x05; total: 0x11 (17)
    data = io.BytesIO('\x11\x00\x00\x00' '12345XXX' '\x11\x00\x00\x00')
    assert read_block_data(data, '<') == '12345'
コード例 #3
0
def test_read_block_data_little_endian():
    # No need for padding; size = 4 bytes (size 0x10)
    data = io.BytesIO(b"\x10\x00\x00\x00" b"1234" b"\x10\x00\x00\x00\x10")
    assert read_block_data(data, "<") == b"1234"

    # Base size: 0x0c (12); payload size: 0x05; total: 0x11 (17)
    data = io.BytesIO(b"\x11\x00\x00\x00" b"12345XXX" b"\x11\x00\x00\x00")
    assert read_block_data(data, "<") == b"12345"
コード例 #4
0
ファイル: test_structs.py プロジェクト: rshk/python-pcapng
def test_read_block_data_little_endian():
    # No need for padding; size = 4 bytes (size 0x10)
    data = io.BytesIO(b'\x10\x00\x00\x00' b'1234' b'\x10\x00\x00\x00\x10')
    assert read_block_data(data, '<') == b'1234'

    # Base size: 0x0c (12); payload size: 0x05; total: 0x11 (17)
    data = io.BytesIO(b'\x11\x00\x00\x00' b'12345XXX' b'\x11\x00\x00\x00')
    assert read_block_data(data, '<') == b'12345'
コード例 #5
0
ファイル: scanner.py プロジェクト: reidlindsay/python-pcapng
    def _read_block(self, block_type):
        """
        Read the block payload and pass to the appropriate block constructor
        """
        data = read_block_data(self.stream, endianness=self.endianness)

        if block_type in blocks.KNOWN_BLOCKS:
            # This is a known block -- instantiate it
            return blocks.KNOWN_BLOCKS[block_type].from_context(data, self)

        if block_type in BLK_RESERVED_CORRUPTED:
            raise CorruptedFile(
                'Block type 0x{0:08X} is reserved to detect a corrupted file'
                .format(block_type))

        if block_type == BLK_RESERVED:
            raise CorruptedFile(
                'Block type 0x00000000 is reserved and should not be used '
                'in capture files!')

        return blocks.UnknownBlock(block_type, data)
コード例 #6
0
ファイル: scanner.py プロジェクト: taleforia/Uforia
    def _read_block(self, block_type):
        """
        Read the block payload and pass to the appropriate block constructor
        """
        data = read_block_data(self.stream, endianness=self.endianness)

        if block_type in blocks.KNOWN_BLOCKS:
            # This is a known block -- instantiate it
            return blocks.KNOWN_BLOCKS[block_type].from_context(data, self)

        if block_type in BLK_RESERVED_CORRUPTED:
            raise CorruptedFile(
                'Block type 0x{0:08X} is reserved to detect a corrupted file'.
                format(block_type))

        if block_type == BLK_RESERVED:
            raise CorruptedFile(
                'Block type 0x00000000 is reserved and should not be used '
                'in capture files!')

        return blocks.UnknownBlock(block_type, data)
コード例 #7
0
ファイル: scanner.py プロジェクト: rshk/python-pcapng
    def _read_block(self, block_type):
        """
        Read the block payload and pass to the appropriate block constructor
        """
        data = read_block_data(self.stream, endianness=self.endianness)

        if block_type in blocks.KNOWN_BLOCKS:
            # This is a known block -- instantiate it
            return self.current_section.new_member(
                blocks.KNOWN_BLOCKS[block_type], raw=data)

        if block_type in BLK_RESERVED_CORRUPTED:
            raise CorruptedFile(
                "Block type 0x{0:08X} is reserved to detect a corrupted file".
                format(block_type))

        if block_type == BLK_RESERVED:
            raise CorruptedFile(
                "Block type 0x00000000 is reserved and should not be used "
                "in capture files!")

        return blocks.UnknownBlock(block_type, data)
コード例 #8
0
ファイル: test_structs.py プロジェクト: sim0nx/python-pcapng
def test_read_block_data_mismatching_lengths():
    data = io.BytesIO('\x00\x00\x00\x11' '12345XXX' '\xff\x00\x00\x11')
    with pytest.raises(CorruptedFile) as ctx:
        read_block_data(data, '>')

    assert ctx.value.message == 'Mismatching block lengths: 17 and 4278190097'
コード例 #9
0
def test_read_block_data_mismatching_lengths():
    data = io.BytesIO(b"\x00\x00\x00\x11" b"12345XXX" b"\xff\x00\x00\x11")
    with pytest.raises(CorruptedFile) as ctx:
        read_block_data(data, ">")

    assert str(ctx.value) == "Mismatching block lengths: 17 and 4278190097"
コード例 #10
0
ファイル: test_structs.py プロジェクト: rshk/python-pcapng
def test_read_block_data_mismatching_lengths():
    data = io.BytesIO(b'\x00\x00\x00\x11' b'12345XXX' b'\xff\x00\x00\x11')
    with pytest.raises(CorruptedFile) as ctx:
        read_block_data(data, '>')

    assert str(ctx.value) == 'Mismatching block lengths: 17 and 4278190097'