This function reads the fixup array and apply the correct values
    to the underlying binary stream. This function changes the bin_view
    in memory.

    Args:
        bin_view (memoryview of bytearray) - The binary stream
        fx_offset (int) - Offset to the fixup array
        fx_count (int) - Number of elements in the fixup array
        entry_size (int) - Size of the MFT entry

def apply_fixup_array(bin_view, fx_offset, fx_count, entry_size):
    '''This function reads the fixup array and apply the correct values
    to the underlying binary stream. This function changes the bin_view
    in memory.

    Args:
        bin_view (memoryview of bytearray) - The binary stream
        fx_offset (int) - Offset to the fixup array
        fx_count (int) - Number of elements in the fixup array
        entry_size (int) - Size of the MFT entry
    '''
    fx_array = bin_view[fx_offset:fx_offset+(2 * fx_count)]
    #the array is composed of the signature + substitutions, so fix that
    fx_len = fx_count - 1
    #we can infer the sector size based on the entry size
    sector_size = int(entry_size / fx_len)
    index = 1
    position = (sector_size * index) - 2
    while (position <= entry_size):
        if bin_view[position:position+2].tobytes() == fx_array[:2].tobytes():
            #the replaced part must always match the signature!
            bin_view[position:position+2] = fx_array[index * 2:(index * 2) + 2]
        else:
            _MOD_LOGGER.error("Error applying the fixup array")
            raise FixUpError(f"Signature {fx_array[:2].tobytes()} does not match {bin_view[position:position+2].tobytes()} at offset {position}.")
        index += 1
        position = (sector_size * index) - 2
    _MOD_LOGGER.info("Fix up array applied successfully.")