Пример #1
0
def test_read_section_header_mismatching_lengths():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number
        '\x00\x00\x00\x1c'  # block length (28 bytes)
        '\x1a\x2b\x3c\x4d'  # byte order magic [it's big endian!]
        '\x00\x01\x00\x00'  # version 1.0
        '\xff\xff\xff\xff\xff\xff\xff\xff'  # section length unknown
        ''  # no options here!
        '\x00\x00\x00\x00')  # block length, again but WRONG!

    with pytest.raises(CorruptedFile) as ctx:
        read_section_header(data)

    assert ctx.value.message == 'Mismatching block lengths: 28 and 0'
Пример #2
0
def test_read_section_header_mismatching_lengths():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number
        b'\x00\x00\x00\x1c'  # block length (28 bytes)
        b'\x1a\x2b\x3c\x4d'  # byte order magic [it's big endian!]
        b'\x00\x01\x00\x00'  # version 1.0
        b'\xff\xff\xff\xff\xff\xff\xff\xff'  # section length unknown
        b''  # no options here!
        b'\x00\x00\x00\x00')  # block length, again but WRONG!

    with pytest.raises(CorruptedFile) as ctx:
        read_section_header(data)

    assert str(ctx.value) == 'Mismatching block lengths: 28 and 0'
Пример #3
0
def test_read_section_header_bad_order_magic():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number
        b'\x1c\x00\x00\x00'  # block length (28 bytes)
        b'\x0B\xAD\xBE\xEF'  # byte order magic [it's big endian!]
        b'\x01\x00\x00\x00'  # version 1.0
        b'\xff\xff\xff\xff\xff\xff\xff\xff'  # section length unknown
        b''  # no options here!
        b'\x1c\x00\x00\x00')  # block length, again

    with pytest.raises(BadMagic) as ctx:
        read_section_header(data)

    assert str(ctx.value) == ('Wrong byte order magic: got 0x0BADBEEF, '
                              'expected 0x1A2B3C4D or 0x4D3C2B1A')
Пример #4
0
def test_read_section_header_mismatching_lengths():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number
        b"\x00\x00\x00\x1c"  # block length (28 bytes)
        b"\x1a\x2b\x3c\x4d"  # byte order magic [it's big endian!]
        b"\x00\x01\x00\x00"  # version 1.0
        b"\xff\xff\xff\xff\xff\xff\xff\xff"  # section length unknown
        b""  # no options here!
        b"\x00\x00\x00\x00"
    )  # block length, again but WRONG!

    with pytest.raises(CorruptedFile) as ctx:
        read_section_header(data)

    assert str(ctx.value) == "Mismatching block lengths: 28 and 0"
Пример #5
0
def test_read_section_header_bad_order_magic():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number
        b'\x1c\x00\x00\x00'  # block length (28 bytes)
        b'\x0B\xAD\xBE\xEF'  # byte order magic [it's big endian!]
        b'\x01\x00\x00\x00'  # version 1.0
        b'\xff\xff\xff\xff\xff\xff\xff\xff'  # section length unknown
        b''  # no options here!
        b'\x1c\x00\x00\x00')  # block length, again

    with pytest.raises(BadMagic) as ctx:
        read_section_header(data)

    assert str(ctx.value) == (
        'Wrong byte order magic: got 0x0BADBEEF, '
        'expected 0x1A2B3C4D or 0x4D3C2B1A')
Пример #6
0
    def _read_section_header(self):
        """
        Section information headers are special blocks in that they
        modify the state of the FileScanner instance (to change current
        section / endianness)
        """

        section_info = read_section_header(self.stream)
        self.endianness = section_info["endianness"]  # todo: use property?

        # todo: make this use the standard schema facilities as well!
        return blocks.SectionHeader(raw=section_info["data"],
                                    endianness=section_info["endianness"])
Пример #7
0
def test_read_section_header_little_endian():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number
        '\x1c\x00\x00\x00'  # block length (28 bytes)
        '\x4d\x3c\x2b\x1a'  # byte order magic [it's big endian!]
        '\x01\x00\x00\x00'  # version 1.0
        '\xff\xff\xff\xff\xff\xff\xff\xff'  # section length unknown
        ''  # no options here!
        '\x1c\x00\x00\x00')  # block length, again

    block = read_section_header(data)
    assert block['endianness'] == '<'
    assert block['data'] == '\x01\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff'
Пример #8
0
def test_read_section_header_big_endian():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number has already been read..
        b'\x00\x00\x00\x1c'  # block length (28 bytes)
        b'\x1a\x2b\x3c\x4d'  # byte order magic [it's big endian!]
        b'\x00\x01\x00\x00'  # version 1.0
        b'\xff\xff\xff\xff\xff\xff\xff\xff'  # section length unknown
        b''  # no options here!
        b'\x00\x00\x00\x1c')  # block length, again

    block = read_section_header(data)
    assert block['endianness'] == '>'
    assert block['data'] == b'\x00\x01\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff'
Пример #9
0
def test_read_section_header_little_endian():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number
        b'\x1c\x00\x00\x00'  # block length (28 bytes)
        b'\x4d\x3c\x2b\x1a'  # byte order magic [it's big endian!]
        b'\x01\x00\x00\x00'  # version 1.0
        b'\xff\xff\xff\xff\xff\xff\xff\xff'  # section length unknown
        b''  # no options here!
        b'\x1c\x00\x00\x00')  # block length, again

    block = read_section_header(data)
    assert block['endianness'] == '<'
    assert block['data'] == b'\x01\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff'
Пример #10
0
    def _read_section_header(self):
        """
        Section information headers are special blocks in that they
        modify the state of the FileScanner instance (to change current
        section / endianness)
        """

        section_info = read_section_header(self.stream)
        self.endianness = section_info['endianness']  # todo: use property?

        # todo: make this use the standard schema facilities as well!
        return blocks.SectionHeader(
            raw=section_info['data'],
            endianness=section_info['endianness'])
Пример #11
0
def test_read_section_header_little_endian():
    data = io.BytesIO(
        # '\x0a\x0d\x0d\x0a'  # magic number
        b"\x1c\x00\x00\x00"  # block length (28 bytes)
        b"\x4d\x3c\x2b\x1a"  # byte order magic [it's big endian!]
        b"\x01\x00\x00\x00"  # version 1.0
        b"\xff\xff\xff\xff\xff\xff\xff\xff"  # section length unknown
        b""  # no options here!
        b"\x1c\x00\x00\x00"
    )  # block length, again

    block = read_section_header(data)
    assert block["endianness"] == "<"
    assert block["data"] == b"\x01\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff"