def get_reverse_bits(bytes_array):
    """
    Reverse all bits in arbitrary-length bytes array
    """
    num_bytes = len(bytes_array)
    formatstring = "{0:0%db}" % (num_bytes * 8)
    bit_str = formatstring.format(int.from_bytes(bytes_array, byteorder='big'))
    return int(bit_str[::-1], 2).to_bytes(num_bytes, byteorder='big')