示例#1
0
    def export(self, dbg_info: DebugInfo = DebugInfo.disabled()) -> bytes:
        """Serialization to binary representation.

        :param dbg_info: instance allowing to provide debug info about exported data
        :return: binary representation of the region (serialization).
        """
        result = super().export()
        # KIB
        kib_data = self._kib.export()
        dbg_info.append_binary_section("BEE-KIB (non-crypted)", kib_data)
        aes = AES.new(self._sw_key, AES.MODE_ECB)
        result += aes.encrypt(kib_data)
        # padding
        result = extend_block(result, self.PRDB_OFFSET)
        # PRDB
        prdb_data = self._prdb.export()
        dbg_info.append_binary_section("BEE-PRDB (non-crypted)", prdb_data)
        aes = AES.new(self._kib.kib_key, AES.MODE_CBC, self._kib.kib_iv)
        result += aes.encrypt(prdb_data)
        # padding
        return extend_block(result, self.SIZE)
示例#2
0
def test_add_padding_invalid_input():
    """Test invalid inputs for misc.align_block()"""
    # negative length
    with pytest.raises(AssertionError):
        extend_block(b'', -1)
    # length < current length
    with pytest.raises(AssertionError):
        extend_block(b'\x00\x00', 1)
    # padding > 255
    with pytest.raises(AssertionError):
        extend_block(b'\x00\x00', 1, 256)
    # padding < 0
    with pytest.raises(AssertionError):
        extend_block(b'\x00\x00', 1, -1)
示例#3
0
def test_SegCSF_export_parse():
    obj = SegCSF(enabled=True)
    obj.append_command(
        CmdWriteData(ops=EnumWriteOps.WRITE_VALUE,
                     data=[(0x30340004, 0x4F400005)]))

    data = obj.export()
    csf_parsed = SegCSF.parse(data)
    assert data == csf_parsed.export()

    # with padding
    obj.padding_len = 0x10
    assert obj.export() == extend_block(data, obj.size + 0x10)
示例#4
0
 def export(self) -> bytes:
     """:return: binary representation of the region (serialization)."""
     result = super().export()
     result += pack(
         self._struct_format(),
         self.TAGL,
         self.TAGH,
         self.VERSION,
         self.fac_count,
         self._start_addr,
         self._end_addr,
         self.mode,
         self.lock_options,
         self.counter[::-1],  # bytes swapped: reversed order
         b'\x00' * 32)
     for fac in self.fac_regions:
         result += fac.export()
     result = extend_block(result, self.SIZE)
     return result
示例#5
0
def test_add_padding(test_input: bytes, length: int, padding: int, expected: bytes) -> None:
    """Test misc.add_padding()"""
    data = extend_block(test_input, length, padding)
    assert data == expected